Tweet the weather forecast with a bot

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

Tweet the weather forecast with a bot
Tweet the weather forecast with a bot Part 2
I made a weather forecast bot-like with Python.
View today's weather forecast with a shell script
Create a tweet heatmap with the Google Maps API
Scraping weather forecast with python
Notification of weather forecast (rain, etc.) by DM as a part of the function of bot
Create a Twitter BOT with the GoogleAppEngine SDK for Python
[Python] I asked LINE BOT to answer the weather forecast.
The story of making a question box bot with discord.py
Get the weather with Python requests
Get the weather with Python requests 2
I liked the tweet with python. ..
I want to know the weather with LINE bot feat.Heroku + Python
Search the maze with the python A * algorithm
Let's make a Twitter Bot with Python!
The story of making a university 100 yen breakfast LINE bot with Python
A model that identifies the guitar with fast.ai
I made a stamp substitute bot with line
Tweet regularly with the Go language Twitter API
[Python] Get the files in a folder with Python
Make a Twitter trend bot with heroku + Python
Find a position above the threshold with NumPy
Create a LINE BOT with Minette for Python
Follow the AR marker with a 2-axis servo
I made a LINE Bot with Serverless Framework!
Steps to create a Twitter bot with python
Save the object to a file with pickle
Make a LINE WORKS bot with Amazon Lex
Let's do web scraping with Python (weather forecast)
Create a translation tool with the Translate Toolkit
I made a Mattermost bot with Python (+ Flask)
I tried to make the weather forecast on the official line by referring to the weather forecast bot of "Dialogue system made with python".
Add a function to tell the weather of today to slack bot (made by python)
Draw a graph with PyQtGraph Part 5-Increase the Y-axis
[AWS] I made a reminder BOT with LINE WORKS
I made a Twitter BOT with GAE (python) (with a reference)
I made a household account book bot with LINE Bot
Make a morphological analysis bot loosely with LINE + Flask
How to create a submenu with the [Blender] plugin
Make a BOT that shortens the URL of Discord
Take a screenshot of the LCD with Python-LEGO Mindstorms
Create a Todo app with the Django REST framework
Generate a random sentence from your tweet with trigram
Crawl the URL contained in the twitter tweet with python
Make a breakpoint on the c layer with python
A story that struggled with the common set HTTP_PROXY = ~
Fill the background with a single color with OpenCV2 + Python
I made a LINE BOT with Python and Heroku
Visualize the characteristic vocabulary of a document with D3.js
Tweet the triple forecast of the boat race on Twitter
Tweet the probability of precipitation as part of the function of the bot
A memo that I touched the Datastore with python
Transit to the update screen with the Django a tag
[Super easy] Let's make a LINE BOT with Python.
Calculate the product of matrices with a character expression?
Display the weather forecast on M5Stack + Google Cloud Platform
Create a bot that only returns the result of morphological analysis with MeCab on Discord
A4 size with python-pptx
Kyotei forecast with TensorFlow
Decorate with a decorator