preface

Before had sent an article, made of Python to the weather forecast warned parents the weather turned cold, small tools for parents to produce a weather remind little helper, after I synchronization to blog, this article has the reader comments in the comments section, for some WeChat no web interface, lead to cannot achieve this function, the readers advice, It is suggested to send text messages, so that they will not be limited by wechat.

This is a good way, today’s tutorial is to teach you how to send a free text message to your girlfriend.

There are two common SMS sending interfaces that I know. One is Twilio, which can send 500 free SMS messages and any information, and the other is Tencent Cloud, which can send 100 free SMS messages. We need to apply for the content template of SMS sending.

Since There are more free times on Twilio, we will send the weather information to our parents on Twilio this time.

Twilio registered

To send text messages, we need to set up an account on twilio’s website.

https://www.twilio.com/Copy the code

Click Sign Up to Sign Up for an account.

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

To fill in the mailbox to verify, need to fill in the machine number verification.

At the beginning, I used the mobile number to send the verification code twice, but I didn’t receive the verification code. I don’t know why, but I received the verification code after changing the telecom.

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

After selecting Yes, we chose Python.

Get trial number

After selecting the purpose, you can obtain a Trial Number. Click “Get a Trial Number”.

We can see the number that the system gave me.

Clicking OK will bring up a successful page with the number Provided by Twilio for sending text messages.

After successfully obtaining the number, you are automatically returned to the home page. Below is an example of Python calling the SMS interface.

After going into the interface call instructions, we see an example on the right of calling the interface directly from Python to send a message.

Let’s just go ahead and replace the accountSID and AuthToken values in the code with our own, which are on the page where the number was displayed.

Replace the body in message with your own text, and replace the number from which the message was sent with the number just provided.

Verification of receiving number

Before using the receiving number, you need to verify it on Twilio and click verified Numbers on the right to add the number.

Since this is a free version, only one number is supported. If there is a verification number before, we need to click the X on the right to delete the number before adding a new number.

After clicking the verification number button, select text you instead at the bottom left of the popup page, which is to verify the newly added number with SMS verification code and send it to your girlfriend. Of course, the number you receive is filled in by your girlfriend.

After entering the number, click Verify and wait for the verification code.

I respectively tried the mobile number, Unicom number, electrical signal, electrical signal and unicom card can normally receive verification code through verification, mobile number sent several times are not received verification code, the card is a balance, may be mobile card does not support this interface, we can try.

Code debugging

Before running the code, don’t forget to install the Twilio library with the PIP command.

pip install twilioCopy the code

Then replace a few values in the code with your own.

Add the number of successful verification just now to the code, run the code, after success will receive the message sent.

And then we text out the previous weather information, but of course you can send other information. I’m going to use the weather information from before.

The previous code to remove the wechat related, the weather interface part is retained.

The weather is getting cold. Make a weather alert for your parents.

Replace the message sent just now with the MSG message returned by the weather interface, and the code of timing operation is the same as before.

Running the code looks like this:

Again, I put the program on the server, and the next day at the same time I will continue to send the weather information for that day. I set the interval to 24 hours, but of course you can change the interval.

If you don’t have a server, you can take a look at the price of Tencent Cloud’s “Double 11” activity, which is 88 yuan a year. It is very cost-effective to put small tools and make personal websites at ordinary times. The purchase address: Tencent Cloud 1 core 2G, 88 yuan a year

All the code for this article can be obtained by replying to “text message” in the background of the public account “Python Knowledge circle”.

Welcome to follow the public account “Python knowledge circle”, the public account background reply keyword, get more dry goods.

Answer “English” : send you English 7000 words shorthand, pro test is very effective.

Reply to “programming” : receive the latest programming materials of 2019 for free, and get a soft hand after carefully studying BAT offer.

Reply to “Make money” : Get 36 simple and practical projects to make money and earn 100 extra pocket money every day.

Reply to “ebooks” : free 10 Python ebooks.