utils/create_url_polemics_param.py
changeset 39 c922bf9167aa
parent 38 dfb5081e8ebe
child 41 69a7e0b101de
--- a/utils/create_url_polemics_param.py	Fri Oct 17 17:05:09 2014 +0200
+++ b/utils/create_url_polemics_param.py	Fri Oct 17 17:45:38 2014 +0200
@@ -1,23 +1,51 @@
 # yo
+import argparse
 import json
+import sys
 import urllib
 
-path = "../client/data/categories.json"
-json_file=open(path)
-data = json.load(json_file)
-json_file.close()
+
+def get_options():
+
+    parser = argparse.ArgumentParser(description="Create url for iframe in Mons projects")
 
-output = []
+    parser.add_argument("-c", "--content", dest="content_id",
+                      help="content uuid", metavar="CONTENT_UUID", required=True)
+    parser.add_argument("-p", "--project", dest="project_id",
+                      help="project uuid", metavar="PROJECT_UUID", required=True)
+
+    return (parser.parse_args(), parser)
+
 
-for c in data["categories"]:
-    if "subcategories" in c and len(c["subcategories"])>0:
-        for sc in c["subcategories"]:
-            output.append({"name": sc["code"],"keywords": [ sc["label"] ], "color" : sc["color"] })
-    else:
-        output.append({"name": c["code"],"keywords": [ c["label"] ], "color" : c["color"] })
+if __name__ == "__main__" :
+    
+    (options, parser) = get_options()
+    
+    if len(sys.argv) == 1 or options.content_id is None or options.project_id is None:
+        parser.print_help()
+        sys.exit(1)
+    
+    path = "../client/data/categories.json"
+    json_file=open(path)
+    data = json.load(json_file)
+    json_file.close()
+    
+    output = []
+    
+    for c in data["categories"]:
+        if "subcategories" in c and len(c["subcategories"])>0:
+            for sc in c["subcategories"]:
+                output.append({"name": sc["code"],"keywords": [ sc["label"] ], "color" : sc["color"] })
+        else:
+            output.append({"name": c["code"],"keywords": [ c["label"] ], "color" : c["color"] })
+    
+    base_url = "http://ldt.iri.centrepompidou.fr/ldtplatform/ldt/embediframe/?content_id=" + options.content_id + "&project_id=" + options.project_id + "&polemic=all&polemics_list="
+    output_str = json.dumps(output, separators=(',',':'))
+    
+    print "SIMPLE JSON DUMPS :"
+    print base_url + output_str
+    print "\nURLLIB QUOTE_PLUS JSON DUMPS :"
+    print base_url + urllib.quote_plus(output_str)
 
-output_str = json.dumps(output, separators=(',',':'))
-print "SIMPLE JSON DUMPS :"
-print output_str
-print "\nURLLIB QUOTE_PLUS JSON DUMPS :"
-print urllib.quote_plus(output_str)
\ No newline at end of file
+
+