I have created a new article for Part 2. http://qiita.com/clarinet758/items/1e084ce44c04aade1c2e
Latest information: It stopped working in my environment from around October 2014, and the contents of the following articles are not guaranteed to work now.
Hachioji, Sendai, Kumamoto, and Kyoto are selected according to friends on twitter. If you can modify JAXX and get it from yahoo! Weather, it will be in any area. http://99blues.dyndns.org/blog/2011/01/lets_get_weather_6/ The above site was very helpful in addition to getting the code to get the weather forecast. I was worried that the Chinjufu would be okay if my daughters were fighting in the rain. We are not keeping up with the addition of new server regions. I haven't checked if the truck harbor is also good. If you throw too much tweet in the same second, you are afraid of some penalty, so it is every 4 seconds when forecasting. Because it is a weather forecast. However, with this method, even after the last posting, wait 4 seconds and then finish.
yohou.py
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
import pywapi
from urllib import urlencode
from oauth2 import Client, Consumer, Token
from prettyprint import pp, pp_str
import oat
import datetime
import time
con = datetime.datetime.now()
class Today():
form = u"%The weather from the present to tonight is%The temperature is the highest in s%The lowest is about s degree%About s degree"
@classmethod
def noww(self):
yaho = pywapi.get_weather_from_yahoo
hachi, sendai = yaho('JAXX0013', 'metric'), yaho('JAXX0104', 'metric')
kuma, kyoto = yaho('JAXX0043', 'metric'), yaho('JAXX0047', 'metric')
ha, sn = hachi['forecasts'][0], sendai['forecasts'][0]
ku, ky = kuma['forecasts'][0], kyoto['forecasts'][0]
hac = Today.form % (u"Hachioji", ha['text'], ha['high'], ha['low'])
sen = Today.form % (u"Sendai", sn['text'], sn['high'], sn['low'])
kum = Today.form % (u"Kumamoto", ku['text'], ku['high'], ku['low'])
kyo = Today.form % (u"Kyoto", ky['text'], ky['high'], ky['low'])
hachi, sendai = hac.encode("utf-8"), sen.encode("utf-8")
kumamoto, kyouto = kum.encode("utf-8"), kyo.encode("utf-8")
for x in sendai, hachi, kumamoto, kyouto:
oat.client.request('https://api.twitter.com/1.1/statuses/update.json', 'POST', urlencode({'status': x}))
time.sleep(4)
@classmethod
def tinj(self):
yaho = pywapi.get_weather_from_yahoo
yoko, kure, sase, maid = yaho('JAXX0099', 'metric'), yaho('JAXX0045', 'metric'), yaho('JAXX0079', 'metric'), yaho('JAXX0047', 'metric')
oomin, chuuku = yaho('JAXX0004', 'metric'), yaho('JAXX0045', 'metric')
yo, ku = yoko['forecasts'][0], kure['forecasts'][0]
sa, ma = sase['forecasts'][0], maid['forecasts'][0]
oo, ch = oomin['forecasts'][0], chuuku['forecasts'][0]
yok = Today.form % (u"Yokosuka Naval District", yo['text'], yo['high'], yo['low'])
kur = Today.form % (u"Kure Naval District", ku['text'], ku['high'], ku['low'])
sas = Today.form % (u"Sasebo Naval District", sa['text'], sa['high'], sa['low'])
mai = Today.form % (u"Maizuru Naval District", ma['text'], ma['high'], ma['low'])
oom = Today.form % (u"Ominato Guard Office", oo['text'], oo['high'], oo['low'])
chu = Today.form % (u"Truck harbor", ch['text'], ch['high'], ch['low'])
yokosuka, kure = yok.encode("utf-8"), kur.encode("utf-8")
sasebo, maiduru = sas.encode("utf-8"), mai.encode("utf-8")
oominato, chuuk = oom.encode("utf-8"), chu.encode("utf-8")
for x in yokosuka, kure, sasebo, maiduru, oominato, chuuk:
oat.client.request('https://api.twitter.com/1.1/statuses/update.json', 'POST', urlencode({'status': x}))
time.sleep(4)
if con.minute == 46:
Today.noww()
elif con.minute == 10:
Today.tinj()
else:
pass
I forcibly created a class, but it doesn't seem to be used like this. ..
Recommended Posts