soonmyeong2

make view_counter

wello_firebase_SDKKey.json
__pycache__
vip_key.jks
\ No newline at end of file
......
{
"0": {
"2019-11-19": 14
},
"1": {
"2019-11-19": 3
},
"2": {
"2019-11-19": 13
},
"3": {
"2019-11-19": 4
},
"4": {
"2019-11-19": 3
},
"5": {
"2019-11-19": 4
},
"6": {
"2019-11-19": 6
},
"7": {
"2019-11-19": 3
},
"8": {
"2019-11-19": 4
},
"9": {
"2019-11-19": 11
}
}
\ No newline at end of file
......
from firebase_admin import db
from firebase_admin import credentials
import firebase_admin
import json
from datetime import datetime
cred = credentials.Certificate('wello_firebase_SDKKey.json')
firebase_admin.initialize_app(cred, {'databaseURL': 'https://capstone-vip.firebaseio.com/'})
ref = db.reference()
policies = ref.get()
## compare dict
json_data = dict()
today = str(datetime.now().year) + "-" + str(datetime.now().month) + "-" + str(datetime.now().day)
def view_count_raw_writer():
with open('./view_count_raw.json', 'w', encoding='utf-8') as make_file:
json.dump(json_data, make_file, indent="\t")
def count_update():
for policy in policies:
if policy["Value"] in json_data.keys():
if policy["Value"][datetime.now()] in json_data["Value"].keys():
json_data[policy["Value"]][today] = abs(policy["View"])
else:
json_data[policy["Value"]][today] = dict()
json_data[policy["Value"]][today] = abs(policy["View"])
else:
json_data[policy["Value"]] = dict()
json_data[policy["Value"]][today] = abs(policy["View"])
def view_count_raw_reader():
with open('./view_count_raw.json', 'r', encoding='utf-8') as json_file:
json_data = json.load(json_file)
view_count_raw_reader()
count_update()
print(json.dumps(json_data, indent="\t"))
view_count_raw_writer()