[PYTHON] Notification of weather forecast (rain, etc.) by DM as a part of the function of bot

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

Notification of weather forecast (rain, etc.) by DM as a part of the function of bot
Tweet the weather forecast with a bot Part 2
Tweet the probability of precipitation as part of the function of the bot
Add a function to tell the weather of today to slack bot (made by python)
Tweet the weather forecast with a bot
Find the optimal value of a function with a genetic algorithm (Part 2)
Finding the optimum value of a function using a genetic algorithm (Part 1)
Find the minimum value of a function by particle swarm optimization (PSO)
<Python> A quiz to batch convert file names separated by a specific character string as part of the file name
I tried to make the weather forecast on the official line by referring to the weather forecast bot of "Dialogue system made with python".
Get the caller of a function in Python
[Ruby] How to replace only a part of the string matched by the regular expression?
Get the variable name of the variable as a character string.
Make a BOT that shortens the URL of Discord
# Function that returns the character code of a string
Output the output result of sklearn.metrics.classification_report as a CSV file
A super introduction to Django by Python beginners! Part 6 I tried to implement the login function