diff --git a/main.py b/main.py index 98e12745..db86a94b 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -from datetime import date, datetime +from datetime import date, datetime, timedelta import math from wechatpy import WeChatClient from wechatpy.client.api import WeChatMessage, WeChatTemplate @@ -6,7 +6,7 @@ import os import random -today = datetime.now() +today = datetime.now() + timedelta(hours=8) start_date = os.environ['START_DATE'] city = os.environ['CITY'] birthday = os.environ['BIRTHDAY'] @@ -14,7 +14,7 @@ app_id = os.environ["APP_ID"] app_secret = os.environ["APP_SECRET"] -user_id = os.environ["USER_ID"] +user_ids = os.environ["USER_ID"].split("\n") template_id = os.environ["TEMPLATE_ID"] @@ -22,7 +22,7 @@ def get_weather(): url = "http://autodev.openspeech.cn/csp/api/v2.1/weather?openId=aiuicus&clientType=android&sign=android&city=" + city res = requests.get(url).json() weather = res['data']['list'][0] - return weather['weather'], math.floor(weather['temp']) + return weather['weather'], math.floor(weather['temp']), math.floor(weather['high']), math.floor(weather['low']) def get_count(): delta = today - datetime.strptime(start_date, "%Y-%m-%d") @@ -47,7 +47,11 @@ def get_random_color(): client = WeChatClient(app_id, app_secret) wm = WeChatMessage(client) -wea, temperature = get_weather() -data = {"weather":{"value":wea},"temperature":{"value":temperature},"love_days":{"value":get_count()},"birthday_left":{"value":get_birthday()},"words":{"value":get_words(), "color":get_random_color()}} -res = wm.send_template(user_id, template_id, data) -print(res) +wea, temperature, highest, lowest = get_weather() +data = {"date":{"value":today.strftime('%Y年%m月%d日'),"color":get_random_color()},"weather":{"value":wea,"color":get_random_color()},"temperature":{"value":temperature,"color":get_random_color()},"love_days":{"value":get_count(),"color":get_random_color()},"birthday_left":{"value":get_birthday(),"color":get_random_color()},"words":{"value":get_words(),"color":get_random_color()},"highest": {"value":highest,"color":get_random_color()},"lowest":{"value":lowest, "color":get_random_color()}} +count = 0 +for user_id in user_ids: + res = wm.send_template(user_id, template_id, data) + count+=1 + +print("发送了" + str(count) + "条消息")