python定制天气预报推送微信2020.11.5

2022-09-21 11:21:12 浏览数 (1)

1、找2个天气预报网址

2、采集今天、明天的最高低温度、天气

3、计算温差超过正负3度或者天气中出现雨的时候推送微信。

代码语言:javascript复制
from DrissionPage import *
import re
from time import sleep
import csv
import os
import datetime#写入时间


p = MixPage('s')
#p = MixPage()

#p.get('http://tianqi.2345.com/today-57516.htm')
p.get('http://tianqi.2345.com/today-59431.htm') #南宁

data = p.ele('@class:seven-day').eles('@class:tem')

today_low = int(data[3].text[0:2])
tomorrow_low = int(data[5].text[0:2])
today_high = int(data[3].text[3:5])
tomorrow_high = int(data[5].text[3:5])

tomorrow_High = tomorrow_high-today_high
tomorrow_Low = tomorrow_low-today_low

#print(tomorrow_High)
#print(tomorrow_Low)

p.get('http://tianqi.114la.com/101300113.html') #南宁
#p.get('http://tianqi.114la.com/101040100.html') #重庆
shangwu_cludy = p.eles('@class=sevenItemTop')
print(shangwu_cludy[2].text[9:])
sleep(1)
xiawu_cludy = p.eles('@class:sevenItemBottom')
print(xiawu_cludy[2].text[0:2])


#有雨或者气温变化超过3度才推送
if '雨' in xiawu_cludy[2].text[0:2] or '云' in shangwu_cludy[2].text[9:]:
    import requests
    token = 'xxxx' #在pushplus网站中可以找到
    title= '南宁:' str(shangwu_cludy[2].text[9:]) '~' str(xiawu_cludy[2].text[0:2])
    content = str(shangwu_cludy[2].text[9:]) '~' str(xiawu_cludy[2].text[0:2])
    url = 'http://pushplus.hxtrip.com/send?token=' token '&title=' title '&content=' content '&template=html&topic=0' #群发南宁
    requests.get(url)

if int(tomorrow_High)>=3 or int(tomorrow_High)<=-3 or int(tomorrow_Low)>=3 or int(tomorrow_Low)<=-3:
    import requests
    token = 'xxxx' #在pushplus网站中可以找到
    title= '南宁:' '高' str(tomorrow_High) '低' str(tomorrow_Low) str(shangwu_cludy[2].text[9:]) '~' str(xiawu_cludy[2].text[0:2])#改成你要的标题内容
    content = str(shangwu_cludy[2].text[9:]) '~' str(xiawu_cludy[2].text[0:2])
    url = 'http://pushplus.hxtrip.com/send?token=' token '&title=' title '&content=' content '&template=html&topic=0' #群发南宁
    requests.get(url)

24小时内有雨,微信推送

代码语言:javascript复制
from DrissionPage import *
import re
from time import sleep
import csv
import os
import datetime#写入时间

p = MixPage('s')
#p = MixPage()
p.get('https://www.weaoo.com/nanning-181523.html') 
p.response.html.encoding=p.response.encoding
data = p.ele('@class:mt1 _24hours')
#print(data.text)
if '雨' in data.text:
#    print(data.tex)
    import requests
    token = 'XXXX' #在pushplus网站中可以找到
    title= '南宁24小时内有雨'
    content = ' '
    url = 'http://pushplus.hxtrip.com/send?token=' token '&title=' title '&content=' content '&template=html&topic=0' #群发南宁
    requests.get(url)

sleep(2)
p.get('https://www.weaoo.com/chongqing-181406.html') 
p.response.html.encoding=p.response.encoding
data = p.ele('@class:mt1 _24hours')
if '雨' in data.text:
    import requests
    token = 'XXXX' #在pushplus网站中可以找到
    title= '重庆24小时内有雨'
    content = ' '
    url = 'http://pushplus.hxtrip.com/send?token=' token '&title=' title '&content=' content '&template=html&topic=0' #群发南宁
    requests.get(url)

0 人点赞