hypochondria

Find your best suited disease.
git clone git://r-36.net/hypochondria
Log | Files | Refs | README | LICENSE

update-assets (1154B)


      1 #!/usr/bin/env python
      2 # coding=utf-8
      3 #
      4 # Copy me if you can.
      5 # by 20h
      6 #
      7 
      8 import os
      9 import sys
     10 import getopt
     11 import requests
     12 import js2py
     13 import pickle
     14 
     15 def usage(app):
     16 	app = os.path.basename(app)
     17 	print("usage: %s [-h] [-b baseuri]" % (app), file=sys.stderr)
     18 	sys.exit(1)
     19 
     20 def main(args):
     21 	try:
     22 		opts, largs = getopt.getopt(args[1:], "hb:")
     23 	except getopt.GetoptError as err:
     24 		print(str(err))
     25 		usage(args[0])
     26 
     27 	baseuri = "http://hypochondriapp.io"
     28 	for o, a in opts:
     29 		if o == "-h":
     30 			usage(args[0])
     31 		elif o == "-b":
     32 			baseuri = o
     33 		else:
     34 			assert False, "unhandled option"
     35 
     36 	print("Downloading symptoms.js and diseases.js from %s." %(baseuri))
     37 	fd = requests.get("%s/symptoms.js" % (baseuri))
     38 	fd2 = requests.get("%s/diseases.js" % (baseuri))
     39 
     40 	ctx = js2py.EvalJs()
     41 	ctx.execute(fd.text)
     42 	ctx.execute(fd2.text)
     43 	diseases = ctx.diseases.to_dict()
     44 	symptoms = ctx.symptoms.to_dict()
     45 
     46 	print("Writing out diseases.pickle and symptoms.pickle.")
     47 	with open("diseases.pickle", "wb") as f:
     48 		pickle.dump(diseases, f)
     49 	with open("symptoms.pickle", "wb") as f:
     50 		pickle.dump(symptoms, f)
     51 
     52 	return 0
     53 
     54 if __name__ == "__main__":
     55 	sys.exit(main(sys.argv))
     56