-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
64 lines (50 loc) · 1.87 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- coding: utf-8 -*-
"""
@Time : 2020/4/20 9:49
@Author : dreamhomes
@File : DailyWarning.py
@Description: 每日温暖提醒实现: @日期/农历 + @每日壹句/每日情话 + @天气预报 + @天气指数
"""
import argparse
import schedule
import time
import datetime
import itchat
import threading
from daily_sentence import *
from date import get_date
from china_weather import get_information
# 若出现二维码显示错误则令 enableCmdQR=2
itchat.auto_login(hotReload=True, enableCmdQR=True)
parser = argparse.ArgumentParser(description="*** Input parameters ***")
parser.add_argument('-s', '--sender', type=str, help='Sender')
parser.add_argument('-r', '--recipient', type=str, help='recipient')
parser.add_argument('-c', '--city', default="101240214", type=str, help='city code')
parser.add_argument('-t', '--time', default="08:00", type=str, help='reminder time')
args = parser.parse_args()
print(args.sender, args.recipient, args.city, args.time)
begin = "亲爱的 @琪琪宝贝:\n\n"
end = "\n\n来自 @"+args.sender+" 的爱,么么哒!"
location = "http://www.weather.com.cn/weather/" + args.city + ".shtml"
name = itchat.search_friends(nickName=args.recipient)[0]['UserName']
def main():
message = begin + get_date() + get_daily_love() + get_information(location) + end
print('The message sending time:', datetime.datetime.now())
print(message)
# test
# itchat.send_msg(msg=message, toUserName='filehelper')
itchat.send_msg(msg=message, toUserName=name)
def hold():
"""
hold wechat sign in.
:return:
"""
itchat.send_msg(msg="", toUserName='filehelper')
def threaded(job_func):
job_thread = threading.Thread(target=job_func)
job_thread.start()
schedule.every().hour.do(threaded, hold)
schedule.every().day.at(args.time).do(threaded, main)
while True:
schedule.run_pending()
time.sleep(1)