程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Teach you how to use Python to automatically send free text messages to your girlfriend every day

編輯:Python

Today's tutorial is to teach you how to send free text messages to your girlfriend .

Send SMS interface , There are two common platforms I know , One is twilio, Free SMS 500 strip , Can send any information , One is Tencent cloud , Free SMS 100 strip , Need to apply for SMS content template .

Whereas twilio More free times , therefore , This time, we will twilio To send the weather information of the day to my parents .

twilio register

To send a text message , We need now twilio Register an account on the official website .

https://www.twilio.com/

Click on Sign Up Create an account .

Fill in email, password and other information , After submission, there will be a verification to determine whether it is a robot , Click the left and right arrows to display the pattern as a positive picture .

Then go to the email just filled in to verify , Need to fill in mobile number verification .

Just started to use the mobile number to send two times without receiving the verification code , I don't know why , After changing the telecommunication, we received the verification code .

After successful verification, you will be prompted to choose whether to call through code .

choice yes Then select the corresponding language , Of course, we choose Python 了 .

Get trial number

After use , You can get a trial number , Click on Get a Trial Number Button .

We can see the number that the system gave me .

Click OK and a successful page will appear , Show Twilio Number provided , This number is used to send text messages .

Automatically jump back to the home page after obtaining the number successfully , There is Python Example of calling SMS interface .

After entering the interface call description , We see that on the right, directly from Python Example of calling interface to send SMS .

We can use it directly , In the code accountsid and authtoken Replace with your own , The two values are shown on the page where the number is just shown .

And then message Medium body Change to your own text , Change the number of the message sent to the number just provided by the official .

Receive number verification

Receiving number before use , Need to be in Twilio Up and down , Click on the right verified numbers Get into , Add number .

Because it's free , So only one number is supported , If you have a verification number before , We need to click on the right X Delete this number to add a new number .

After clicking the button of verification number , On the pop-up page, select the text you instead, That is to use SMS verification code to verify the newly added number , You want to send it to your girlfriend , Of course , The receiving numbers are all for my girlfriend .

After filling in the number , Click verify , Wait for the verification code .

I tried the mobile numbers 、 Unicom No 、 Electrical signals , It is found that the electric signal and the Unicom card can receive the verification code normally and pass the verification , The mobile number has been sent several times and can't receive the verification code , The card has a balance , Maybe the mobile card does not support this interface , You can try .

Code debugging

Before running code , Don't forget to twilio Library use pip Command installation .

pip install twilio

Then replace several values in the code with your own .

Add the successful number to the code , Run code , The message will be sent after success .

Then we send out the weather information by SMS , Of course, you can send other messages . Here I use the previous weather information .

In the previous code, wechat is removed , Weather interface part reserved .

Put them in key Change to your own , Replace the message sent just now with the information returned by the weather interface msg, The timing operation code is the same as before .

The effect of running the code is as follows :

Again , I still put the program on the server , The next day at the same time will continue to send the weather information of the day , I set the gap 24 Hours , Of course , You can change the time between .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved