Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bintong zhao patch 1 #1

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions .github/workflows/send_love.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
name: CI
on:
schedule:
- cron: "5 0 * * *"
# 每天早上7:40运行
- cron: "40 7 * * *"
# 每天下午5:00运行
- cron: "0 17 * * *"
push:
branches: [ "main" ]
jobs:
build:
send-morning-message:
runs-on: ubuntu-latest
steps:
steps:
- name: Checkout repository
- uses: actions/checkout@v3

- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: send msg

- name: Run morning message script
run: |
python send_love_msg.py
python send_morning_message.py
send-evening-message:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Run evening message script
run: |
python send_evening_message.py
17 changes: 0 additions & 17 deletions config.dev.yaml

This file was deleted.

17 changes: 17 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
wxPusher:
appToken: "AT_penx9gyzxwP6g7dwd4lb6LoWHskuGPiE" # wxPusher的appToken
topicIds:
- 34432 # wxPusher的topicIds,支持多个ID

wechatWork:
webhookKey: "xxxxxx" # 企业微信的webhook key

weather:
apiKey: "fd14b9ca913160e65eb47b1edba5d48c" # 高德天气接口的key
city: 610118 # https://a.amap.com/lbs/static/code_resource/AMap_adcode_citycode.zip

lover:
expressLoveTimestamp: 1594378800
monthOfBirthday: 8
dayOfBirthday: 19
meetingTimestamp: 1504233600
71 changes: 71 additions & 0 deletions send_evening_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import json
from datetime import datetime, timedelta
import pytz
import requests
from config import loadConfig

# Load configuration
config = loadConfig("config.yaml")
qywxWebhookKey = config.weChatWork.webhookKey
wxpushAppToken = config.wxPusher.appToken
wxpushTopicIds = config.wxPusher.topicIds

def getDaysUntil(date_str):
target_date = datetime.strptime(date_str, "%Y-%m-%d")
tz = pytz.timezone("Asia/Shanghai")
now = datetime.now(tz)
return (target_date - now).days

def sendAlarmMsg(mdTex):
wechatwork(mdTex)

def wechatwork(tex):
webhook = f"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={qywxWebhookKey}"
header = {"Content-Type": "application/json", "Charset": "UTF-8"}
message = {"msgtype": "markdown", "markdown": {"content": tex}}
message_json = json.dumps(message)
try:
requests.post(url=webhook, data=message_json, headers=header)
except requests.exceptions.RequestException as e:
print("unable to connect to wechat server, err:", e)
except Exception as e2:
print("send message to wechat server, err:", e2)
sendAlarmMsg(str(e2))

def wxPusher(tex):
url = "http://wxpusher.zjiecode.com/api/send/message"
header = {"Content-Type": "application/json", "Charset": "UTF-8"}
message = {
"appToken": wxpushAppToken,
"content": tex,
"summary": "按时吃药提醒",
"contentType": 2,
"topicIds": wxpushTopicIds,
"url": "http://wxpusher.zjiecode.com",
}
message_json = json.dumps(message)
try:
info = requests.post(url=url, data=message_json, headers=header)
print(info.text)
except requests.exceptions.RequestException as e:
print("unable to connect to wx, err:", e)
sendAlarmMsg(str(e))
except Exception as e:
print("send message to wx, err:", e)
sendAlarmMsg(str(e))

if __name__ == "__main__":
days_until_end = getDaysUntil("2024-10-27")

# 新增的提醒内容
medication_reminder = (
'宝宝快要下班了呢,记得按时吃药哦:'
'饭前半小时:雷贝拉唑 * 1,枸酸秘钾 * 2;'
'饭后半小时:阿莫西林 * 4,克拉霉素 * 2。'
)

# 发送提醒内容到企业微信
wechatwork(medication_reminder)

# 发送提醒内容到WxPusher
wxPusher(medication_reminder)
Loading