-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworddata.py
More file actions
53 lines (41 loc) · 1.36 KB
/
worddata.py
File metadata and controls
53 lines (41 loc) · 1.36 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
51
52
53
# -*- coding: utf-8 -*-
"""
Created on Thu June 10 00:00:00 2022
@author: Yuichiro Iwashita
"""
# Modules
# Firebase Admin
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
# JSON
import json
import codecs
def parse_json_files(filename):
path = 'json/' + filename
json_open = codecs.open(path, 'r', 'utf-8-sig')
json_load = json.load(json_open)
print(json_load)
print('Parsed: ' + path)
return json_load
def upload_namelist_to_firestore():
if not len(firebase_admin._apps):
cred = credentials.Certificate("ServiceAccountKey.json")
firebase_admin.initialize_app(cred)
db = firestore.client()
doc_ref = db.collection(u'worddata').document('namelist') # Write Firestore path
filename = 'namelist.json'
data = parse_json_files(filename)
doc_ref.set({'namelist': data}, merge=True)
def upload_lemma_to_firestore():
if not len(firebase_admin._apps):
cred = credentials.Certificate("ServiceAccountKey.json")
firebase_admin.initialize_app(cred)
db = firestore.client()
doc_ref = db.collection('worddata').document('lemma') # Write Firestore path
filename = 'lemma.json'
data = parse_json_files(filename)
doc_ref.set({'lemma': data}, merge=True)
if __name__ == '__main__':
upload_namelist_to_firestore()
upload_lemma_to_firestore()