Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1.  
  2. #!/usr/bin/env python
  3. # -*- coding: utf-8 -*-
  4.  
  5. import tweepy, time, sys, urllib, json
  6.  
  7. # enter the corresponding information from your Twitter application/Forecast.io API KEY/lat and long:
  8. CONSUMER_KEY = 'DbEG8s1HDlKOHlqj3uHPiwXkm'
  9. CONSUMER_SECRET = '8F0FRwawvUySpuZbzo9THsSV2epcVsOpeC0XRwtrH824nJWYNO'
  10. ACCESS_KEY = '1085469144471011328-VVjezkLyW9tu4UU7DPsohLrPr2lXj2'
  11. ACCESS_SECRET = 's1CTFAij250WxOOKffvY692EAXCZ3iy9n3F7aEnmyqMvM'
  12. FORECAST_IO_APIKEY = 'f8294f034877bd8290859430ce6816e2'
  13. LATITUDE = '32.53213'
  14. LONGITUDE = '-117.07662'
  15.  
  16. auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
  17. auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
  18. api = tweepy.API(auth)
  19.  
  20. url = "https://api.forecast.io/forecast/" + FORECAST_IO_APIKEY + "/" + LATITUDE + "," + LONGITUDE?UNITS=SI
  21. response = urllib.urlopen(url);
  22. data = json.loads(response.read())
  23.  
  24. # print json.dumps(data, sort_keys=True, indent=4)
  25.  
  26. temperature = str(int(round((data['currently']['temperature']-32)/1.8)))
  27. degree_sign = u'\N{DEGREE SIGN}'
  28. summary = data['daily']['summary']
  29. today = data['hourly']['summary']
  30.  
  31. tweet = "It's " + temperature + degree_sign + "C. " + today + " " + summary
  32.  
  33. if len(tweet) > 140:
  34.     tweet = "It's " + temperature + degree_sign + "C. " + today
  35.    
  36. print tweet
  37. api.update_status(status=tweet)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement