soonmyeong2

make auto date_calculate file

wello_firebase_SDKKey.json
\ No newline at end of file
wello_firebase_SDKKey.json
__pycache__
\ No newline at end of file
......
#-*- coding: utf-8 -*-
from datetime import datetime, timedelta
import re
class D_day:
def __init__(self, date_str):
self.date = date_str
def dday_calculate(self, date):
y_m_d = date.split("-")
return (datetime.now() - datetime(int(y_m_d[0]), int(y_m_d[1]), int(y_m_d[2]))).days
def date_calculate(self):
dates = re.findall(r'[0-9]{2,4}[.|-][0-9]{1,2}[.|-][0-9]{1,2}|~', self.date)
for i in range(len(dates)):
dates[i] = dates[i].replace(".", "-")
# 날짜가 없는 경우
if len(dates) == 0:
return "상시"
# XXX ~
if dates[-1] == "~":
dday = self.dday_calculate(dates[0])
if dday > 0:
return "진행중"
else:
return "준비중"
# ~ XXX and XXX ~ XXX
if dates[-1] != "~":
dday = self.dday_calculate(dates[-1])
if dday < 0:
return "D"+str(dday)
else:
return "종료"
# except
return "상 시"
def update_date(self, date):
self.date = date
#### example
'''
a=D_day("2019.11.20")
print(a.date_calculate())
a.update_date("2019.11.21")
print(a.date_calculate())
a.update_date("~2019.11.30")
print(a.date_calculate())
a.update_date("2019.10.11~2019.11.27")
print(a.date_calculate())
a.update_date("2019.10.11~")
print(a.date_calculate())
'''
from firebase_admin import db
from firebase_admin import credentials
import firebase_admin
from D_dayCalculator import D_day
import json
cred = credentials.Certificate('wello_firebase_SDKKey.json')
firebase_admin.initialize_app(cred, {'databaseURL': 'https://wello-pocliy-temp.firebaseio.com/'})
ref = db.reference()
policies = ref.get()
date = D_day("1970.01.01")
with open('view_count_raw.json', 'rt', encoding='utf-8') as json_file:
view_count = json.load(json_file)
for policy in policies:
# 날짜 갱신
date.update_date(policy["Date"])
print(date.date_calculate())
ref.child(policy["Value"]).child("D_day").set(date.date_calculate())
......@@ -3,7 +3,7 @@ from datetime import datetime, timedelta
import json
import re
'''
def dday_calculate(date):
y_m_d = date.split("-")
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):
# except
return "상 시"
'''
with open('d.json', 'rt', encoding='utf-8') as json_file:
......@@ -50,14 +50,16 @@ for js in json_data:
js[key] = str(value)
if key == "Link" and value[0] == '[':
js[key] = value[1:-1]
# if key == "Date":
# js[key] = date_calculate(value)
# critical point
if key == "View":
js["D_day"] = date_calculate(js["Date"])
break
###############
with open('result.json', 'w', encoding='utf-8') as make_file:
make_file.write('[')
for i, js in enumerate(json_data):
#make_file.write(json.dumps(js, indent="\t",ensure_ascii=False))
json.dump(js, make_file, indent="\t", ensure_ascii=False)
if i != len(json_data) - 1:
make_file.write(',')
......
File mode changed
......@@ -42,7 +42,8 @@ data class MemoItemDetail(
val Keyword : String = "",
val Content : String = "",
val Link : String = "",
val Date : String = "상시"
val Date : String = "상시",
val D_day : String = ""
)
class DetailActivity : AppCompatActivity() {
......@@ -75,7 +76,7 @@ class DetailActivity : AppCompatActivity() {
var detailFavor: TextView =findViewById(R.id.policyFavorDetail)
detailImage.setImageResource(R.drawable.image01)
detailDday.text=memo!!.Date
detailDday.text=memo!!.D_day
detailTitle.text=memo!!.Policy
detailScore.rating=4.toFloat()
detailFavor.text= " " + memo!!.Keyword
......
......@@ -79,9 +79,8 @@
android:id="@+id/policyFavorDetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:text="TextView" />
<TextView
......@@ -109,7 +108,8 @@
<WebView
android:id="@+id/policy_context"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</ScrollView>
......