Skip to content

Commit

Permalink
对微信推送天气的修复以及功能扩展 (tech-shrimp#1)
Browse files Browse the repository at this point in the history
* Update weather_report.py

* Delete .github/workflows/love_heart_macos.yml

* Delete .github/workflows/love_heart_ubuntu.yml

* Delete .github/workflows/love_heart_windows.yml

* Update weather_report.py

* Update weather_report.py

* Update weather_report.py

* Update weather_report.py

* Update weather_report.py

* Update weather_report.py

* Update weather_report.yml

* Update weather_report.py

* Update weather_report.py

* Update weather_report.py

* Update weather_report.py

* Update weather_report.yml

* Update weather_report.yml

* Update weather_report.py

* Update weather_report.py

* Update weather_report.yml

* Update weather_report.py

* Update weather_report.yml

* Update weather_report.yml
  • Loading branch information
yltx authored Jan 7, 2024
1 parent 238374e commit 4929140
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 74 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/love_heart_macos.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .github/workflows/love_heart_ubuntu.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .github/workflows/love_heart_windows.yml

This file was deleted.

6 changes: 4 additions & 2 deletions .github/workflows/weather_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: 天气预报推送

on:
schedule:
# 此处是UTC时间,对应北京时间早七点
# 设置启动时间,为 UTC 时间。
- cron : '00 23 * * *'
workflow_dispatch:

Expand All @@ -16,7 +16,8 @@ jobs:
build:

runs-on: ubuntu-latest

env:
TZ: Asia/Shanghai
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.12
Expand All @@ -35,3 +36,4 @@ jobs:
APP_SECRET: ${{ secrets.APP_SECRET }}
OPEN_ID: ${{ secrets.OPEN_ID }}
TEMPLATE_ID: ${{ secrets.TEMPLATE_ID }}
LOCATION_LIST: ${{ secrets.LOCATION_LIST }}
22 changes: 16 additions & 6 deletions weather_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
appID = os.environ.get("APP_ID")
appSecret = os.environ.get("APP_SECRET")
# 收信人ID即 用户列表中的微信号
openId = os.environ.get("OPEN_ID")
openId_str = os.environ.get("OPEN_ID", "")
openId_list = [id.strip() for id in openId_str.split('\n') if id.strip()]
# 读入地址列表
location_str = os.environ.get("LOCATION_LIST", "")
Location_list = [loc.strip() for loc in location_str.split('\n') if loc.strip()]

# 天气预报模板ID
weather_template_id = os.environ.get("TEMPLATE_ID")

Expand Down Expand Up @@ -78,7 +83,7 @@ def get_daily_love():
return daily_love


def send_weather(access_token, weather):
def send_weather(access_token, openId, weather):
# touser 就是 openID
# template_id 就是模板ID
# url 就是点击模板跳转的url
Expand All @@ -87,7 +92,7 @@ def send_weather(access_token, weather):
import datetime
today = datetime.date.today()
today_str = today.strftime("%Y年%m月%d日")

body = {
"touser": openId.strip(),
"template_id": weather_template_id.strip(),
Expand Down Expand Up @@ -118,16 +123,21 @@ def send_weather(access_token, weather):



def weather_report(this_city):
def weather_report(this_user, this_city):
# 1.获取access_token
access_token = get_access_token()
# 2. 获取天气
weather = get_weather(this_city)
print(f"天气信息: {weather}")
# 3. 获取用户列表
print(f"用户: {this_user}")
# 3. 发送消息
send_weather(access_token, weather)
send_weather(access_token, this_user, weather)



if __name__ == '__main__':
weather_report("淄博")
print(f"用户列表: {openId_list}")
print(f"地点列表: {Location_list}")
for _ in range(0,len(openId_list)):
weather_report(openId_list[_],Location_list[_])

0 comments on commit 4929140

Please sign in to comment.