-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d412372
Showing
4 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: morning | ||
on: | ||
schedule: | ||
- cron: '0 0 * * *' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
send_message: | ||
runs-on: ubuntu-latest | ||
name: send morning to your girlfriend | ||
|
||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: master | ||
|
||
- name: sender | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
architecture: 'x64' | ||
- run: pip install -r ./requirements.txt && python ./main.py | ||
|
||
env: | ||
APP_ID: ${{ secrets.APP_ID }} | ||
APP_SECRET: ${{ secrets.APP_SECRET }} | ||
TEMPLATE_ID: ${{ secrets.TEMPLATE_ID }} | ||
USER_ID: ${{ secrets.USER_ID }} | ||
START_DATE: ${{ secrets.START_DATE }} | ||
BIRTHDAY: ${{ secrets.BIRTHDAY }} | ||
CITY: ${{ secrets.CITY }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# 每日早安推送给别人家的女朋友 | ||
|
||
首发在小红书,但是有大家说字看不清,因此在这里搞一篇使用说明。 | ||
|
||
> 我一脸懵逼地在小红书新建的群里听说有网友在抖音帮推我这个项目.. | ||
> | ||
> 在此表示十分感谢,因为我懒得做视频。。当时也是一时兴起,所以就只发了小红书。。 | ||
> | ||
> 大家喜欢我的项目我真的十分感谢,不过有朋友说找不到我本人。对于涨粉丝这件事情我还是很感兴趣的。。 | ||
*我的小红书昵称==抖音昵称==微博账号==一切社交平台==“纠结当道”* | ||
|
||
并且都是柯南的头像 | ||
|
||
 | ||
 | ||
|
||
---------------------- 以下是正文 ---------------------- | ||
|
||
在我刚想构思这个教程怎么让不懂编程的朋友很快入门的时候,我考虑到:避免服务器搭建,避免定时任务,避免接触代码。在经历过各种思考后,觉得可以用 Github Actions 来白嫖。。 | ||
|
||
效果如图。当然,文字是可以修改的。 | ||
 | ||
|
||
首先,按图搜索,测试号,进来之后微信扫码登录! | ||
 | ||
|
||
按图点击 Use this template,创建到自己的仓库下! | ||
 | ||
|
||
按下图,创建模板,设置变量,把微信公众平台上的各种字符串按说明创建到 GitHub -> Settings -> Secrets -> Actions 中。 | ||
 | ||
 | ||
 | ||
|
||
启用自己项目下的 Action! | ||
 | ||
|
||
如果运行出现错误,按以下方法可以看到错误,在这里 issue 提问也可以,在小红书群里问也可以 | ||
 | ||
|
||
启用后可以直接运行,看看女朋友的手机有没有收到推送吧! | ||
这个定时任务是每天早晨8点推送,如果会编程的同学可以自己自定义一些东西~ | ||
|
||
图中的操作,除了各种英文字符串不一样,模板消息中的中文不一样,其他的应该都是一样的,不然程序跑不通的~ | ||
|
||
Github 的右上角可以点击 star 给我点鼓励吧亲 | ||
|
||
小红书上点点关注,点点赞,有什么好玩的东西可以at我,我来教你们做 | ||
|
||
ps. 有一些注意事项在此补充 | ||
|
||
1. 第一次登录微信公众平台测试号给的 app secret 是错误的,刷新一下页面即可 | ||
2. 生日的日期格式是:`05-20`,纪念日的格式是 `2022-08-09`,请注意区分。城市请写到地级市,比如:`北京`,`广州`,`承德` | ||
3. 变量中粘贴的各种英文字符串不要有空格,不要有换行,除了模板之外都没有换行 | ||
4. Github Actions 的定时任务,在 workflow 的定义是 `0 0 * * *`,是 UTC 时间的零点,北京时间的八点。但是由于 Github 同一时间任务太多,因此会有延迟 | ||
5. 我会偶尔优化一下代码,emm 但现在我自己在做一个完整的平台项目,想让大家更加便捷地上手 | ||
|
||
但那个平台还没完全做好,我要抑制住我赚钱(不是)的欲望。。 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from datetime import date, datetime | ||
import math | ||
from wechatpy import WeChatClient | ||
from wechatpy.client.api import WeChatMessage, WeChatTemplate | ||
import requests | ||
import os | ||
import random | ||
|
||
today = datetime.now() | ||
start_date = os.environ['START_DATE'] | ||
city = os.environ['CITY'] | ||
birthday = os.environ['BIRTHDAY'] | ||
|
||
app_id = os.environ["APP_ID"] | ||
app_secret = os.environ["APP_SECRET"] | ||
|
||
user_id = os.environ["USER_ID"] | ||
template_id = os.environ["TEMPLATE_ID"] | ||
|
||
|
||
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']) | ||
|
||
def get_count(): | ||
delta = today - datetime.strptime(start_date, "%Y-%m-%d") | ||
return delta.days | ||
|
||
def get_birthday(): | ||
next = datetime.strptime(str(date.today().year) + "-" + birthday, "%Y-%m-%d") | ||
if next < datetime.now(): | ||
next = next.replace(year=next.year + 1) | ||
return (next - today).days | ||
|
||
def get_words(): | ||
words = requests.get("https://api.shadiao.pro/chp") | ||
if words.status_code != 200: | ||
return get_words() | ||
return words.json()['data']['text'] | ||
|
||
def get_random_color(): | ||
return "#%06x" % random.randint(0, 0xFFFFFF) | ||
|
||
|
||
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) |
Binary file not shown.