Yes. Past articles http://qiita.com/clarinet758/items/0142e88cd19a4246f308
http://weather.service.msn.com/data.aspx?src=vista&weadegreetype=C&culture=ja-JP&wealocations=wc:
Unfortunately the update seems to have not updated the data since mid-November 2016.
Somehow it causes the third, so the update will make the tea muddy. The new acquisition destination is OpenWeatherMap. I still used Python 2 series. It's spicy.
Reference
http://qiita.com/b-wind/items/06e19043a0cd70b10b03
http://qiita.com/nownabe/items/aeac1ce0977be963a740
http://qiita.com/sudnonk12/items/744fb48e378c05979952
If you read the above, I don't think you need to read anything in the future.
If you want a little information for Twitter, do you use one of the two? When,
Sample code
weather
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import datetime
import oat
import time
import urllib2
import json
class Weather3:
def __init__(self, api_key, hour, name, code, tag):
self.api_key = api_key
self.day = [u'today', u'tomorrow'][hour == **].encode('utf-8')
self.name = name.encode('utf-8')
self.code = code
self.indx = [-1]*25
self.indx[*] = *
self.f = self.indx[hour]
self.tag = tag
def get_json(self):
url = 'http://api.openweathermap.org/data/2.5/forecast?id={0:}&APPID={1:}'.format(self.code, self.api_key)
o = urllib2.urlopen(url)
r = o.read()
j = json.loads(r)
return j
def get_info(self):
ind = self.f
data = self.get_json()
base = data['list'][ind]
tenki = base['weather'][0]['main']
t_max = str('{0:.2f}'.format(base['main']['temp_max']-273.15))
t_min = str('{0:.2f}'.format(base['main']['temp_min']-273.15))
return (tenki, t_max, t_min)
def make_txt(self):
d = self.get_info()
temp = "{0:}of{1:}ら辺of天候は{2:}is. The maximum temperature is{3:}At around degrees, the lowest temperature is{4:}About degree.#{5:}"
text = temp.format(self.day, self.name, d[0], d[1], d[2], self.tag)
return text
def tweet(self):
message = self.make_txt()
# print message
oat.tweet(message)
def run(self):
self.tweet()
time.sleep(5)
if __name__ == '__main__':
target = [[u'Shinagawa', 1852140], [u'Funabashi', '1863905'], [u'Kumamoto', '1858421'], [u'Uji', '1849372']]
jikan = datetime.datetime.now()
flag = jikan.hour
tag = jikan.microsecond
for i in target:
w = Weather3(oat.api_key, flag, i[0], i[1], tag)
w.run()
token
#!/usr/bin/python
# -*- coding:UTF-8 -*-
from urllib import urlencode
from oauth2 import Client, Consumer, Token
import tweepy
#Twitter
consumer_key = "xxxxxx"
consumer_secret = "xxxxxxxxxxx"
user_key = "*****-xxxxxxxxxx"
user_secret = "xxxxxxxxx"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(user_key, user_secret)
client = Client(Consumer(consumer_key, consumer_secret), Token(user_key, user_secret))
api = tweepy.API(auth)
ep = "https://api.twitter.com/1.1/statuses/update.json"
#OpenWeatherMap
api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
def tweet(message):
client.request(ep, 'POST', urlencode({'status': message}))
def reply(message, ids):
client.request(ep, 'POST', urlencode({'status': message, 'in_reply_to_status_id': ids}))
Depending on the time you move, the weather tomorrow today and the number of information you use in the acquired information will vary depending on how you use it. In addition, I wrote -273.15 to convert the temperature from Kelvin to Celsius, but it seems that it will be returned in Celsius if you turn on the option when you hit the endpoint. Twitter post sample image
Recommended Posts