Showing
12 changed files
with
892 additions
and
0 deletions
backend/D_dayCalculator.py
0 → 100644
1 | +#-*- coding: utf-8 -*- | ||
2 | +from datetime import datetime, timedelta | ||
3 | +import re | ||
4 | + | ||
5 | +class D_day: | ||
6 | + def __init__(self, date_str): | ||
7 | + self.date = date_str | ||
8 | + | ||
9 | + def dday_calculate(self, date): | ||
10 | + y_m_d = date.split("-") | ||
11 | + return (datetime.now() - datetime(int(y_m_d[0]), int(y_m_d[1]), int(y_m_d[2]))).days | ||
12 | + | ||
13 | + | ||
14 | + def date_calculate(self): | ||
15 | + dates = re.findall(r'[0-9]{2,4}[.|-][0-9]{1,2}[.|-][0-9]{1,2}|~', self.date) | ||
16 | + | ||
17 | + for i in range(len(dates)): | ||
18 | + dates[i] = dates[i].replace(".", "-") | ||
19 | + | ||
20 | + # 날짜가 없는 경우 | ||
21 | + if len(dates) == 0: | ||
22 | + return "상시" | ||
23 | + | ||
24 | + # XXX ~ | ||
25 | + if dates[-1] == "~": | ||
26 | + dday = self.dday_calculate(dates[0]) | ||
27 | + if dday > 0: | ||
28 | + return "진행중" | ||
29 | + else: | ||
30 | + return "준비중" | ||
31 | + | ||
32 | + # XXX | ||
33 | + if len(dates) == 1: | ||
34 | + return str(dates[0]) | ||
35 | + | ||
36 | + # ~ XXX and XXX ~ XXX | ||
37 | + if dates[-1] != "~": | ||
38 | + dday = self.dday_calculate(dates[-1]) | ||
39 | + if dday < 0: | ||
40 | + return "D"+str(dday) | ||
41 | + else: | ||
42 | + return "종료" | ||
43 | + | ||
44 | + # except | ||
45 | + return "상 시" | ||
46 | + | ||
47 | + | ||
48 | + def update_date(self, date): | ||
49 | + self.date = date | ||
50 | + | ||
51 | +#### example | ||
52 | +''' | ||
53 | +a=D_day("2019.11.20") | ||
54 | +print(a.date_calculate()) | ||
55 | +a.update_date("2019.11.21") | ||
56 | +print(a.date_calculate()) | ||
57 | +a.update_date("~2019.11.30") | ||
58 | +print(a.date_calculate()) | ||
59 | +a.update_date("2019.10.11~2019.11.27") | ||
60 | +print(a.date_calculate()) | ||
61 | +a.update_date("2019.10.11~") | ||
62 | +print(a.date_calculate()) | ||
63 | +''' |
backend/README.md
0 → 100644
1 | +check_policy : | ||
2 | +* hash_policy.csv를 읽어와서 RSA256해싱 결과 값으로 디비랑 달라진 값 찾음 | ||
3 | +* csv 갱신하려면 policy_hash_writer(policies) 메소드 쓰면 된다. | ||
4 | + | ||
5 | +D_dayCalculator: | ||
6 | +* 날자 계산하는 클래스 파일 | ||
7 | + | ||
8 | +db_updater: | ||
9 | +* DB의 날자를 갱신해주는 파일, input 없이 실행만 시키면 된다. | ||
10 | + | ||
11 | +push_messaging: | ||
12 | +* push message를 보내는 파일 | ||
13 | +* 실행시켜서 input으로 카테고리 명을 띄어쓰기 없이 입력하면 해당 구독자에게 메세지 발생 | ||
14 | +** ex) c1_2c3_4c11_1 | ||
15 | + | ||
16 | +raw_preprocessing: | ||
17 | +* raw data 전처리 파일 | ||
18 | +* D-day를 계산해서 새로운 컬럼으로 추가해주고, 카테고리 명을 str로 변환시킨다. | ||
19 | +* 주소는 정규식과 그리디로 최초 url 발견시 리턴 없으면 None | ||
20 | +* input 값은 raw를 json으로 변환 시킨 것 | ||
21 | + | ||
22 | +view_counter | ||
23 | +* view_count_raw.json를 갱신 시킨다 | ||
24 | +* 날자별로 정책별 조회수를 전부 긁어와서 json으로 저장 | ||
25 | +* 날자별로 실행하면 그날의 조회수 조회 가능 | ||
26 | + | ||
27 | + | ||
28 | +raw_calculate_Dday -> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
backend/check_policy.py
0 → 100644
1 | +import hashlib | ||
2 | +from firebase_admin import db | ||
3 | +from firebase_admin import credentials | ||
4 | +import firebase_admin | ||
5 | +import csv | ||
6 | + | ||
7 | + | ||
8 | +cred = credentials.Certificate('wello_firebase_SDKKey.json') | ||
9 | +firebase_admin.initialize_app(cred, {'databaseURL': 'https://capstone-vip.firebaseio.com/'}) | ||
10 | +ref = db.reference() | ||
11 | +policies = ref.get() | ||
12 | + | ||
13 | +## compare dict | ||
14 | +policy_dict = dict() | ||
15 | + | ||
16 | +def policy_hash_writer(policies): | ||
17 | + with open('./hash_policy.csv', 'w', encoding='utf-8', newline='') as csvfile: | ||
18 | + wr = csv.writer(csvfile) | ||
19 | + | ||
20 | + for policy in policies: | ||
21 | + sha = hashlib.sha256() | ||
22 | + sha.update(str(policy).encode('utf-8')) | ||
23 | + wr.writerow([policy["Value"], sha.hexdigest()]) | ||
24 | + | ||
25 | + | ||
26 | +def policy_db_reader(): | ||
27 | + for policy in policies: | ||
28 | + if policy["Value"] in policy_dict.keys(): | ||
29 | + sha = hashlib.sha256() | ||
30 | + sha.update(str(policy).encode('utf-8')) | ||
31 | + if policy_dict[policy["Value"]] != sha.hexdigest(): | ||
32 | + print("change contents : ", policy["Value"], ".", policy["Policy"]) | ||
33 | + else: | ||
34 | + print("new policy : ", policy["Value"], ". ", policy["Policy"]) | ||
35 | + | ||
36 | + | ||
37 | +def policy_hash_reader(): | ||
38 | + with open('./hash_policy.csv', 'r', encoding='utf-8') as csvfile: | ||
39 | + rdr = csv.reader(csvfile) | ||
40 | + | ||
41 | + for r in rdr: | ||
42 | + policy_dict[r[0]] = r[1] | ||
43 | + | ||
44 | +#policy_hash_writer(policies) | ||
45 | +policy_hash_reader() | ||
46 | +policy_db_reader() |
backend/db_updater.py
0 → 100644
1 | +from firebase_admin import db | ||
2 | +from firebase_admin import credentials | ||
3 | +import firebase_admin | ||
4 | +from D_dayCalculator import D_day | ||
5 | +import json | ||
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 | + | ||
11 | +policies = ref.get() | ||
12 | +date = D_day("1970.01.01") | ||
13 | + | ||
14 | +#with open('view_count_raw.json', 'rt', encoding='utf-8') as json_file: | ||
15 | +# view_count = json.load(json_file) | ||
16 | + | ||
17 | + | ||
18 | +for policy in policies: | ||
19 | + # 날짜 갱신 | ||
20 | + date.update_date(policy["Date"]) | ||
21 | + print(date.date_calculate()) | ||
22 | + ref.child(policy["Value"]).child("D_day").set(date.date_calculate()) | ||
23 | + | ||
24 | + | ||
25 | + |
backend/find_url.py
0 → 100644
1 | +import re | ||
2 | + | ||
3 | + | ||
4 | +''' | ||
5 | +test cast: | ||
6 | + | ||
7 | +lines1 = "['mailto:psalms1273@merryyear.org', 'http://www.merryyear.org/abbs/?act=bbs&subAct=view&bid=Notice&page=1&order_index=no&order_type=desc&seq=1571']" | ||
8 | +lines = "['https://www.shinhanhope.com/web/main.jsp']" | ||
9 | +ll ="['https://www.childfund.or.kr/news/noticeView.do?bmTemplate=/inc/jsp/board/template/default&bdId=20019410&bmIds=10000023,10000097']" | ||
10 | +l="http://bokjiro.go.kr/gowf/wel/welsvc/svcsearch/WelGvmtSvcSearchView.do?servId=WII00000124" | ||
11 | +t = "https://welfare.gangdong.go.kr/site/contents/bokji/html00/html00/index3.html" | ||
12 | +''' | ||
13 | + | ||
14 | +def find_url_in_str(url) : | ||
15 | +# regex = re.compile(r'(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?[^\'\]](\/|\/([\w#!:.?+=&%@!\-\/]))?', re.IGNORECASE) | ||
16 | + regex = re.compile(r'https?://(\w*:\w*@)?[-\w.]+(:\d+)?(/([\w/_.]*(\?\S+)?)?[^\'\]])?', re.IGNORECASE) | ||
17 | + | ||
18 | + m = regex.search(url) | ||
19 | + if m != None: | ||
20 | + return m.group() | ||
21 | + return None | ||
22 | + | ||
23 | +find_url_in_str() |
backend/hash_policy.csv
0 → 100644
1 | +0,d24548533c984425a9a96cbd23e0085baed58a16d26d2764ee3e08f4ec9f2713 | ||
2 | +1,4f2e40e552527f48278fa2cdfadfa34e61c5a1672d82dc2ff42fcb4bff484cc2 | ||
3 | +2,7f41b893ec6ca567b928f9ba975c87e31db98a14fa6bc1c28431ab3a244cca43 | ||
4 | +3,fb6094dc6ba8c21846557664fda37a808f9877f35f301c444194b484e6cf38ae | ||
5 | +4,121b23de7cf0d313077a208739b7a202ddfe6442c3f62dd2ed0cb475411c3bb8 | ||
6 | +5,26e05536f3fc6a844af4a746ecd070157180e4787fb122cf18b5dc8b91d2ff63 | ||
7 | +6,2809644d986b0226b080fdffbe7d3d1453095a12984101edbaefbf61821a8848 | ||
8 | +7,c7e3ac97575b1006424d0f2a391df327dc249067f0361d604355700bbe780102 | ||
9 | +8,3d7f2a439aa277c88101b08d2af865d6610f9791b614d9bbcce5a5f424736bb5 | ||
10 | +9,fba861e8ecc5f5411dec793409f8a98a96cbbb738fba74be397294e288dc7a4b |
backend/push_messaging.py
0 → 100644
1 | +from firebase_admin import messaging | ||
2 | +from firebase_admin import credentials | ||
3 | +from firebase_admin import datetime | ||
4 | +from firebase_admin import db | ||
5 | +import firebase_admin | ||
6 | +import json | ||
7 | +import re | ||
8 | + | ||
9 | + | ||
10 | +cred = credentials.Certificate('wello_firebase_SDKKey.json') | ||
11 | +firebase_admin.initialize_app(cred, {'databaseURL': 'https://wello-topic.firebaseio.com/'}) | ||
12 | +ref = db.reference() | ||
13 | +topics = list(ref.get()) | ||
14 | +pre_topic = list() | ||
15 | + | ||
16 | + | ||
17 | +def send_to_topic(policy, topic): | ||
18 | + message = messaging.Message( | ||
19 | + android=messaging.AndroidConfig( | ||
20 | + ttl=datetime.timedelta(seconds=3600), | ||
21 | + priority='normal', | ||
22 | + notification=messaging.AndroidNotification( | ||
23 | + title='새 정책 알람', | ||
24 | + body=policy, | ||
25 | + icon='@drawable/mini', | ||
26 | + color='#29ABE2', | ||
27 | + sound='default' | ||
28 | + ), | ||
29 | + ), | ||
30 | + data={ | ||
31 | + 'score': '850', | ||
32 | + 'time': '2:45', | ||
33 | + }, | ||
34 | + webpush=messaging.WebpushConfig( | ||
35 | + notification=messaging.WebpushNotification( | ||
36 | + title='웹 알림', | ||
37 | + body='TEST', | ||
38 | + icon='', | ||
39 | + ), | ||
40 | + ), | ||
41 | + topic=topic, | ||
42 | + ) | ||
43 | + response = messaging.send(message) | ||
44 | + print('Successfully sent message:', response) | ||
45 | + | ||
46 | + | ||
47 | +for topic in topics: | ||
48 | + categorys = re.findall('c[0-9]+[_][0-9]+', topic) | ||
49 | + for i in range(len(categorys) - 1, -1, -1): | ||
50 | + if '1' == categorys[i].split('_')[-1]: | ||
51 | + categorys.pop(i) | ||
52 | + pre_topic.append(categorys) | ||
53 | + | ||
54 | + | ||
55 | +print('new policy category : ', end = '') | ||
56 | +policy = input() | ||
57 | +policy_category = re.findall('c[0-9]+[_][0-9]+', policy) | ||
58 | +policy_category_list = re.findall('c[0-9]+', policy) | ||
59 | +push_index = list() | ||
60 | +flag = True | ||
61 | + | ||
62 | + | ||
63 | +for i, categorys in enumerate(pre_topic): | ||
64 | + for category in categorys: | ||
65 | + if category.split('_')[0] in policy_category_list: | ||
66 | + if category not in policy_category: | ||
67 | + flag = False | ||
68 | + break | ||
69 | + if flag: push_index.append(i) | ||
70 | + flag = True | ||
71 | + | ||
72 | + | ||
73 | +for push in push_index: | ||
74 | + send_to_topic('[가정복지부] 기성이를 보유하신 가정에 지원금을 드립니다.', topics[push]) |
backend/raw_calculate.py
0 → 100644
1 | +#-*- coding: utf-8 -*- | ||
2 | +from datetime import datetime, timedelta | ||
3 | +import json | ||
4 | +import re | ||
5 | + | ||
6 | + | ||
7 | +def find_url_in_str(url) : | ||
8 | + regex = re.compile(r'https?://(\w*:\w*@)?[-\w.]+(:\d+)?(/([\w/_.]*(\?\S+)?)?[^\'\]])?', re.IGNORECASE) | ||
9 | + | ||
10 | + m = regex.search(url) | ||
11 | + if m != None: | ||
12 | + return m.group() | ||
13 | + return None | ||
14 | + | ||
15 | + | ||
16 | +def dday_calculate(date): | ||
17 | + y_m_d = date.split("-") | ||
18 | + return (datetime.now() - datetime(int(y_m_d[0]), int(y_m_d[1]), int(y_m_d[2]))).days | ||
19 | + | ||
20 | + | ||
21 | +def date_calculate(url): | ||
22 | + dates = re.findall(r'[0-9]{2,4}[.|-][0-9]{1,2}[.|-][0-9]{1,2}|~', url) | ||
23 | + | ||
24 | + for i in range(len(dates)): | ||
25 | + dates[i] = dates[i].replace(".", "-") | ||
26 | + | ||
27 | + # 날짜가 없는 경우 | ||
28 | + if len(dates) == 0: | ||
29 | + return "상시" | ||
30 | + | ||
31 | + # XXX ~ | ||
32 | + if dates[-1] == "~": | ||
33 | + dday = dday_calculate(dates[0]) | ||
34 | + if dday > 0: | ||
35 | + return "진행중" | ||
36 | + else: | ||
37 | + return "준비중" | ||
38 | + | ||
39 | + # XXX | ||
40 | + if len(dates) == 1: | ||
41 | + return "상시" | ||
42 | + | ||
43 | + # ~ XXX and XXX ~ XXX | ||
44 | + if dates[-1] != "~": | ||
45 | + dday = dday_calculate(dates[-1]) | ||
46 | + if dday < 0: | ||
47 | + return "D"+str(dday) | ||
48 | + else: | ||
49 | + return "종료" | ||
50 | + | ||
51 | + # except | ||
52 | + return "상 시" | ||
53 | + | ||
54 | + | ||
55 | + | ||
56 | +with open('db (2).json', 'rt', encoding='utf-8') as json_file: | ||
57 | + json_data = json.load(json_file) | ||
58 | + | ||
59 | + | ||
60 | +for js in json_data: | ||
61 | + for key, value in js.items(): | ||
62 | + if type(value) != str and key != 'View': | ||
63 | + js[key] = str(value) | ||
64 | + if key == "Link": | ||
65 | + js[key] = find_url_in_str(value) | ||
66 | + # critical point | ||
67 | + if key == "Keyword": | ||
68 | + js[key] = "[" + value.replace("[", "").replace("]", "") + "]" | ||
69 | + if key == "View": | ||
70 | + js["D_day"] = date_calculate(js["Date"]) | ||
71 | + break | ||
72 | + ############### | ||
73 | + | ||
74 | +with open('result1.json', 'w', encoding='utf-8') as make_file: | ||
75 | + make_file.write('[') | ||
76 | + for i, js in enumerate(json_data): | ||
77 | + json.dump(js, make_file, indent="\t", ensure_ascii=False) | ||
78 | + if i != len(json_data) - 1: | ||
79 | + make_file.write(',') | ||
80 | + make_file.write(']') |
backend/raw_preprocessing.py
0 → 100644
1 | +#-*- coding: utf-8 -*- | ||
2 | +from datetime import datetime, timedelta | ||
3 | +import json | ||
4 | +import re | ||
5 | + | ||
6 | + | ||
7 | +def dday_calculate(date): | ||
8 | + y_m_d = date.split("-") | ||
9 | + return (datetime.now() - datetime(int(y_m_d[0]), int(y_m_d[1]), int(y_m_d[2]))).days | ||
10 | + | ||
11 | + | ||
12 | +def date_calculate(url): | ||
13 | + dates = re.findall(r'[0-9]{2,4}[.|-][0-9]{1,2}[.|-][0-9]{1,2}|~', url) | ||
14 | + | ||
15 | + for i in range(len(dates)): | ||
16 | + dates[i] = dates[i].replace(".", "-") | ||
17 | + | ||
18 | + # 날짜가 없는 경우 | ||
19 | + if len(dates) == 0: | ||
20 | + return "상시" | ||
21 | + | ||
22 | + # XXX ~ | ||
23 | + if dates[-1] == "~": | ||
24 | + dday = dday_calculate(dates[0]) | ||
25 | + if dday > 0: | ||
26 | + return "진행중" | ||
27 | + else: | ||
28 | + return "준비중" | ||
29 | + | ||
30 | + # ~ XXX and XXX ~ XXX | ||
31 | + if dates[-1] != "~": | ||
32 | + dday = dday_calculate(dates[-1]) | ||
33 | + if dday < 0: | ||
34 | + return "D"+str(dday) | ||
35 | + else: | ||
36 | + return "종료" | ||
37 | + | ||
38 | + # except | ||
39 | + return "상 시" | ||
40 | + | ||
41 | + | ||
42 | + | ||
43 | +with open('d.json', 'rt', encoding='utf-8') as json_file: | ||
44 | + json_data = json.load(json_file) | ||
45 | + | ||
46 | + | ||
47 | +for js in json_data: | ||
48 | + for key, value in js.items(): | ||
49 | + if type(value) != str and key != 'View': | ||
50 | + js[key] = str(value) | ||
51 | + if key == "Link" and value[0] == '[': | ||
52 | + js[key] = value[1:-1] | ||
53 | + | ||
54 | + # critical point | ||
55 | + if key == "View": | ||
56 | + js["D_day"] = date_calculate(js["Date"]) | ||
57 | + break | ||
58 | + ############### | ||
59 | + | ||
60 | +with open('result.json', 'w', encoding='utf-8') as make_file: | ||
61 | + make_file.write('[') | ||
62 | + for i, js in enumerate(json_data): | ||
63 | + json.dump(js, make_file, indent="\t", ensure_ascii=False) | ||
64 | + if i != len(json_data) - 1: | ||
65 | + make_file.write(',') | ||
66 | + make_file.write(']') |
backend/sample_data.json
0 → 100644
This diff could not be displayed because it is too large.
backend/view_count_raw.json
0 → 100644
1 | +{ | ||
2 | + "0": { | ||
3 | + "2019-11-20": 27 | ||
4 | + }, | ||
5 | + "1": { | ||
6 | + "2019-11-20": 3 | ||
7 | + }, | ||
8 | + "2": { | ||
9 | + "2019-11-20": 26 | ||
10 | + }, | ||
11 | + "3": { | ||
12 | + "2019-11-20": 4 | ||
13 | + }, | ||
14 | + "4": { | ||
15 | + "2019-11-20": 3 | ||
16 | + }, | ||
17 | + "5": { | ||
18 | + "2019-11-20": 4 | ||
19 | + }, | ||
20 | + "6": { | ||
21 | + "2019-11-20": 7 | ||
22 | + }, | ||
23 | + "7": { | ||
24 | + "2019-11-20": 3 | ||
25 | + }, | ||
26 | + "8": { | ||
27 | + "2019-11-20": 4 | ||
28 | + }, | ||
29 | + "9": { | ||
30 | + "2019-11-20": 22 | ||
31 | + }, | ||
32 | + "10": { | ||
33 | + "2019-11-20": 0 | ||
34 | + }, | ||
35 | + "11": { | ||
36 | + "2019-11-20": 0 | ||
37 | + }, | ||
38 | + "12": { | ||
39 | + "2019-11-20": 0 | ||
40 | + }, | ||
41 | + "13": { | ||
42 | + "2019-11-20": 0 | ||
43 | + }, | ||
44 | + "14": { | ||
45 | + "2019-11-20": 0 | ||
46 | + }, | ||
47 | + "15": { | ||
48 | + "2019-11-20": 0 | ||
49 | + }, | ||
50 | + "16": { | ||
51 | + "2019-11-20": 0 | ||
52 | + }, | ||
53 | + "17": { | ||
54 | + "2019-11-20": 0 | ||
55 | + }, | ||
56 | + "18": { | ||
57 | + "2019-11-20": 0 | ||
58 | + }, | ||
59 | + "19": { | ||
60 | + "2019-11-20": 0 | ||
61 | + }, | ||
62 | + "20": { | ||
63 | + "2019-11-20": 0 | ||
64 | + }, | ||
65 | + "21": { | ||
66 | + "2019-11-20": 0 | ||
67 | + }, | ||
68 | + "22": { | ||
69 | + "2019-11-20": 0 | ||
70 | + }, | ||
71 | + "23": { | ||
72 | + "2019-11-20": 0 | ||
73 | + }, | ||
74 | + "24": { | ||
75 | + "2019-11-20": 0 | ||
76 | + }, | ||
77 | + "25": { | ||
78 | + "2019-11-20": 0 | ||
79 | + }, | ||
80 | + "26": { | ||
81 | + "2019-11-20": 0 | ||
82 | + }, | ||
83 | + "27": { | ||
84 | + "2019-11-20": 0 | ||
85 | + }, | ||
86 | + "28": { | ||
87 | + "2019-11-20": 0 | ||
88 | + }, | ||
89 | + "29": { | ||
90 | + "2019-11-20": 0 | ||
91 | + }, | ||
92 | + "30": { | ||
93 | + "2019-11-20": 0 | ||
94 | + }, | ||
95 | + "31": { | ||
96 | + "2019-11-20": 0 | ||
97 | + }, | ||
98 | + "32": { | ||
99 | + "2019-11-20": 0 | ||
100 | + }, | ||
101 | + "33": { | ||
102 | + "2019-11-20": 0 | ||
103 | + }, | ||
104 | + "34": { | ||
105 | + "2019-11-20": 0 | ||
106 | + }, | ||
107 | + "35": { | ||
108 | + "2019-11-20": 0 | ||
109 | + }, | ||
110 | + "36": { | ||
111 | + "2019-11-20": 0 | ||
112 | + }, | ||
113 | + "37": { | ||
114 | + "2019-11-20": 0 | ||
115 | + }, | ||
116 | + "38": { | ||
117 | + "2019-11-20": 0 | ||
118 | + }, | ||
119 | + "39": { | ||
120 | + "2019-11-20": 0 | ||
121 | + }, | ||
122 | + "40": { | ||
123 | + "2019-11-20": 0 | ||
124 | + }, | ||
125 | + "41": { | ||
126 | + "2019-11-20": 0 | ||
127 | + }, | ||
128 | + "42": { | ||
129 | + "2019-11-20": 0 | ||
130 | + }, | ||
131 | + "43": { | ||
132 | + "2019-11-20": 0 | ||
133 | + }, | ||
134 | + "44": { | ||
135 | + "2019-11-20": 0 | ||
136 | + }, | ||
137 | + "45": { | ||
138 | + "2019-11-20": 0 | ||
139 | + }, | ||
140 | + "46": { | ||
141 | + "2019-11-20": 0 | ||
142 | + }, | ||
143 | + "47": { | ||
144 | + "2019-11-20": 0 | ||
145 | + }, | ||
146 | + "48": { | ||
147 | + "2019-11-20": 0 | ||
148 | + }, | ||
149 | + "49": { | ||
150 | + "2019-11-20": 0 | ||
151 | + }, | ||
152 | + "50": { | ||
153 | + "2019-11-20": 0 | ||
154 | + }, | ||
155 | + "51": { | ||
156 | + "2019-11-20": 0 | ||
157 | + }, | ||
158 | + "52": { | ||
159 | + "2019-11-20": 0 | ||
160 | + }, | ||
161 | + "53": { | ||
162 | + "2019-11-20": 0 | ||
163 | + }, | ||
164 | + "54": { | ||
165 | + "2019-11-20": 0 | ||
166 | + }, | ||
167 | + "55": { | ||
168 | + "2019-11-20": 0 | ||
169 | + }, | ||
170 | + "56": { | ||
171 | + "2019-11-20": 0 | ||
172 | + }, | ||
173 | + "57": { | ||
174 | + "2019-11-20": 0 | ||
175 | + }, | ||
176 | + "58": { | ||
177 | + "2019-11-20": 0 | ||
178 | + }, | ||
179 | + "59": { | ||
180 | + "2019-11-20": 0 | ||
181 | + }, | ||
182 | + "60": { | ||
183 | + "2019-11-20": 0 | ||
184 | + }, | ||
185 | + "61": { | ||
186 | + "2019-11-20": 0 | ||
187 | + }, | ||
188 | + "62": { | ||
189 | + "2019-11-20": 0 | ||
190 | + }, | ||
191 | + "63": { | ||
192 | + "2019-11-20": 0 | ||
193 | + }, | ||
194 | + "64": { | ||
195 | + "2019-11-20": 0 | ||
196 | + }, | ||
197 | + "65": { | ||
198 | + "2019-11-20": 0 | ||
199 | + }, | ||
200 | + "66": { | ||
201 | + "2019-11-20": 0 | ||
202 | + }, | ||
203 | + "67": { | ||
204 | + "2019-11-20": 0 | ||
205 | + }, | ||
206 | + "68": { | ||
207 | + "2019-11-20": 0 | ||
208 | + }, | ||
209 | + "69": { | ||
210 | + "2019-11-20": 0 | ||
211 | + }, | ||
212 | + "70": { | ||
213 | + "2019-11-20": 0 | ||
214 | + }, | ||
215 | + "71": { | ||
216 | + "2019-11-20": 0 | ||
217 | + }, | ||
218 | + "72": { | ||
219 | + "2019-11-20": 0 | ||
220 | + }, | ||
221 | + "73": { | ||
222 | + "2019-11-20": 0 | ||
223 | + }, | ||
224 | + "74": { | ||
225 | + "2019-11-20": 0 | ||
226 | + }, | ||
227 | + "75": { | ||
228 | + "2019-11-20": 0 | ||
229 | + }, | ||
230 | + "76": { | ||
231 | + "2019-11-20": 0 | ||
232 | + }, | ||
233 | + "77": { | ||
234 | + "2019-11-20": 0 | ||
235 | + }, | ||
236 | + "78": { | ||
237 | + "2019-11-20": 0 | ||
238 | + }, | ||
239 | + "79": { | ||
240 | + "2019-11-20": 0 | ||
241 | + }, | ||
242 | + "80": { | ||
243 | + "2019-11-20": 0 | ||
244 | + }, | ||
245 | + "81": { | ||
246 | + "2019-11-20": 0 | ||
247 | + }, | ||
248 | + "82": { | ||
249 | + "2019-11-20": 0 | ||
250 | + }, | ||
251 | + "83": { | ||
252 | + "2019-11-20": 0 | ||
253 | + }, | ||
254 | + "84": { | ||
255 | + "2019-11-20": 0 | ||
256 | + }, | ||
257 | + "85": { | ||
258 | + "2019-11-20": 0 | ||
259 | + }, | ||
260 | + "86": { | ||
261 | + "2019-11-20": 0 | ||
262 | + }, | ||
263 | + "87": { | ||
264 | + "2019-11-20": 0 | ||
265 | + }, | ||
266 | + "88": { | ||
267 | + "2019-11-20": 0 | ||
268 | + }, | ||
269 | + "89": { | ||
270 | + "2019-11-20": 0 | ||
271 | + }, | ||
272 | + "90": { | ||
273 | + "2019-11-20": 1 | ||
274 | + }, | ||
275 | + "91": { | ||
276 | + "2019-11-20": 0 | ||
277 | + }, | ||
278 | + "92": { | ||
279 | + "2019-11-20": 0 | ||
280 | + }, | ||
281 | + "93": { | ||
282 | + "2019-11-20": 0 | ||
283 | + }, | ||
284 | + "94": { | ||
285 | + "2019-11-20": 0 | ||
286 | + }, | ||
287 | + "95": { | ||
288 | + "2019-11-20": 0 | ||
289 | + }, | ||
290 | + "96": { | ||
291 | + "2019-11-20": 0 | ||
292 | + }, | ||
293 | + "97": { | ||
294 | + "2019-11-20": 0 | ||
295 | + }, | ||
296 | + "98": { | ||
297 | + "2019-11-20": 0 | ||
298 | + }, | ||
299 | + "99": { | ||
300 | + "2019-11-20": 0 | ||
301 | + }, | ||
302 | + "100": { | ||
303 | + "2019-11-20": 0 | ||
304 | + }, | ||
305 | + "101": { | ||
306 | + "2019-11-20": 0 | ||
307 | + }, | ||
308 | + "102": { | ||
309 | + "2019-11-20": 0 | ||
310 | + }, | ||
311 | + "103": { | ||
312 | + "2019-11-20": 0 | ||
313 | + }, | ||
314 | + "104": { | ||
315 | + "2019-11-20": 0 | ||
316 | + }, | ||
317 | + "105": { | ||
318 | + "2019-11-20": 0 | ||
319 | + }, | ||
320 | + "106": { | ||
321 | + "2019-11-20": 0 | ||
322 | + }, | ||
323 | + "107": { | ||
324 | + "2019-11-20": 0 | ||
325 | + }, | ||
326 | + "108": { | ||
327 | + "2019-11-20": 0 | ||
328 | + }, | ||
329 | + "109": { | ||
330 | + "2019-11-20": 0 | ||
331 | + }, | ||
332 | + "110": { | ||
333 | + "2019-11-20": 0 | ||
334 | + }, | ||
335 | + "111": { | ||
336 | + "2019-11-20": 0 | ||
337 | + }, | ||
338 | + "112": { | ||
339 | + "2019-11-20": 0 | ||
340 | + }, | ||
341 | + "113": { | ||
342 | + "2019-11-20": 0 | ||
343 | + }, | ||
344 | + "114": { | ||
345 | + "2019-11-20": 0 | ||
346 | + }, | ||
347 | + "115": { | ||
348 | + "2019-11-20": 0 | ||
349 | + }, | ||
350 | + "116": { | ||
351 | + "2019-11-20": 0 | ||
352 | + }, | ||
353 | + "117": { | ||
354 | + "2019-11-20": 0 | ||
355 | + }, | ||
356 | + "118": { | ||
357 | + "2019-11-20": 0 | ||
358 | + }, | ||
359 | + "119": { | ||
360 | + "2019-11-20": 0 | ||
361 | + }, | ||
362 | + "120": { | ||
363 | + "2019-11-20": 0 | ||
364 | + }, | ||
365 | + "121": { | ||
366 | + "2019-11-20": 0 | ||
367 | + }, | ||
368 | + "122": { | ||
369 | + "2019-11-20": 0 | ||
370 | + }, | ||
371 | + "123": { | ||
372 | + "2019-11-20": 0 | ||
373 | + }, | ||
374 | + "124": { | ||
375 | + "2019-11-20": 0 | ||
376 | + }, | ||
377 | + "125": { | ||
378 | + "2019-11-20": 0 | ||
379 | + }, | ||
380 | + "126": { | ||
381 | + "2019-11-20": 0 | ||
382 | + }, | ||
383 | + "127": { | ||
384 | + "2019-11-20": 0 | ||
385 | + }, | ||
386 | + "128": { | ||
387 | + "2019-11-20": 0 | ||
388 | + }, | ||
389 | + "129": { | ||
390 | + "2019-11-20": 0 | ||
391 | + }, | ||
392 | + "130": { | ||
393 | + "2019-11-20": 0 | ||
394 | + }, | ||
395 | + "131": { | ||
396 | + "2019-11-20": 0 | ||
397 | + }, | ||
398 | + "132": { | ||
399 | + "2019-11-20": 0 | ||
400 | + }, | ||
401 | + "133": { | ||
402 | + "2019-11-20": 0 | ||
403 | + }, | ||
404 | + "134": { | ||
405 | + "2019-11-20": 0 | ||
406 | + }, | ||
407 | + "135": { | ||
408 | + "2019-11-20": 0 | ||
409 | + }, | ||
410 | + "136": { | ||
411 | + "2019-11-20": 0 | ||
412 | + }, | ||
413 | + "137": { | ||
414 | + "2019-11-20": 0 | ||
415 | + }, | ||
416 | + "138": { | ||
417 | + "2019-11-20": 0 | ||
418 | + }, | ||
419 | + "139": { | ||
420 | + "2019-11-20": 0 | ||
421 | + }, | ||
422 | + "140": { | ||
423 | + "2019-11-20": 0 | ||
424 | + }, | ||
425 | + "141": { | ||
426 | + "2019-11-20": 1 | ||
427 | + }, | ||
428 | + "142": { | ||
429 | + "2019-11-20": 0 | ||
430 | + }, | ||
431 | + "143": { | ||
432 | + "2019-11-20": 0 | ||
433 | + } | ||
434 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
backend/view_counter.py
0 → 100644
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 today in json_data[policy["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 | + global json_data | ||
37 | + json_data = json.load(json_file) | ||
38 | + | ||
39 | + | ||
40 | +view_count_raw_reader() | ||
41 | +count_update() | ||
42 | +print(json.dumps(json_data, indent="\t")) | ||
43 | +view_count_raw_writer() |
-
Please register or login to post a comment