Github Actions + Tencent Cloud function realizes WeChat push weather, class schedule, class reminder, good night message every day

Foreword:

Recently, I found out that dy is a very popular small project, and I just wanted to learn about WeChat official account push. Based on other people's projects (only the weather is pushed, the original author forgot to apologize!), I added some of my own needs: 1. When the weather is pushed every day, the course of the day will be pushed by the way; 2. If there is a class in the next class, before the class Push reminder; 3. Daily good night heartfelt words and course push for the next day.

Implementation principle:

At the beginning, there was only daily weather push (it only needs to be pushed once a day at regular intervals). The implementation is very simple, just use GitHub Actions to create a scheduled workflow.
After the increase in demand, the original idea remained unchanged. Use GitHub Actions to create a workflow multi-run project, so that the program will continue to execute until the "Good Night Words" is pushed and it will end. But there are two fatal limitations of GitHub Actions : 1. The total time that the project can be executed in a month is usually 2000 minutes, and the program will run out of time soon if it continues to execute! 2. If you set the daily push time to be 7:40, since GitHub Actions is queued for execution, if it is a peak period, the project will be delayed in execution (generally delayed by 20-40 minutes), so the second point directly negates what we want Punctual needs.
It is worth noting that if we manually trigger the workflow in GitHub Actions, it will be executed in real time (the deployment time of this project is generally about 50s). Therefore, the problem changes, by using the timing function of Tencent Cloud Function to trigger the workflow file in GitHub Actions, to achieve the curve to save the country!
Using the timing trigger function of Tencent Cloud function, you only need to trigger the workflow file in Actions two minutes before the daily reminder of the program setting, the reminder of each class, and the daily good night reminder time to perfectly solve the time limit of GitHub Actions . and timing delays.

1. Preparatory conditions:

1. GitHub account, registration address (https://github.com/)

2. WeChat public platform account, registration address (https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login)

3. Tencent Cloud Function account, registration address (https://cloud.tencent.com/)

4. Tianxing data account (used to obtain the content of good night heart words), registration address (https://www.tianapi.com/)

Second, the realization of the effect diagram

1. Daily reminder

daily reminder

2. Class reminder

class reminder

3. Good night heartfelt words and lesson reminders for the next day

Good night words

3. Steps

1. Pull the GitHub project

Fork the project in the warehouse to the
GitHub project address of your own warehouse: https://github.com/ghwmx/WeiXinPost

2. Change the configuration file in the project: config.py

change configuration file
insert image description here

3. Related configuration of the WeChat public platform, log in to the WeChat public platform, and register the interface testing official account for free

Copy the appID and appsecret to fill in the corresponding location of config.py

insert image description here

②Copy appID and appsecret

insert image description here

③Fill in the corresponding position of config.py

insert image description here
Pay attention to fill in the double quotes

④Copy the template at the bottom of the config.py file and add it to the WeChat public platform respectively

Explanation: The text other than { {***}} in the template is fixedly displayed, as shown in the 90th line of code, "Today is the day of the broken shell: { { ...}} day", this sentence corresponds to a timer device, can be changed to: today is and. . . The { {…}} day of love , today is. . . . Wait, change according to your needs.
In the same way, "There are still: { {...}} days before school starts" is a countdown, which can be changed to birthdays, etc. Birthdays only support the Gregorian calendar for the time being, and the main program can be changed according to your needs for the lunar calendar.
When copying, remember to remove the "#" in front of each line . You can copy it to the txt file first and then add it after sorting it out.
insert image description here

Copy template 1 and add:

On the WeChat public platform, find the "template message interface" ----> add a new test template ----> template title (that is, the title seen on WeChat) ----> the content of the template is the content just copied ----->Submit
insert image description here

insert image description here
insert image description here
insert image description here

⑤ Copy the template ID and fill it in template_id1 of config.py

⑥The following class reminder template is the same as the good night heart words template

insert image description here

⑦Scan and test the QR code, follow the official account, copy the WeChat ID after following, and fill in the user in config.py

Note: You need to fill in double quotes
insert image description here
insert image description here

⑧Save the modification

insert image description here

So far, the WeChat public platform configuration is complete!

4. Configure GitHub Actions

①Open the actions workflow file template.yml, and copy all the content inside

insert image description here
insert image description here

②Click Actions to configure the workflow file

insert image description here
Select set up a workflow yourself
insert image description here
to delete all content, and paste the copied content into it, save and
insert image description here
insert image description here
click Actions, the newly created workflow file will appear to
insert image description here
test whether the workflow is correct
insert image description here
insert image description here
*If the operation fails, click to view the generated during operation Error
insert image description here
* The reason for the positioning problem is that the environment configuration is not correct, or the problem of the program itself. The following problem is the function on line 79 of the program main.py: get_Today_Class An error occurred while running. Reason: No school start time configured
insert image description here

③ Obtain GitHub Token to prepare for the subsequent Tencent Cloud function configuration

Click on personal settings
insert image description here

Scroll to the bottom and select 'Developer Settings'
insert image description here

insert image description here

insert image description here

insert image description here

insert image description here

insert image description here
At this point, the github configuration is complete!

5. Configure Tencent Cloud functions

①Search for 'cloud function' after login

insert image description here

insert image description here

Next there will be some authentication
insert image description here

②After completing relevant authentication, select 'Function Service', 'New'

insert image description here

Select 'from scratch', the name of the function is arbitrary, and the operating environment selects 'Python3.6'
insert image description here

Next change the content in the function body, open 'txPost.py' in GitHub and copy all the content
insert image description here

insert image description here

Paste it into the window and replace the token, user name and other information in it
insert image description here

User name/project name as shown in the picture
insert image description here

The rest are set to default
insert image description here

insert image description here

③Create a timing trigger that triggers the function, just operate as shown in the figureinsert image description here

insert image description here

insert image description here

insert image description here

insert image description here

insert image description here

Congratulations, you have successfully completed all configurations!

conclusion

This article has been written for a long time due to my own reasons, and it is not a hot topic until now hahahaha. During the summer vacation of 2022, I was tossing the server at home, and I happened to see the weather being sent to my girlfriend on a certain music, ahhhhhh, thinking that although I don’t have a girlfriend, can I change it from other people’s projects and write something about myself? According to the demand, learn how to push, eh! Wouldn't it be nice to hang it on your own small NAS. When I tried to hang the written program on the NAS, I found that the performance of the small NAS was too weak!

ps: The small NAS is a NAS that I fiddled with a set-top box for watching TV. The chip is Huawei's hi3798 and the Ubuntu system. I also learned to learn docker, installed openwrt, and later used it as a bypass to see the outside world. Attached is the picture of the small NAS, hahahaha and a little sense of accomplishment. If there are friends who are interested in the follow-up, if you have time, you can make a tutorial on flashing the set-top box haha.
But then I tossed a Synology NAS, j1900 processor. Cooperating with the public network ip can satisfy my too many weird ideas.
insert image description here
insert image description here

Because my good friend needs to complete the relevant Python experimental project, so I am familiar with it again, so let's take this opportunity to complete it. The tutorial should be more detailed, I try to take screenshots every step of the way. Hope to be of some help to you! grateful!

Guess you like

Origin blog.csdn.net/qq_29711355/article/details/126808897