-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyrebase_worker.py
176 lines (144 loc) · 5.02 KB
/
pyrebase_worker.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import pyrebase
import firebase_admin
from firebase_admin import credentials
import json
from os import environ
from datetime import datetime
config = {
"apiKey": environ["firebaseApiKey"],
"authDomain": environ["authDomain"],
"databaseURL": environ["databaseURL"],
"projectId": environ["projectId"],
"storageBucket": environ["storageBucket"],
"messagingSenderId": environ["messagingSenderId"],
"serviceAccount": environ["sapath"]
}
def setUpServiceAccountFile():
try:
with open(environ["sapath"], 'r') as f:
f.write(environ['serviceAccount'])
except IOError:
with open(environ["sapath"], 'w') as f:
f.write(environ['serviceAccount'])
# def push(name, phone, bcspogo, aqua):
# setUpServiceAccountFile()
# print("connecting")
# firebase = pyrebase.initialize_app(config)
# db = firebase.database()
# data = {
# "name": name,
# "phone": phone,
# "BCS Pokemon Go": bcspogo,
# "Team Aqua's Hideout": aqua
# }
# print("pushing...")
# results = db.child("users").push(data)
# print('finished!\nresults ->')
# print(results)
# def getData():
# setUpServiceAccountFile()
# print("connecting")
# firebase = pyrebase.initialize_app(config)
# db = firebase.database()
# print("retrieving")
# users = db.child("users").get()
# print('finished!\nall_users ->')
# for user in users.val().items():
# print(user)
# return users
# def getByServer(server):
# users = getData()
# nums = []
# if server == "BCS Pokemon Go":
# for user in users.each():
# # print(user.key())
# # print(user.val())
# userDict = user.val()
# if userDict["BCS Pokemon Go"].lower() == 'true': # stored as strings in firebase
# print("userDict[\"name\"] -> " + userDict["name"])
# print("userDict[\"phone\"] -> " + userDict["phone"])
# print("userDict[\"BCS Pokemon Go\"] -> " + userDict["BCS Pokemon Go"])
# nums.append(userDict["phone"])
# return nums
# if server == "Team Aqua's Hideout":
# for user in users.each():
# # print(user.key())
# # print(user.val())
# userDict = user.val()
# if userDict["Team Aqua's Hideout"].lower() == 'true': # stored as strings in firebase
# print("userDict[\"name\"] -> " + userDict["name"])
# print("userDict[\"phone\"] -> " + userDict["phone"])
# print("userDict[\"Team Aqua's Hideout\"] -> " + userDict["Team Aqua's Hideout"])
# nums.append(userDict["phone"])
# return nums
# return nums
# def remove(name):
# setUpServiceAccountFile()
# print("connecting")
# firebase = pyrebase.initialize_app(config)
# db = firebase.database()
# users = getData()
# removeKey = "not set"
# for user in users.each():
# # print(user.key())
# # print(user.val())
# userDict = user.val()
# if userDict["name"].lower() == name.lower(): # stored as strings in firebase
# print("Deleting user -> " + userDict["name"])
# print("user key -> " + user.key())
# removeKey = user.key()
# print("deleting")
# results = db.child("users").child(removeKey).remove()
# print("result from delete:")
# print(results)
def upload(data):
setUpServiceAccountFile()
print("connecting")
firebase = pyrebase.initialize_app(config)
db = firebase.database()
uploadPacket = {
"dateUploaded": str(datetime.now()),
"discord_name": data["discord_name"],
"team": data["team"],
"gym_name": data["gym_name"],
"date_extracted": data["date_extracted"],
"unprocessed_image_to_string": data["unprocessed_image_to_string"],
"image_url": data["image_url"]
}
print("pushing...")
results = db.child("ex_ocr_testing").push(uploadPacket)
print('finished!\nresults ->')
print(results)
def getData():
setUpServiceAccountFile()
print("connecting")
firebase = pyrebase.initialize_app(config)
db = firebase.database()
print("retrieving")
ocr_data = db.child("ex_ocr_testing").get()
print('finished!\nocr_data ->')
for item in ocr_data.val().items():
print(item)
return ocr_data
# def logPin(gym, user):
# setUpServiceAccountFile()
# print("connecting")
# firebase = pyrebase.initialize_app(config)
# db = firebase.database()
# data = {
# "date": str(datetime.now()),
# "gym": gym,
# "user": user
# }
# print("pushing...")
# results = db.child("pin_data").push(data)
# print('finished!\nresults ->')
# print(results)
# def getLogs():
# setUpServiceAccountFile()
# print("connecting")
# firebase = pyrebase.initialize_app(config)
# db = firebase.database()
# print("retrieving logs")
# data = db.child("logs").get()
# return data