9 CAMUNDA="http://localhost:8080/engine-rest/"
11 def get_current_deployments(key = 'sentiment-analysis'):
12 res = requests.get(CAMUNDA + "deployment")
13 #return [proc for proc in res.json() if proc['name'] == key]
16 def cleanup_old_deployments(key='sentiment-analysis'):
17 print ("Cleaning up old deployments")
18 for deployment in get_current_deployments(key):
19 res = requests.delete(CAMUNDA + "deployment/" + deployment['id'] + "?cascade=true")
20 if (res.status_code == 204):
21 print ("Cleaned up deployment {}".format(deployment['id']))
23 print ("Error cleaning old deployment {}: Code: {}".format(deployment['id'], res.status_code))
25 def create_deployment(cleanup=False):
27 ("deployment-name", "sentiment-analysis"),
28 #("enable-duplicate-filtering", "true"),
29 #("deploy-changed-only", "true"),
30 ("file1", open("sentiment-analysis.bpmn")),
31 ("file2", open("forms/input-terms.html")),
32 ("file3", open("forms/download-pdf.html")),
35 cleanup_old_deployments()
36 res = requests.post(CAMUNDA + "deployment/create", files=parameters)
37 if (res.status_code == 200):
38 print ("Successfully deployed Sentiment Analysis")
40 from pprint import pprint
41 pprint ("Status Code: {}".format(res.status_code))
47 def submit_terms(terms=[]):
48 termlist = [{'term': term} for term in terms]
53 'value': json.dumps(termlist),
56 'serializationDataFormat': "application/json",
61 res = requests.post(CAMUNDA + "process-definition/key/sentiment-analysis/start", json=params)
62 if (res.status_code == 200):
63 print ("Successfully started Sentiment Analysis")
65 from pprint import pprint
66 pprint ("Status Code: {}".format(res.status_code))
72 if __name__ == "__main__":
73 parser = argparse.ArgumentParser()
74 parser.add_argument('--deploy', dest='deploy', default=True, action='store_false', help="Do deployment step")
75 parser.add_argument('--cleanup', dest='cleanup', default=True, action='store_false', help="Initial deploy needs cleanup")
76 parser.add_argument('--autoclick', dest='autoclick', type=int, nargs=1, default=0, help="How many steps to autoclick")
77 args = parser.parse_args()
80 # initialize camunda process
81 create_deployment(cleanup=args.cleanup)
83 if args.autoclick[0] >= 1:
85 submit_terms(["voting", "phonegate", "35c3"])