log_scan.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import subprocess
  2. import requests
  3. import datetime
  4. import os
  5. import glob
  6. from os import listdir
  7. from os.path import isfile, join
  8. all_ids=['Jared','Hana','huai-sian','jesseng','conradlan','mike','Hong','andy','nina','CJYen','ccc','miacheng913','noodlesloves','yukyo0821','ming']
  9. all_ids=['Jared','Hana','huai-sian','jesseng','conradlan','mike','Hong','andy','nina','CJYen','ccc','miacheng913','noodlesloves','yukyo0821','ming']
  10. weekday_ids={1:[all_ids],2:[all_ids],3:[all_ids],4:[all_ids],5:[all_ids]}
  11. #git_ids=['Jared']
  12. #,'Hana','huai-sian','jesseng','conradlan','mike','Hong','andy','nina','CJYen','ccc','miacheng913','noodlesloves','yukyo0821','ming']
  13. def notify_group(msg):
  14. gid='WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD'
  15. headers = {"Authorization": "Bearer " + gid,"Content-Type": "application/x-www-form-urlencoded"}
  16. r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params={"message": msg})
  17. #os.system("git log --author Jared --date=short --after=2021-12-20")
  18. #lines=subprocess.run(['git','log','--author','Jared'], capture_output=True)
  19. """ allids=""
  20. for gid in git_ids:
  21. ot=subprocess.run(['git','log','--author',gid,'--date=short','--after=2021-12-20'], capture_output=True)
  22. print(ot.args)
  23. otstr=ot.stdout.decode('utf-8').strip()
  24. o_len=len(otstr)
  25. print(o_len)
  26. print(otstr)
  27. if o_len <=0:
  28. allids+= gid+", "
  29. print('notify') """
  30. pypath = __file__[0:__file__.replace("\\","/").rfind("/")]
  31. print(pypath)
  32. os.chdir(pypath + "/..")
  33. #os.system("cd " + pypath + "/..")
  34. #os.system("cd ..")
  35. os.system("git pull")
  36. nologlist = []
  37. mylist = [f for f in glob.glob(pypath + "/../" + str(datetime.date.today().year) +"/*.md")]
  38. #print(mylist)
  39. #print(datetime.date.today().strftime("%Y/%m/%d"))
  40. for file in mylist:
  41. f = open(file, 'r' ,encoding='utf8')
  42. if not ('## ' + datetime.date.today().strftime("%Y/%m/%d")) in f.read():
  43. #print(f.name)
  44. #print('true')
  45. #else:
  46. nologlist.append(f.name[f.name.replace('\\','/').rfind('/')+1:f.name.find('.md')])
  47. #print(f.read())
  48. f.close()
  49. if len(nologlist) > 0:
  50. #print(', '.join(nologlist))
  51. print('提醒:' + ', '.join(nologlist) + ' 今天尚未填寫工作日誌喔!')
  52. notify_group('提醒:' + ', '.join(nologlist) + ' 今天尚未填寫工作日誌喔!')
  53. notify_group('提醒:請大家記得使用104企業大師每日上下班打卡喔!')
  54. #onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
  55. #print(allids+" remember to write your work journal" )
  56. #notify_group('@yukyo test tag')
  57. #print('提醒:' + ', '.join(nologlist) + ' 今天尚未填寫工作日誌喔!')
  58. #notify_group('提醒:' + ', '.join(nologlist) + ' 今天尚未填寫工作日誌喔!')
  59. #wd=datetime.datetime.today().isoweekday()
  60. #print(mylist)