Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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 = 'DbEG8s1HDlKOHlqj3uHPiwXkm'
- CONSUMER_SECRET = '8F0FRwawvUySpuZbzo9THsSV2epcVsOpeC0XRwtrH824nJWYNO'
- ACCESS_KEY = '1085469144471011328-VVjezkLyW9tu4UU7DPsohLrPr2lXj2'
- ACCESS_SECRET = 's1CTFAij250WxOOKffvY692EAXCZ3iy9n3F7aEnmyqMvM'
- FORECAST_IO_APIKEY = 'f8294f034877bd8290859430ce6816e2'
- LATITUDE = '32.53213'
- LONGITUDE = '-117.07662'
- 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?UNITS=SI
- 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']-32)/1.8)))
- degree_sign = u'\N{DEGREE SIGN}'
- summary = data['daily']['summary']
- today = data['hourly']['summary']
- tweet = "It's " + temperature + degree_sign + "C. " + today + " " + summary
- if len(tweet) > 140:
- tweet = "It's " + temperature + degree_sign + "C. " + today
- print tweet
- api.update_status(status=tweet)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement