forked from fraunhoferfokus/ogd-metadata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skript, das Gruppen und Untergruppen anlegt.
- Loading branch information
Florian Marienfeld
committed
Nov 21, 2012
1 parent
e296425
commit 4b1fa5b
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf8 -*- | ||
import traceback,pprint,sys | ||
import ckanclient #developed with ckanclient 0.10 | ||
reload(sys) | ||
sys.setdefaultencoding('utf-8') | ||
|
||
import ckanclient | ||
import json | ||
import argparse | ||
import groupmap | ||
|
||
pp=pprint.PrettyPrinter(indent=4) | ||
parser = argparse.ArgumentParser(description='Create group/subgroup structur.') | ||
parser.add_argument('--ckanurl', help='ckan url', required=True) | ||
parser.add_argument('--apikey', help='ckan api key, eg localhost:5000/api') | ||
parser.add_argument('--domain', help='ID for a group of domains like "iso" or "berlin".', required=True) | ||
args = parser.parse_args() | ||
|
||
|
||
# Instantiate the CKAN client. | ||
ckan = ckanclient.CkanClient(base_location=args.ckanurl, api_key=args.apikey) | ||
pp=pprint.PrettyPrinter(indent=4) | ||
|
||
filename = "../kategorien/" + args.domain + ".json" | ||
groups = json.loads( open(filename, 'r').read()) | ||
transl = groupmap.Translator('bremen') | ||
|
||
for gid in groups.iterkeys(): | ||
group_entity = { | ||
'name': gid, | ||
'title': groups[gid] | ||
} | ||
if not 'deutschland' == args.domain: | ||
group_entity['type'] = 'subgroup' | ||
|
||
try: | ||
ckan.group_register_post(group_entity) | ||
except: | ||
traceback.print_exc() | ||
|
||
if not 'deutschland' == args.domain: | ||
for supergroupname in transl.translate(gid): | ||
supergroup = ckan.group_entity_get(supergroupname) | ||
supergroup['groups'] = [{'name':gid}] + supergroup['groups'] | ||
try: | ||
ckan.group_register_post(supergroup) | ||
except: | ||
traceback.print_exc() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters