genia.likes.science@gmail.com | 6760586 | 2013-10-04 05:43:57 -0700 | [diff] [blame^] | 1 | import os |
| 2 | import json |
| 3 | import sys |
| 4 | |
| 5 | import requests |
| 6 | from requests import ConnectionError, HTTPError |
| 7 | |
| 8 | def bootstrap(): |
| 9 | asterix_host = "localhost" |
| 10 | asterix_port = 19002 |
| 11 | |
| 12 | # First, let's get the path to this script, we'll need it to configure the demo. |
| 13 | base = os.path.dirname(os.path.realpath(__file__)) |
| 14 | print "Running AdmAQL101 from",base |
| 15 | |
| 16 | # First, we bootstrap our request query |
| 17 | print "Loading TinySocial Dataset..." |
| 18 | query_statement = open("tinysocial/query.txt").read().split("load") |
| 19 | for i in range(1,5): |
| 20 | query_statement[i] = "load" + query_statement[i].replace("FULL_PATH",base + "/tinysocial") |
| 21 | |
| 22 | ddl = { |
| 23 | 'ddl': query_statement[0] |
| 24 | } |
| 25 | |
| 26 | load = { |
| 27 | "statements" : "use dataverse TinySocial; " + "\n".join(query_statement[1:5]) |
| 28 | } |
| 29 | |
| 30 | http_header = { |
| 31 | 'content-type': 'application/json' |
| 32 | } |
| 33 | |
| 34 | # Now we run our query |
| 35 | print "Running query...\n" |
| 36 | |
| 37 | ddl_url = "http://" + asterix_host + ":" + str(asterix_port) + "/ddl" |
| 38 | update_url = "http://" + asterix_host + ":" + str(asterix_port) + "/update" |
| 39 | |
| 40 | try: |
| 41 | requests.get(ddl_url, params=ddl) |
| 42 | response = requests.get(update_url, params=load, headers=http_header) |
| 43 | except (ConnectionError, HTTPError): |
| 44 | print "Encountered connection error; stopping execution" |
| 45 | sys.exit(1) |
| 46 | |
| 47 | return True |