|
@@ -0,0 +1,100 @@
|
|
|
+import requests
|
|
|
+import datetime
|
|
|
+from dateutil import parser
|
|
|
+import gspread
|
|
|
+from oauth2client.service_account import ServiceAccountCredentials
|
|
|
+import time
|
|
|
+import sys
|
|
|
+import dataset
|
|
|
+import codecs
|
|
|
+import networkx as nx
|
|
|
+
|
|
|
+db = dataset.connect('sqlite:///:memory:')
|
|
|
+table=db['tmp']
|
|
|
+# drop this at PUBLIC2
|
|
|
+
|
|
|
+# TASK LIST HERE
|
|
|
+# https://docs.google.com/spreadsheets/d/153w046qHhpnZTYU7FJ-S2xyGIH_BXbycLYfLI2fFsZc/edit#gid=0
|
|
|
+
|
|
|
+scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
|
|
|
+creds = ServiceAccountCredentials.from_json_keyfile_name('c:/keys/choozmointernal-2e314f3d4e12.json', scope)
|
|
|
+client = gspread.authorize(creds)
|
|
|
+message = "提醒近期預定執行的作業如下:\n\n"
|
|
|
+message2 = "提醒近期需完成的作業如下:\n\n"
|
|
|
+
|
|
|
+def notify_group(msg):
|
|
|
+ gid='WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD'
|
|
|
+ headers = {"Authorization": "Bearer " + gid,"Content-Type": "application/x-www-form-urlencoded"}
|
|
|
+ print(msg)
|
|
|
+# r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params={"message": msg})
|
|
|
+
|
|
|
+sheet = client.open('ChoozMo 專案執行表單_20220720')
|
|
|
+sheet_instance = sheet.get_worksheet(0)
|
|
|
+
|
|
|
+records_data = sheet_instance.get_all_records()
|
|
|
+#print(records_data[0])
|
|
|
+
|
|
|
+rowidx=1
|
|
|
+for data in records_data:
|
|
|
+ data['rownum']=rowidx
|
|
|
+ print(data['完成日'].strip())
|
|
|
+ print(len(data['完成日'].strip()))
|
|
|
+
|
|
|
+ if len(data['完成日'].strip())<=2:
|
|
|
+ dtstr=None
|
|
|
+ data['完成日']=None
|
|
|
+ elif len(data['完成日'].strip())<8:
|
|
|
+ dtstr='2022/'+data['完成日']
|
|
|
+ if dtstr is not None:
|
|
|
+ data['完成日']=datetime.datetime.strptime(dtstr, '%Y/%m/%d')
|
|
|
+# print(datetime.datetime.strptime(dtstr, '%Y/%m/%d'))
|
|
|
+# data['完成日']=
|
|
|
+
|
|
|
+ table.insert(data)
|
|
|
+ rowidx+=1
|
|
|
+#cursor=db.query("select *, Cast (julianday('now') - julianday(完成日) as integer) as dt from tmp order by 專案來源,專案")
|
|
|
+cursor=db.query("select *, julianday('2022-08-01') - julianday(完成日) as dt from tmp order by 專案來源,專案")
|
|
|
+
|
|
|
+#[#red]
|
|
|
+
|
|
|
+fw=codecs.open('C:\\gitlab\\worklog\\docs\\test.md','w','utf-8')
|
|
|
+fw.write('# example \n\n')
|
|
|
+fw.write('```plantuml\n')
|
|
|
+fw.write('@startmindmap\n')
|
|
|
+fw.write('+ 專案管理\n')
|
|
|
+
|
|
|
+G = nx.DiGraph()
|
|
|
+prev=None
|
|
|
+for c in cursor:
|
|
|
+ G.add_edge('root', c['專案來源'])
|
|
|
+ G.add_edge(c['專案來源'], c['專案'])
|
|
|
+ if c['專案項目'] is not None:
|
|
|
+ if len(c['專案項目'].strip())>0:
|
|
|
+ if c['dt'] is not None and c['dt']>=0:
|
|
|
+ G.add_edge(c['專案'], '過期:'+c['專案項目'])
|
|
|
+ else:
|
|
|
+ G.add_edge(c['專案'], c['專案項目'])
|
|
|
+
|
|
|
+
|
|
|
+l1=list(G.successors('root'))
|
|
|
+print(l1)
|
|
|
+for l2 in l1:
|
|
|
+ fw.write('++ '+l2+'\n')
|
|
|
+ print(l2)
|
|
|
+ l3=list(G.successors(l2))
|
|
|
+ for l4 in l3:
|
|
|
+ print(l4)
|
|
|
+ fw.write('+++ '+l4+'\n')
|
|
|
+ l5=list(G.successors(l4))
|
|
|
+ for l6 in l5:
|
|
|
+ print(l6)
|
|
|
+ if '過期:' in l6:
|
|
|
+ fw.write('++++[#red] '+l6+'\n')
|
|
|
+ else:
|
|
|
+ fw.write('++++_ '+l6+'\n')
|
|
|
+
|
|
|
+fw.write('@endmindmap\n')
|
|
|
+fw.write('```\n')
|
|
|
+fw.close()
|
|
|
+
|
|
|
+sys.exit()
|