[PYTHON] Tweet the probability of precipitation as part of the function of the bot

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

Tweet the probability of precipitation as part of the function of the bot
Is the probability of precipitation correct?
Notification of weather forecast (rain, etc.) by DM as a part of the function of bot
Defeat the probability density function of the normal distribution
Think about the analysis environment (Part 1: Overview) * As of January 2017
Understand the function of convolution using image processing as an example
Find the optimal value of a function with a genetic algorithm (Part 2)
Try transcribing the probability mass function of the binomial distribution in Python
Finding the optimum value of a function using a genetic algorithm (Part 1)
Implement part of the process in C ++
The importance of Lint as Pythonista thinks
[Python3] Rewrite the code object of the function
About the arguments of the setup function of PyCaret
Understand the "temporary" part of UNIX / Linux
[Verification] Try to align the point cloud with the optimization function of pytorch Part 1
Try installing only the core part of Ubuntu
I tried the pivot table function of pandas
[Python] Read the source code of Bottle Part 2
Example of taking Python> function> * args as arguments
Get the caller of a function in Python
[Python] Read the source code of Bottle Part 1
Fix the argument of the function used in map
Calculate the probability of outliers on a boxplot
Get only the address part of NIC (eth0)
The transition of baseball as seen from the data
[Python + OpenCV] Whiten the transparent part of the image
Various methods to numerically create the inverse function of a certain function Part 1 Polynomial regression
Note: The meaning of specifying only * (asterisk) as an argument in the Python function definition.
Add a function to tell the weather of today to slack bot (made by python)