genia.likes.science@gmail.com | d42b402 | 2013-08-09 05:05:23 -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 Black Cherry from",base |
| 15 | |
| 16 | # First, we bootstrap our request query |
| 17 | print "Preparing Dataset..." |
| 18 | query_statement = open("static/data/query.txt").read().split("load") |
| 19 | query_statement[1] = "load" + query_statement[1].replace("FULL_PATH",base + "/static/data") |
| 20 | |
| 21 | ddl = { |
| 22 | 'ddl': query_statement[0] |
| 23 | } |
| 24 | |
| 25 | load = { |
| 26 | "statements" : "use dataverse twitter; " + query_statement[1] |
| 27 | } |
| 28 | |
| 29 | http_header = { |
| 30 | 'content-type': 'application/json' |
| 31 | } |
| 32 | |
| 33 | # Now we run our query |
| 34 | print "Running query...\n" |
| 35 | |
| 36 | ddl_url = "http://" + asterix_host + ":" + str(asterix_port) + "/ddl" |
| 37 | update_url = "http://" + asterix_host + ":" + str(asterix_port) + "/update" |
| 38 | |
| 39 | try: |
| 40 | requests.get(ddl_url, params=ddl) |
| 41 | response = requests.get(update_url, params=load, headers=http_header) |
| 42 | except (ConnectionError, HTTPError): |
| 43 | print "Encountered connection error; stopping execution" |
| 44 | sys.exit(1) |
| 45 | |
| 46 | return True |