Created
September 17, 2019 04:39
-
-
Save rosuH/cdbd0b5752acd6efe1a6c3bd9950492b to your computer and use it in GitHub Desktop.
FoodReminder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date | |
import requests | |
import json | |
from apscheduler.schedulers.blocking import BlockingScheduler | |
from chinese_calendar import is_workday | |
# https://work.weixin.qq.com/help?doc_id=13376 | |
wk_bot_url = $YOUR_WECHAT_BOT_URL | |
def postMsg(): | |
if not is_workday(date.today()): | |
return | |
jdata = { | |
"msgtype": "news", | |
"news": { | |
"articles": [ | |
{ | |
"title": get_weekday() + " 点餐提示🔔", | |
"description": "今天是 " + str(date.today()) + ", 快戳我去点餐!", | |
"url": "https://example.com/", | |
"picurl": "https://example.com/example.jpg" | |
} | |
] | |
} | |
} | |
return requests.post(wk_bot_url, json.dumps(jdata)) | |
def get_weekday(): | |
return { | |
6: "周日", | |
0: "周一", | |
1: "周二", | |
2: "周三", | |
3: "周四", | |
4: "周五", | |
5: "周六" | |
}.get(date.today().weekday()) | |
if __name__ == "__main__": | |
scheduler = BlockingScheduler() | |
scheduler.add_job(postMsg, 'cron', hour=10) | |
scheduler.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
APScheduler==3.6.0 | |
certifi==2019.3.9 | |
chardet==3.0.4 | |
chinesecalendar==1.2.2 | |
idna==2.8 | |
pytz==2019.1 | |
requests==2.22.0 | |
six==1.12.0 | |
tzlocal==1.5.1 | |
urllib3==1.25.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment