File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ # Converst Google Takeout Data to API endpoint format
2+ # Only send data placevisits for the last 2 weeks
3+
4+ import ijson
5+ import time
6+ import json
7+
8+ import boto3
9+
10+
11+ # In case we need to download off s3
12+ #s3 = boto3.client('s3')
13+ #s3.download_file('covid19-tracer', 'LocationHistory.json', 'location.json')
14+ #print('file download complete')
15+
16+
17+ current_milli_time = lambda : int (round (time .time () * 1000 ))
18+
19+ # Specify json file below
20+ with open ('2020_JANUARY.json' ,'rb' ) as input_file :
21+
22+ #up to 2 weeks ago
23+ begin_time = current_milli_time () - (2 * 604800 * 1000 )
24+
25+ # Collection placeVisits
26+ objects = ijson .items (input_file , 'timelineObjects.item.placeVisit' )
27+
28+ # Only keep those visits from the last 14 days
29+ placevisits = (o for o in objects if int (o ['duration' ]['startTimestampMs' ]) > begin_time )
30+
31+ with open ('output_json.json' , 'w' ) as output_file :
32+ output_data = []
33+ for visits in placevisits :
34+ row = {}
35+ row ["lat" ] = visits ['location' ]['latitudeE7' ]
36+ row ["lng" ] = visits ['location' ]['longitudeE7' ]
37+ row ["startTS" ] = int (visits ['duration' ]['startTimestampMs' ])
38+ row ["endTS" ] = int (visits ['duration' ]['endTimestampMs' ])
39+
40+ output_data .append (row )
41+ print (output_data )
42+
43+ json .dump (output_data , output_file , indent = 4 )
44+
You can’t perform that action at this time.
0 commit comments