Showing
7 changed files
with
98 additions
and
10 deletions
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 and XXX ~ XXX | ||
33 | + if dates[-1] != "~": | ||
34 | + dday = self.dday_calculate(dates[-1]) | ||
35 | + if dday < 0: | ||
36 | + return "D"+str(dday) | ||
37 | + else: | ||
38 | + return "종료" | ||
39 | + | ||
40 | + # except | ||
41 | + return "상 시" | ||
42 | + | ||
43 | + | ||
44 | + def update_date(self, date): | ||
45 | + self.date = date | ||
46 | + | ||
47 | +#### example | ||
48 | +''' | ||
49 | +a=D_day("2019.11.20") | ||
50 | +print(a.date_calculate()) | ||
51 | +a.update_date("2019.11.21") | ||
52 | +print(a.date_calculate()) | ||
53 | +a.update_date("~2019.11.30") | ||
54 | +print(a.date_calculate()) | ||
55 | +a.update_date("2019.10.11~2019.11.27") | ||
56 | +print(a.date_calculate()) | ||
57 | +a.update_date("2019.10.11~") | ||
58 | +print(a.date_calculate()) | ||
59 | +''' |
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://wello-pocliy-temp.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 | + |
... | @@ -3,7 +3,7 @@ from datetime import datetime, timedelta | ... | @@ -3,7 +3,7 @@ from datetime import datetime, timedelta |
3 | import json | 3 | import json |
4 | import re | 4 | import re |
5 | 5 | ||
6 | -''' | 6 | + |
7 | def dday_calculate(date): | 7 | def dday_calculate(date): |
8 | y_m_d = date.split("-") | 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 | 9 | return (datetime.now() - datetime(int(y_m_d[0]), int(y_m_d[1]), int(y_m_d[2]))).days |
... | @@ -37,7 +37,7 @@ def date_calculate(url): | ... | @@ -37,7 +37,7 @@ def date_calculate(url): |
37 | 37 | ||
38 | # except | 38 | # except |
39 | return "상 시" | 39 | return "상 시" |
40 | -''' | 40 | + |
41 | 41 | ||
42 | 42 | ||
43 | with open('d.json', 'rt', encoding='utf-8') as json_file: | 43 | with open('d.json', 'rt', encoding='utf-8') as json_file: |
... | @@ -50,14 +50,16 @@ for js in json_data: | ... | @@ -50,14 +50,16 @@ for js in json_data: |
50 | js[key] = str(value) | 50 | js[key] = str(value) |
51 | if key == "Link" and value[0] == '[': | 51 | if key == "Link" and value[0] == '[': |
52 | js[key] = value[1:-1] | 52 | js[key] = value[1:-1] |
53 | -# if key == "Date": | ||
54 | -# js[key] = date_calculate(value) | ||
55 | 53 | ||
54 | + # critical point | ||
55 | + if key == "View": | ||
56 | + js["D_day"] = date_calculate(js["Date"]) | ||
57 | + break | ||
58 | + ############### | ||
56 | 59 | ||
57 | with open('result.json', 'w', encoding='utf-8') as make_file: | 60 | with open('result.json', 'w', encoding='utf-8') as make_file: |
58 | make_file.write('[') | 61 | make_file.write('[') |
59 | for i, js in enumerate(json_data): | 62 | for i, js in enumerate(json_data): |
60 | - #make_file.write(json.dumps(js, indent="\t",ensure_ascii=False)) | ||
61 | json.dump(js, make_file, indent="\t", ensure_ascii=False) | 63 | json.dump(js, make_file, indent="\t", ensure_ascii=False) |
62 | if i != len(json_data) - 1: | 64 | if i != len(json_data) - 1: |
63 | make_file.write(',') | 65 | make_file.write(',') | ... | ... |
view_count_raw.json
0 → 100644
File mode changed
... | @@ -42,7 +42,8 @@ data class MemoItemDetail( | ... | @@ -42,7 +42,8 @@ data class MemoItemDetail( |
42 | val Keyword : String = "", | 42 | val Keyword : String = "", |
43 | val Content : String = "", | 43 | val Content : String = "", |
44 | val Link : String = "", | 44 | val Link : String = "", |
45 | - val Date : String = "상시" | 45 | + val Date : String = "상시", |
46 | + val D_day : String = "" | ||
46 | ) | 47 | ) |
47 | 48 | ||
48 | class DetailActivity : AppCompatActivity() { | 49 | class DetailActivity : AppCompatActivity() { |
... | @@ -75,7 +76,7 @@ class DetailActivity : AppCompatActivity() { | ... | @@ -75,7 +76,7 @@ class DetailActivity : AppCompatActivity() { |
75 | var detailFavor: TextView =findViewById(R.id.policyFavorDetail) | 76 | var detailFavor: TextView =findViewById(R.id.policyFavorDetail) |
76 | 77 | ||
77 | detailImage.setImageResource(R.drawable.image01) | 78 | detailImage.setImageResource(R.drawable.image01) |
78 | - detailDday.text=memo!!.Date | 79 | + detailDday.text=memo!!.D_day |
79 | detailTitle.text=memo!!.Policy | 80 | detailTitle.text=memo!!.Policy |
80 | detailScore.rating=4.toFloat() | 81 | detailScore.rating=4.toFloat() |
81 | detailFavor.text= " " + memo!!.Keyword | 82 | detailFavor.text= " " + memo!!.Keyword | ... | ... |
... | @@ -79,9 +79,8 @@ | ... | @@ -79,9 +79,8 @@ |
79 | android:id="@+id/policyFavorDetail" | 79 | android:id="@+id/policyFavorDetail" |
80 | android:layout_width="wrap_content" | 80 | android:layout_width="wrap_content" |
81 | android:layout_height="wrap_content" | 81 | android:layout_height="wrap_content" |
82 | - android:layout_weight="1" | ||
83 | - android:ellipsize="end" | ||
84 | android:layout_marginTop="5dp" | 82 | android:layout_marginTop="5dp" |
83 | + android:ellipsize="end" | ||
85 | android:text="TextView" /> | 84 | android:text="TextView" /> |
86 | 85 | ||
87 | <TextView | 86 | <TextView |
... | @@ -109,7 +108,8 @@ | ... | @@ -109,7 +108,8 @@ |
109 | <WebView | 108 | <WebView |
110 | android:id="@+id/policy_context" | 109 | android:id="@+id/policy_context" |
111 | android:layout_width="match_parent" | 110 | android:layout_width="match_parent" |
112 | - android:layout_height="wrap_content" /> | 111 | + android:layout_height="wrap_content" |
112 | + android:layout_weight="1" /> | ||
113 | </LinearLayout> | 113 | </LinearLayout> |
114 | </LinearLayout> | 114 | </LinearLayout> |
115 | </ScrollView> | 115 | </ScrollView> | ... | ... |
-
Please register or login to post a comment