200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > python 简单爬虫获取气象数据发送气象定时报-预报预警信息及时推送及阿里云短信群发

python 简单爬虫获取气象数据发送气象定时报-预报预警信息及时推送及阿里云短信群发

时间:2020-01-19 01:55:41

相关推荐

python 简单爬虫获取气象数据发送气象定时报-预报预警信息及时推送及阿里云短信群发

!/usr/bin/python#encoding=utf-8 #Author:Ruiy##python-bs4#ilio#///import sysimport datetimenowTime="\"" + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + "\""#print nowTimeaddr="\"长沙\""if sys.getdefaultencoding() != 'utf-8':reload(sys)sys.setdefaultencoding('utf-8')#apt-get install python-bs4 for Ubuntufrom urllib import urlopenfrom bs4 import BeautifulSoupimport reurl='/weather/101250101.shtml'html=urlopen(url).read()soup=BeautifulSoup(html,'html.parser',from_encoding='utf-8')#print soup.prettify()#print soup.title#tagAfterTomorrow=soup.find('li',class_="sky skyid lv3")#print tagAfterTomorrow#weather=tagAfterTomorrow.find_next('p',class_="wea").string#print weather#temperatureHigh=tagAfterTomorrow.find_next('span').string#print temperatureHigh#temperatureLow=tagAfterTomorrow.find_next('i').string#print temperatureLow#windDirection=tagAfterTomorrow.find_next('span',class_='SE').string#print windDirection#res_data=soup.findALL('script')#print res_datares_data=soup.find('ul','t clearfix')#print res_data#print twoDays#h1s=soup.find_all('h1')#for h1 in h1s:# for li in h1.children:# print h1.stringli_tag=res_data.findAll('li')#print li_tag#print 'bug/'#for i in li_tag:# print i#print "/ruiy"#数据回值for tag in li_tag:patchTwoDays=tag.find('h1').stringif '后天' in patchTwoDays:TC=tag.find('h1').string #时间T="\"" + TC + "\""print TWC=tag.find('p','wea').string #天气W="\"" + WC + "\""print Wtry:HC=tag.find('p','tem').find('span').string #最高温H="\"" + HC + "\""print HLC=tag.find('p','tem').find('i').string #最低温度L="\"" + LC + "\""print Lexcept:#print("没有高温低温数据")passFXC=tag.find('p','win').find('i').string #风向级数FX="\"" + FXC + "\""print FX#print "patch"#print(tag.find('h1').string) #时间#print(tag.find('p','wea').string) #天气#try:# print(tag.find('p','tem').find('span').string) #最高温# print(tag.find('p','tem').find('i').string) #最低温#except:# print("没有高温低温数据")# pass#print(tag.find('p','win').find('i').string) #风向级数#print('_______________ 分割线 ____________________')#else:# print 'no patch'#Email mess interface#import smtplib#from email.mime.text import MIMEText#from email.utils import formataddr#import time#_user="5160558@"#_pwd="nphqgzgcbce"#_to="1507@"#receives=[# "5160@",# "1505567****@",# "374093@",#]#for i in receives:# msg=MIMEText("te")# msg["Subject"]="dot't p"# msg["Form"]=_user# msg["To"]=i# try:# s = smtplib.SMTP_SSL("", 465)# s.login(_user, _pwd)# s.sendmail(_user, i, msg.as_string())# s.quit()# print("Success!")# except smtplib.SMTPException,e: # print ("Falied,%s" %e) #阿里短信接口import sysfrom aliyunsdkdysmsapi.request.v0525 import SendSmsRequestfrom aliyunsdkdysmsapi.request.v0525 import QuerySendDetailsRequestfrom aliyunsdkcore.client import AcsClientimport uuidfrom aliyunsdkcore.profile import region_providerfrom aliyunsdkcore.http import method_type as MTfrom aliyunsdkcore.http import format_type as FTimport const"""短信业务调用接口"""try:reload(sys)sys.setdefaultencoding('utf8')except NameError:passexcept Exception as err:raise err# 注意:不要更改REGION = "cn-hangzhou"PRODUCT_NAME = "Dysmsapi"DOMAIN = ""acs_client = AcsClient(const.ACCESS_KEY_ID, const.ACCESS_KEY_SECRET, REGION)region_provider.add_endpoint(PRODUCT_NAME, REGION, DOMAIN)def send_sms(business_id, phone_numbers, sign_name, template_code, template_param=None):smsRequest = SendSmsRequest.SendSmsRequest()# 申请的短信模板编码,必填 smsRequest.set_TemplateCode(template_code)# 短信模板变量参数if template_param is not None:smsRequest.set_TemplateParam(template_param)# 设置业务请求流水号,必填。 smsRequest.set_OutId(business_id)# 短信签名 smsRequest.set_SignName(sign_name)# 数据提交方式# smsRequest.set_method(MT.POST)# 数据提交格式# smsRequest.set_accept_format(FT.JSON)# 短信发送的号码列表,必填。 smsRequest.set_PhoneNumbers(phone_numbers)# 调用短信发送接口,返回jsonsmsResponse = acs_client.do_action_with_exception(smsRequest)# TODO 业务处理return smsResponseif __name__ == '__main__':__business_id = uuid.uuid1()#plist=['13121172','15198367']pce=['1312272***','15055367****','15316']#print(__business_id)#params = "{\"code\":\"12345\",\"product\":\"云通信\"}"#params = {\"nowTime\":nowTime,\"addr\":\"长沙\",\"T\":\"12345\",\"W\":\"12345\",\"H\":\"12345\",\"L\":\"12345\",\"FX\":\"12345\"}"#params = {"nowTime":nowTime,"addr":addr,"T":T,"W":W,"H":H,"L":L,"FX":FX}#params = "{\"nowTime\":%s,\"addr\":\"云通信\",\"T\":\"12345\",\"W\":\"12345\",\"H\":\"12345\",\"L\":\"12345\",\"FX\":\"12345\",%nowTime}"#params="{\"nowTime\":%s,\"addr\":\"云通信\",\"T\":\"12345\",\"W\":\"12345\",\"H\":\"12345\",\"L\":\"12345\",\"FX\":\"12345\"}",%nowTimepms = """{\"nowTime\":%(nowTime01)s,\"addr\":%(addr01)s,\"T\":%(T01)s,\"W\":%(W01)s,\"H\":%(H01)s,\"L\":%(L01)s,\"FX\":%(FX01)s}"""params = pms % dict(nowTime01=nowTime,addr01=addr,T01=T,W01=W,H01=H,L01=L,FX01=FX)#print paramsop#params = "{\"nowTime\":\"12345\",\"addr\":\"云通信\",\"T\":\"12345\",\"W\":\"12345\",\"H\":\"12345\",\"L\":\"12345\",\"FX\":\"12345\"}"#print params#params = "{\"nowTime\":\"12345\",\"addr\":\"云通信\",\"T\":\"12345\",\"W\":\"12345\",\"H\":\"12345\",\"L\":\"12345\",\"FX\":\"12345\"}"for i in pce:#params = u'{"name":"wqb","code":"12345678","address":"bz","phone":"13000000000"}'print(send_sms(__business_id,i, "位温", "SMS_1297439", params))

//预警数据采集,未完..

#!/usr/bin/python#encoding=utf-8#Author:Ruiy##python-bs4#ilio#///import sysimport datetimeif sys.getdefaultencoding() != 'utf-8':reload(sys)sys.setdefaultencoding('utf-8')#apt-get install python-bs4 for Ubuntufrom urllib import urlopenfrom bs4 import BeautifulSoupimport reurl='http://www./yjs.asp'html=urlopen(url).read()soup=BeautifulSoup(html,'html.parser',from_encoding='utf-8')res_data=soup.find_all('td')print res_data

阿里短信推送测试,因为只是测试推送的数据爬取间隔很短,正常使用预报是定时报,预警的功能实现中,预警的是有预警立即推送信息!!@

邮件推送测试结果

python 简单爬虫获取气象数据发送气象定时报-预报预警信息及时推送及阿里云短信群发接口...

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。