soonmyeong2

make view_counter

1 wello_firebase_SDKKey.json 1 wello_firebase_SDKKey.json
2 -__pycache__
...\ No newline at end of file ...\ No newline at end of file
2 +__pycache__
3 +vip_key.jks
...\ No newline at end of file ...\ No newline at end of file
......
1 +{
2 + "0": {
3 + "2019-11-19": 14
4 + },
5 + "1": {
6 + "2019-11-19": 3
7 + },
8 + "2": {
9 + "2019-11-19": 13
10 + },
11 + "3": {
12 + "2019-11-19": 4
13 + },
14 + "4": {
15 + "2019-11-19": 3
16 + },
17 + "5": {
18 + "2019-11-19": 4
19 + },
20 + "6": {
21 + "2019-11-19": 6
22 + },
23 + "7": {
24 + "2019-11-19": 3
25 + },
26 + "8": {
27 + "2019-11-19": 4
28 + },
29 + "9": {
30 + "2019-11-19": 11
31 + }
32 +}
...\ No newline at end of file ...\ No newline at end of file
......
1 +from firebase_admin import db
2 +from firebase_admin import credentials
3 +import firebase_admin
4 +import json
5 +from datetime import datetime
6 +
7 +cred = credentials.Certificate('wello_firebase_SDKKey.json')
8 +firebase_admin.initialize_app(cred, {'databaseURL': 'https://capstone-vip.firebaseio.com/'})
9 +ref = db.reference()
10 +policies = ref.get()
11 +
12 +## compare dict
13 +json_data = dict()
14 +today = str(datetime.now().year) + "-" + str(datetime.now().month) + "-" + str(datetime.now().day)
15 +
16 +def view_count_raw_writer():
17 + with open('./view_count_raw.json', 'w', encoding='utf-8') as make_file:
18 + json.dump(json_data, make_file, indent="\t")
19 +
20 +
21 +def count_update():
22 + for policy in policies:
23 + if policy["Value"] in json_data.keys():
24 + if policy["Value"][datetime.now()] in json_data["Value"].keys():
25 + json_data[policy["Value"]][today] = abs(policy["View"])
26 + else:
27 + json_data[policy["Value"]][today] = dict()
28 + json_data[policy["Value"]][today] = abs(policy["View"])
29 + else:
30 + json_data[policy["Value"]] = dict()
31 + json_data[policy["Value"]][today] = abs(policy["View"])
32 +
33 +
34 +def view_count_raw_reader():
35 + with open('./view_count_raw.json', 'r', encoding='utf-8') as json_file:
36 + json_data = json.load(json_file)
37 +
38 +
39 +view_count_raw_reader()
40 +count_update()
41 +print(json.dumps(json_data, indent="\t"))
42 +view_count_raw_writer()