Last active
July 1, 2021 00:03
-
-
Save jeffehobbs/ee1ccb01a80cf9834143 to your computer and use it in GitHub Desktop.
Simple Python Twitter Weather Bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import tweepy, time, sys, urllib, json | |
# enter the corresponding information from your Twitter application/Forecast.io API KEY/lat and long: | |
CONSUMER_KEY = 'YOUR_CONSUMER_KEY' | |
CONSUMER_SECRET = 'YOUR_CONSUMER_SECRET' | |
ACCESS_KEY = 'YOUR_ACCESS_KEY' | |
ACCESS_SECRET = 'YOUR_ACCESS_SECRET' | |
FORECAST_IO_APIKEY ='YOUR_FORECAST_IO_APIKEY' | |
LATITUDE = 'YOUR_LATITUDE_VALUE' | |
LONGITUDE = 'YOUR_LONGITUDE_VALUE' | |
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) | |
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET) | |
api = tweepy.API(auth) | |
url = "https://api.forecast.io/forecast/" + FORECAST_IO_APIKEY + "/" + LATITUDE + "," + LONGITUDE | |
response = urllib.urlopen(url); | |
data = json.loads(response.read()) | |
# print json.dumps(data, sort_keys=True, indent=4) | |
temperature = str(int(round(data['currently']['temperature']))) | |
degree_sign = u'\N{DEGREE SIGN}' | |
summary = data['daily']['summary'] | |
today = data['hourly']['summary'] | |
tweet = "It's " + temperature + degree_sign + "F. " + today + " " + summary | |
if len(tweet) > 140: | |
tweet = "It's " + temperature + degree_sign + "F. " + today | |
print tweet | |
api.update_status(status=tweet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: https://twitter.com/wmassweatherbot