Use the Apsara interface to provide weather forecast services.

Source: Internet
Author: User

 

 

Use the Apsara interface to provide weather forecast services.

 

Luo Weifeng 2010-7-9

The original article was published to the QQ space, and now it is transferred.

I thought that I wanted to write this one year ago, but I never wrote it when I was very busy. In the past two months, I decided to share all the things I have explored. You need to know that life is very short, and you are still very happy to dedicate some things. The following is a little stuff that crawls web pages last year and uses the fetion API. I think it is very practical, below I post all the source code

Of course it may be better to use web service to do this. Here we will only introduce this stupid method. Haha

Script: weather. py

# Coding = UTF-8 <br/> from sys import argv <br/> from urllib import urlopen <br/> from RE import S, sub, compile <br/> def format_reports (s): <br/> S = sub ("/S +", '', S) <br/> S = sub ("", ', S) <br/> S = sub ("<[^>] *>",', S) <br/> return S <br/> def weather_report (searchurl): <br/> string = ''<br/> # searchurl = 'HTTP: // www.weather.com.cn/html/weather/101110101.shtml' <br/> html = urlopen (searchurl ). read () <Br/> day1weather = compile ('<! -- Day 1 --> (.*?) <! -- Day 2 --> ', S). findall (HTML) <br/> day2weather = compile (' <! -- Day 2 --> (.*?) <! -- Day 3 --> ', S). findall (HTML) <br/> day3weather = compile (' <! -- Day 3 --> (.*?) <! -- Day 4 --> ', S). findall (HTML) <br/> day4weather = compile (' <! -- Day 4 --> (.*?) <! -- Day 5 --> ', S ). findall (HTML) <br/> for result in day1weather: <br/> string + = ''. join (format_reports (result ). split () <br/> string + = '. '<Br/> for result in day2weather: <br/> string + = ''. Join (format_reports (result). Split () <br/> string + = '. '<Br/> for result in day3weather: <br/> string + = ''. Join (format_reports (result). Split () <br/> string + = '. '<Br/> for result in day4weather: <br/> string + = ''. Join (format_reports (result). Split () <br/> string + = '. '<Br/> return string <br/> If _ name _ =' _ main _ ': <br/> xianmessage = weather_report ('HTTP: // messages) <br/> Print xianmessage + '/N' <br/> xianyangmessage = weather_report ('HTTP: // www.weather.com.cn/html/weather/101110200.shtml ') <br/> Print xianyangmessage + '/N' <br/> hangzhoumessage = weather_report ('HTTP: // www.weather.com.cn/html/weather/101210101.sht ML ') <br/> Print hangzhoumessage +'/N' <br/> weihaimessage = weather_report ('HTTP: // www.weather.com.cn/html/weather/101091301.shtml ') <br/> Print weihaimessage + '/N' <br/> url = 'HTTP: // SMS. API. bz/fetion. PHP? Username = 15098127108 & Password = ***** & sendto = % S & message = % s' <br/> urlopen (URL % ('123', 'xi'an: '+ xianmessage) <br/> urlopen (URL % ('000000', 'hangzhou:' + hangzhoumessage) <br/> urlopen (URL % ('20140901 ', 'xi'an: '+ xianmessage) <br/> urlopen (URL % ('20140901', 'xianyang:' + xianyangmessage )) <br/> urlopen (URL % ('20160301', 'weihai: '+ weihaimessage) <br/> urlopen (URL % ('20160301', 'weihai: '+ weihaimessage) <br/> Print 'sucessce! '<Br/> raw_input ()


This is all I 've explored.CodeIt's so easy, haha. You can drag the script directly to the Startup Folder (win7/Vista/XP/98.

In this way, whenever you start the system, your friends will receive the weather forecast for the current and four days, haha. This can be done by Linux buddies.

Add the File Execution path Python/home/luoweifeng/weather. py to the boot script. Of course, this script is not optimized.

If you are interested, you can compile the Regular Expression and try again. I hope you can share the improved version with me.

In addition, this is the python interpreter of 2.6. OK. If you have any questions, paste them here. The mobile phone number is your own number, and the password is your Feixin password.

Also, this can only be sent to your Feixin friends. The content can be anything. Here I crawled a webpage, matched the weather and sent it. Good luck

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.