鱼C论坛

 找回密码
 立即注册
查看: 2414|回复: 0

[作品展示] 实现定时向微信中发布你的计划表,一天一次

[复制链接]
发表于 2019-2-18 16:29:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 算幽幽 于 2019-2-18 21:10 编辑

#当前目录需要crond.txt文件,写入计划表
#https://github.com/suanyouyou/crond.git

  1. import time
  2. import itchat

  3. def crond():
  4.     cronds=dict()
  5.     n = 0
  6.     with open("crond.txt", 'r', encoding='utf-8') as f:
  7.         #f.readlines是列表
  8.         for line in f.readlines():
  9.         #rstrip去掉右边非字符
  10.             linestr=line.strip()
  11.             linestr=linestr.replace('月','-')
  12.             linestr=linestr.replace('日','')
  13.             cronds[n]={'time':linestr[:11].rstrip(),'content':linestr[11:]}
  14.             n += 1
  15.     return cronds
  16. #print(crond())
  17. # print(time)

  18. #设定一天计时器
  19. daysec=24*60*60
  20. def exec():
  21.     get_time=time.strftime('%m-%d',time.localtime())
  22.     for n in range(len(crond())):
  23.         if get_time[:5]==crond()[n]['time'][:5]:
  24.             contents='时间:%s 任务:%s'%(crond()[n]['time']  ,crond()[n]['content']   )
  25.             itchat.send(contents,'filehelper')
  26.     #开始计时
  27.     time.sleep(daysec)
  28.     exec()


  29. if __name__=="__main__":
  30.     itchat.auto_login(hotReload=True)
  31.     exec()



复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-23 15:05

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表