-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsuper_export.py
46 lines (41 loc) · 1.42 KB
/
super_export.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
from coords_to_kreis import coords_convert
import boto3
import json
import time
from datetime import date, timedelta
import pandas as pd
import csv
import ast
import settings
import numpy as np
import ast
date = date.today() - timedelta(days = 2)
print(date)
s3_client = boto3.client('s3')
data = pd.DataFrame()
for x in range(9,19):
try:
response = s3_client.get_object(Bucket=settings.BUCKET, Key='googleplaces_supermarket/{}/{}/{}/{}'.format(str(date.year).zfill(4), str(date.month).zfill(2), str(date.day).zfill(2), str(x).zfill(2)))
result = pd.DataFrame(json.loads(response["Body"].read()))
result["date"] = date
result["hour"] = x
data = data.append(result)
except Exception as e:
print(e)
pass
#return
lat = []
lon = []
data.to_csv("super.csv")
data["coordinates"] = data["coordinates"].astype(str)
for index, row in data.iterrows():
lat.append(ast.literal_eval(row["coordinates"])["lat"])
lon.append(ast.literal_eval(row["coordinates"])["lng"])
def normal_popularity(row):
return row["populartimes"][row["date"].weekday()]["data"][row["hour"]]
data["normal_popularity"] = data.apply(normal_popularity, axis = 1, result_type = "reduce")
data["relative_popularity"] = data["current_popularity"] / data["normal_popularity"]
data["lat"] = lat
data["lon"] = lon
data["ags"] = coords_convert(data)
pd.DataFrame(data["ags"].unique()).to_csv("super_ags.csv")