1 # yo |
1 # yo |
|
2 import argparse |
2 import json |
3 import json |
|
4 import sys |
3 import urllib |
5 import urllib |
4 |
6 |
5 path = "../client/data/categories.json" |
|
6 json_file=open(path) |
|
7 data = json.load(json_file) |
|
8 json_file.close() |
|
9 |
7 |
10 output = [] |
8 def get_options(): |
11 |
9 |
12 for c in data["categories"]: |
10 parser = argparse.ArgumentParser(description="Create url for iframe in Mons projects") |
13 if "subcategories" in c and len(c["subcategories"])>0: |
|
14 for sc in c["subcategories"]: |
|
15 output.append({"name": sc["code"],"keywords": [ sc["label"] ], "color" : sc["color"] }) |
|
16 else: |
|
17 output.append({"name": c["code"],"keywords": [ c["label"] ], "color" : c["color"] }) |
|
18 |
11 |
19 output_str = json.dumps(output, separators=(',',':')) |
12 parser.add_argument("-c", "--content", dest="content_id", |
20 print "SIMPLE JSON DUMPS :" |
13 help="content uuid", metavar="CONTENT_UUID", required=True) |
21 print output_str |
14 parser.add_argument("-p", "--project", dest="project_id", |
22 print "\nURLLIB QUOTE_PLUS JSON DUMPS :" |
15 help="project uuid", metavar="PROJECT_UUID", required=True) |
23 print urllib.quote_plus(output_str) |
16 |
|
17 return (parser.parse_args(), parser) |
|
18 |
|
19 |
|
20 if __name__ == "__main__" : |
|
21 |
|
22 (options, parser) = get_options() |
|
23 |
|
24 if len(sys.argv) == 1 or options.content_id is None or options.project_id is None: |
|
25 parser.print_help() |
|
26 sys.exit(1) |
|
27 |
|
28 path = "../client/data/categories.json" |
|
29 json_file=open(path) |
|
30 data = json.load(json_file) |
|
31 json_file.close() |
|
32 |
|
33 output = [] |
|
34 |
|
35 for c in data["categories"]: |
|
36 if "subcategories" in c and len(c["subcategories"])>0: |
|
37 for sc in c["subcategories"]: |
|
38 output.append({"name": sc["code"],"keywords": [ sc["label"] ], "color" : sc["color"] }) |
|
39 else: |
|
40 output.append({"name": c["code"],"keywords": [ c["label"] ], "color" : c["color"] }) |
|
41 |
|
42 base_url = "http://ldt.iri.centrepompidou.fr/ldtplatform/ldt/embediframe/?content_id=" + options.content_id + "&project_id=" + options.project_id + "&polemic=all&polemics_list=" |
|
43 output_str = json.dumps(output, separators=(',',':')) |
|
44 |
|
45 print "SIMPLE JSON DUMPS :" |
|
46 print base_url + output_str |
|
47 print "\nURLLIB QUOTE_PLUS JSON DUMPS :" |
|
48 print base_url + urllib.quote_plus(output_str) |
|
49 |
|
50 |
|
51 |