-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata_collection.py
More file actions
50 lines (41 loc) · 1.4 KB
/
Copy pathdata_collection.py
File metadata and controls
50 lines (41 loc) · 1.4 KB
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
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
import json
import os
class DataService:
instance = None
def __init__(self):
self.running_locally = False
# Use a service account
try:
cred_object = json.loads(
os.getenv('GOOGLE_APPLICATION_CREDENTIALS'))
except:
print(
"Please set GOOGLE_APPLICATION_CREDENTIALS environmental variable. See readme for more info"
)
return
cred = credentials.Certificate(cred_object)
firebase_admin.initialize_app(cred)
# only store code written on live heroku
if "SHOULD_WRITE_TO_DATABASE" not in os.environ:
self.running_locally = True
self.db = firestore.client()
@staticmethod
def getInstance():
if DataService.instance:
return DataService.instance
else:
DataService.instance = DataService()
return DataService.instance
def writeQuery(self, input_code, output_code, input_lang, output_lang):
if self.running_locally:
return
doc_ref = self.db.collection(u'user-query').document()
doc_ref.set({
u'input_code': input_code,
u'output_code': output_code,
u'input_lang': input_lang,
u'output_lang': output_lang
})