python -c" import sqlite3; db = sqlite3.connect ('rain.db'); db.text_factory = str; db.execute ('create table tweet (locate, now, tomorrow)'); db.execute (' '' insert into tweet values ('ichikawa','dummy','dummy')'''); db.commit (); db.close () "
For some reason, I created a db file that saves the contents of the weather forecast with one liner. If the forecast content is the same as the previous one while operating regularly, it seems that there is no need to send it, so recording is necessary. .. .. .. The database file name is rain.db and the table name is tweet. And it is supposed to record the location, now weather, tomorrow weather.
yohou.py
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
import pywapi
from urllib import urlencode
#oat is unique to our OAuth token storage. .. ..
import oat
import sqlite3
result = pywapi.get_weather_from_yahoo('JAXX0011','metric')
twit = u"The weather in Ichikawa from now to tonight" + result['forecasts'][0]['text'] + u"The temperature is the highest" + result['forecasts'][0]['high'] + u"The lowest is" + result['forecasts'][0]['low'] + u"About." + " #fkdr "
alert = ['Rain', 'Storm', 'Thunder', 'Thunderstorm', 'Snow']
word = result['forecasts'][0]['text']
weth = twit.encode("utf-8")
con = sqlite3.connect("rain.db")
con.text_factory=str;
log = con.cursor()
#This time we are setting the weather for today. For announcements such as rain on the way home.
log.execute(u"select now from tweet")
for row in log:
pass
#Judgment whether the weather is different from the previous time and is a warning target such as Rain
if row[0] != weth and word in alert:
dm = "D screen name?" + weth
oat.client.request('https://api.twitter.com/1.1/statuses/update.json', 'POST', urlencode({'status':dm}))
else:
pass
#It is not possible to save the contents by inputting the variable name in the place of the sql statement
#It seems that it has become.
con.execute(u"update tweet set now=?", (weth,))
con.commit()
log.close()
con.close()
Recommended Posts