-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoarama.py
78 lines (60 loc) · 2.29 KB
/
doarama.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import requests, json
debug = False
doarama_api_url = "https://www.doarama.com/api/0.2/"
doarama_params = {'api-name': 'yuneec-logconvert-web', 'Accept': 'application/JSON'}
# These two lines enable debugging at httplib level (requests->urllib3->http.client)
# You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
# The only thing missing will be the response.body which is not logged.
try:
import http.client as http_client
except ImportError:
# Python 2
import httplib as http_client
http_client.HTTPConnection.debuglevel = 1
def display_debug(r):
print r.url
print r.headers
print r.text
print r
def post_file(user_id, payload):
print("\n\n*********Upload GPX Data *********")
files = {'gps_track': payload}
r = requests.post(doarama_api_url+"activity", headers=doarama_params, files=files)
if(debug):
display_debug(r)
json_response = json.loads(r.text)
post_id = json_response['id']
return post_id
def set_activity_info(activity_type_id, post_id):
print("\n\n*********Set Activity Info *********")
payload = { 'activityTypeId' : activity_type_id}
r = requests.post(doarama_api_url+'activity/' + str(post_id), headers=doarama_params, json=payload)
if(debug):
display_debug(r)
def create_visualisation(post_id):
print("\n\n*********Create Visualisation *********")
payload = { 'activityIds' : [post_id]}
r = requests.post(doarama_api_url+"visualisation", headers=doarama_params, json=payload)
if(debug):
display_debug(r)
json_response = json.loads(r.text)
key_id = json_response['key']
return key_id
def main():
# Query Activity Types
# print("\n\n*********Query Activity Types *********")
# r = requests.get(doarama_api_url+"activityType", headers=doarama_params)
# if(debug):
# display_debug(r)
# print("Doarama Activity Types: {}".format(r.text))
flightlog_data = open('flightlog.gpx', 'rb')
user_id = str(1234)
doarama_params.update({'user-id': user_id})
post_id = post_file(user_id, flightlog_data)
print("Activity Id: " + str(post_id))
set_activity_info(30,post_id)
key_id = create_visualisation(post_id)
print 'keyid: ' + key_id
if __name__ == "__main__":
print 'Starting'
main()