Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Wahyiu019 committed Aug 16, 2022
0 parents commit a592121
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/main.yml
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 }}
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 每日早安推送给别人家的女朋友

> 由于此项目是在小红书开放教程的,因此不便更新代码。我会起一个闭源的仓库,用于赚钱(不是),用于真正零代码做一个早安的推送。大概预计周二晚跟大家见面,我会在小红书上更新,有需要的可以稍微等等。不过这个是要收费的,我用自己的服务器帮大家推送,10块钱应该不多吧。。
首发在小红书,但是有大家说字看不清,因此在这里搞一篇使用说明。

效果如图。当然,文字是可以修改的。
![5e72e89fd7ff692a0bfa62010517c0c](https://user-images.githubusercontent.com/9566402/183242263-c93517a2-5377-435d-8386-8d47252c9e07.jpg)

首先,按图搜索,测试号,进来之后微信扫码登录!
![cf7dbd4502df44765ed3506f55caea5](https://user-images.githubusercontent.com/9566402/183242272-134e37e7-718d-42dd-9ed7-fca2810e94e6.png)

按图点击 Use this template,创建到自己的仓库下!
![e6581c43572b00b12c1a82ca8d7178b](https://user-images.githubusercontent.com/9566402/183242340-2ef26c63-1ca1-420e-abd4-8672c25d61c9.png)


按下图,创建模板,设置变量,把微信公众平台上的各种字符串按说明创建到 GitHub -> Settings -> Secrets -> Actions 中。
![71bf9d11a876d23ef0f0728645a8ba0](https://user-images.githubusercontent.com/9566402/183242301-fd6ab30e-bfe5-4245-b2a9-f690184db307.png)
![381e8ee4a7c5ec6b8c09719f2c7e486](https://user-images.githubusercontent.com/9566402/183242295-4dcf06bb-2083-4883-8745-0af753ca805c.png)
![48c60750cec7adc546e0ad99e3082b3](https://user-images.githubusercontent.com/9566402/183242320-18500adc-14e5-4522-a3ad-ae19cc4479bf.png)

启用自己项目下的 Action!
![30a5b1b2b06ba4a40a3d8ef01652409](https://user-images.githubusercontent.com/9566402/183242334-9943c538-ba3d-4d01-8377-d040143b7560.png)

如果运行出现错误,按以下方法可以看到错误,在这里 issue 提问也可以,在小红书问也可以
![6b0da6f44e18c2bfd94910c377d13e6](https://user-images.githubusercontent.com/9566402/183242349-1aa5ada6-2ee7-4cf9-a542-4b2dad88b8fe.png)

启用后可以直接运行,看看女朋友的手机有没有收到推送吧!
这个定时任务是每天早晨8点推送,如果会编程的同学可以自己自定义一些东西~

图中的操作,除了各种英文字符串不一样,模板消息中的中文不一样,其他的应该都是一样的,不然程序跑不通的~

Github 的右上角可以点击 star 给我点鼓励吧亲

小红书上点点关注,点点赞,有什么好玩的东西可以at我,我来教你们做
53 changes: 53 additions & 0 deletions main.py
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 added requirements.txt
Binary file not shown.

0 comments on commit a592121

Please sign in to comment.