Yes. Until recently, I didn't care about the probability of precipitation, but I needed it for personal reasons, so I decided to tweet it.
kousui.py
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
from urllib import urlencode
from oauth2 import Client, Consumer, Token
from prettyprint import pp, pp_str
import re
import feedparser
import oat
#oat is a self-made one to put OAuth token separately.
#tokyo
msnt = feedparser.parse("http://weather.jp.msn.com/RSS.aspx?wealocations=wc:JAXX0085&weadegreetype=C&culture=ja-JP")
#kumamoto
msnk = feedparser.parse("http://weather.jp.msn.com/RSS.aspx?wealocations=wc:JAXX0043&weadegreetype=C&culture=ja-JP")
msnt2 = msnt['entries'][0].summary
msnk2 = msnk['entries'][0].summary
tokyo = msnt2.encode("utf-8")
kumamoto = msnk2.encode("utf-8")
tori = re.compile('rainy percent:\s\d*%')
twi1 = "Today's Tokyo" + tori.findall(tokyo)[0] + "So tomorrow" + tori.findall(tokyo)[1] + "About. Today's Kumamoto" + tori.findall(kumamoto)[0] + "So tomorrow" + tori.findall(kumamoto)[1] + "About. Information provided by Foreca"
oat.client.request('https://api.twitter.com/1.1/statuses/update.json', 'POST', urlencode({'status': twi1}))
Yes. Click here to get the probability of precipitation this time. http://weather.jp.msn.com/RSS.aspx?wealocations=wc:JAXX0043&weadegreetype=C&culture=ja-JP The JAXX code will change depending on the region you want to acquire. I installed feedparser easily with pip, but when I googled how to use it, it seems that there were quite a few people who compiled it by themselves, but the difference is unknown. (When I checked the version, it was Python 2.7.3 feedparser 5.1.3.) Only the part of the probability of precipitation is not conveniently included in the enclosure, so it is forcibly taken out.
Fixed to fail if it is overseas information 2013/09/12
Overseas correspondence.py
sozai = feedparser.parse("http://weather.jp.msn.com/RSS.aspx?wealocations=wc:%s" % self.code)
prob = sozai['entries'][1].summary
regx = re.compile(u':\s\d*%')
# data = (regx.findall(prob)[0], regx.findall(prob)[1])
#okk kousui_t = u"Today's%s is%s tomorrow%About s." % (self.name, regx.findall(prob)[0], regx.findall(prob)[1])
kousui_t = u"Precipitation probability today%Precipitation probability tomorrow with s%About s." % (regx.findall(prob)[0], regx.findall(prob)[1])
Before the correction, the information is limited to Japanese, and it will fail if there is no Japanese in overseas areas, so acquire it in English even in Japan and supplement Japanese when writing for posting.
Recommended Posts