-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli
More file actions
executable file
·68 lines (57 loc) · 1.93 KB
/
Copy pathcli
File metadata and controls
executable file
·68 lines (57 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
from collections import OrderedDict
from pathlib import Path
from slugify import slugify_filename
import click
DATASET_PATH = Path('datasets', 'metatodos')
TEMPLATE_STR = """
title: {title}
slug: {slug}
description: |
{description}
source_links:
{page_type}: {page_url}"""
def dumper(obj):
if obj['source_links'].get('socrata'):
page_type = 'socrata'
elif obj['source_links'].get('github'):
page_type = 'github'
else:
page_type = 'landing_page'
return TEMPLATE_STR.format(
title=obj['title'].replace('"', '\\"'),
slug=obj['slug'],
description=obj['description'],
page_type=page_type,
page_url=obj['source_links'][page_type])
def slugger(txt):
return slugify_filename(txt, separator='-', to_lower=True)
@click.command()
@click.argument('title')
@click.option('--description', '-d', default="""TK TK said bob "hey", TK TK""",
help="Description of the dataset")
@click.option('--landing', '-u', default="http://www.example.com/landing/TK",
help="The landing page of the data")
@click.option('--socrata', help='Socrata page')
def main(title, description, landing, socrata):
slug = slugger(title)
fname = DATASET_PATH.joinpath(slug + '.yaml')
if fname.exists():
raise ValueError("{0} already exists".format(str(fname)))
else:
click.echo("Creating: " + str(fname))
obj = OrderedDict()
obj['title'] = title
obj['slug'] = slug
obj['description'] = description
obj['source_links'] = OrderedDict()
if socrata:
obj['source_links']['socrata'] = socrata
else:
if 'github.com' in landing:
obj['source_links']['github'] = landing
else:
obj['source_links']['landing_page'] = landing
fname.write_text(dumper(obj))
if __name__ == '__main__':
main()