author | rougeronj |
Sat, 18 Apr 2015 09:37:57 +0200 | |
changeset 167 | 2b99fed0285e |
parent 61 | 511bff609c3d |
permissions | -rwxr-xr-x |
37
2d0e6a207048
convert categories.json into url parameter for embed iframe colorisation
cavaliet
parents:
diff
changeset
|
1 |
# yo |
39
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
2 |
import argparse |
37
2d0e6a207048
convert categories.json into url parameter for embed iframe colorisation
cavaliet
parents:
diff
changeset
|
3 |
import json |
39
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
4 |
import sys |
37
2d0e6a207048
convert categories.json into url parameter for embed iframe colorisation
cavaliet
parents:
diff
changeset
|
5 |
import urllib |
2d0e6a207048
convert categories.json into url parameter for embed iframe colorisation
cavaliet
parents:
diff
changeset
|
6 |
|
39
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
7 |
|
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
8 |
def get_options(): |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
9 |
|
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
10 |
parser = argparse.ArgumentParser(description="Create url for iframe in Mons projects") |
41 | 11 |
|
39
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
12 |
parser.add_argument("-p", "--project", dest="project_id", |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
13 |
help="project uuid", metavar="PROJECT_UUID", required=True) |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
14 |
|
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
15 |
return (parser.parse_args(), parser) |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
16 |
|
37
2d0e6a207048
convert categories.json into url parameter for embed iframe colorisation
cavaliet
parents:
diff
changeset
|
17 |
|
39
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
18 |
if __name__ == "__main__" : |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
19 |
|
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
20 |
(options, parser) = get_options() |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
21 |
|
41 | 22 |
if len(sys.argv) == 1 or options.project_id is None: |
39
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
23 |
parser.print_help() |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
24 |
sys.exit(1) |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
25 |
|
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
26 |
path = "../client/data/categories.json" |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
27 |
json_file=open(path) |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
28 |
data = json.load(json_file) |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
29 |
json_file.close() |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
30 |
|
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
31 |
output = [] |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
32 |
|
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
33 |
for c in data["categories"]: |
56 | 34 |
#if "subcategories" in c and len(c["subcategories"])>0: |
35 |
# for sc in c["subcategories"]: |
|
36 |
# output.append({"name": sc["code"],"keywords": [ sc["label"] ], "color" : sc["color"] }) |
|
37 |
#else: |
|
61 | 38 |
output.append({"name": c["code"] if "code" in c else "","keywords": [ c["label"] ], "color" : c["color"] }) |
39
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
39 |
|
58 | 40 |
base_url = "http://ldt.iri.centrepompidou.fr/ldtplatform/ldt/embediframe/?project_id=" + options.project_id + "&polemic=all&polemic__max_elements=200&polemics_list=" |
39
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
41 |
output_str = json.dumps(output, separators=(',',':')) |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
42 |
|
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
43 |
print "SIMPLE JSON DUMPS :" |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
44 |
print base_url + output_str |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
45 |
print "\nURLLIB QUOTE_PLUS JSON DUMPS :" |
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
46 |
print base_url + urllib.quote_plus(output_str) |
37
2d0e6a207048
convert categories.json into url parameter for embed iframe colorisation
cavaliet
parents:
diff
changeset
|
47 |
|
39
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
48 |
|
c922bf9167aa
create_url_polemics_param now with content and project id to generate full url
cavaliet
parents:
38
diff
changeset
|
49 |