-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebase.py
41 lines (32 loc) · 1.21 KB
/
firebase.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
import firebase_admin
from firebase_admin import credentials, firestore
import pandas as pd
import ast
cred = credentials.Certificate("./firebaseAccountKey.json")
firebase_admin.initialize_app(cred)
db = firestore.client()
passed_df = pd.read_csv("./sales/passed_sd_check.csv")
all_bad_df = pd.read_csv("./sales/all_bad.csv")
failed_df = pd.read_csv("./sales/failed_sd_check.csv")
# with open("./manual_filter/all_bad.txt", "r") as f:
# l = list(map(int, f.read().split(" ")))
# passed_df = passed_df.append(all_bad_df.iloc[l])
# with open("./manual_filter/bad_sd.txt", "r") as f:
# l = list(map(int, f.read().split(" ")))
# passed_df = passed_df.append(failed_df.iloc[l])
passed_df["date"] = pd.to_datetime(passed_df["date"])
grouped = passed_df.groupby("product")
for name, group in grouped:
print(name)
doc = db.collection("gmk").document(name)
doc.set({u"count": group.shape[0]})
collection = doc.collection("sales")
for row in group.itertuples():
data = {
u"link": row.link,
u"sets": ast.literal_eval(row.sets),
u"price": row.price,
u"category": row.category,
u"date": row.date,
}
collection.add(data)