Still saying that the test dog has no time to accompany the female ticket? Python automation teaches you to talk love words to female tickets every day

1. Steps:

  • 1. Need to obtain news, stories, weather and other related information;

  • 2. Get love messages that need to be sent along with news, stories, weather, etc.;

  • 3. Send the content to WeChat

Two, the code

Use WeChat to send regular messages to friends (news, stories, weather, etc.)

from pyquery import PyQuery

from wxpy import *

from threading import Timer

import requests

import random

2. Print out the QR code

bot = Bot()

Three, get online love words

def qinghua():

# 随机生成页数

page_random = random.randint(16, 4870)

url = "http://www.ainicr.cn/qh/+str(page_random)+.html""

header = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"}

html = requests.get(url,headers=header).text

#将获取的内容存入的列表中

nr_list = []

doc = PyQuery(html)

# 爬取网站中的文字

nr = doc(".border_30 .askbody .stbody a p ")

for item in nr.items():

# 将爬取的文字插入到列表中

nr_list.append(item.text())

# 随机获取列表中文字

return nr_list[random.randint(0,len(nr_list))]

def wendu():

#温度API

w_url = "http://t.weather.sojson.com/api/weather/city/101120201"

response = requests.get(w_url)

city = response.json()['cityInfo']['city']

data = response.json()['data']

#接口内容

time ="时间:"+str(data['forecast'][0]['ymd'])

city = "城市:"+str(city)

shidu = "湿度:"+str(data['shidu'])

pm25 = "PM2.5:"+str(data['pm25'])

pm10 = "PM10:"+str(data['pm10'])

quality ="空气质量:"+str(data['quality'])

forecast_high ="最高温度:"+str(data['forecast'][0]['high'].split()[1])

forecast_low ="最低温度:"+str(data['forecast'][0]['low'].split()[1])

ganmao ='感冒提醒(指数):'+str(data['ganmao'])

nr = city+"\n"\

+time+"\n"\

+shidu+"\n"\

+pm25+"\n"\

+pm10+"\n"\

+quality+"\n"\

+forecast_high+"\n"\

+forecast_low+"\n"\

+ganmao+"\n"+"\n"\

+qinghua()

return nr

def send_new():

try:

content = wendu()

# 获取微信名称,注:不是备注,也不是微信号

my_friend = bot.friends().search("小明")[0]

# 发送消息

my_friend.send(content)

# 定时发送,86400秒(1天),发送一次

t = Timer(86400, send_new)

t.start()

except:

# 自己的微信名称

my_friend = bot.friends().search("小兰")[0]

my_friend.send("今天发送消息失败!")

if name == "main": send_new()

Four, example


Then I will share some of my collection materials below, hoping to help you.

This information is organized around [software testing]. The main content includes: python automation test exclusive video, Python automation details, a full set of interview questions and other knowledge content . For friends of software testing, it should be the most comprehensive and complete preparation warehouse. This warehouse has accompanied me through a lot of bumpy roads, and I hope it can also help you. Pay attention to WeChat public account: Programmer Erhei, you can get it directly

At last

Learning is a long road. What we have to learn is not only the superficial technology, but also the bottom layer and understand the following principles. Only in this way can we improve our competitiveness. In today's highly competitive world Foothold.

As the saying goes: There are two best times to plant a tree, one is ten years ago, and the other is now.

A journey of a thousand miles begins with a single step, I hope you and I encourage each other. ,


Good article recommendation

High-paid programmers can't hide from the 35-year-old... When ability and age are out of touch, how do we save ourselves

After graduating from university, it began to sell... Not to be reconciled to the status quo, the road to self-help by switching to testing

Are Meituan’s test interview questions really difficult?

Recommend 52 learning websites that can be called artifacts, stick to one hour every day, so that you will benefit for a lifetime

Working overtime in a state-owned enterprise 996... What should I do when I get an offer from an outsourcing company in the interview?

Guess you like

Origin blog.csdn.net/m0_52668874/article/details/114888064