Last active
          August 29, 2015 14:25 
        
      - 
      
- 
        Save ChuckWoodraska/219406044f464c4e73ba to your computer and use it in GitHub Desktop. 
    Tweet weather
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | import time | |
| import pywapi | |
| import string | |
| import tweepy | |
| from myconfig import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_SECRET, ZIPCODE | |
| auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) | |
| auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET) | |
| api = tweepy.API(auth) | |
| while True: | |
| result = pywapi.get_weather_from_yahoo(ZIPCODE, 'metric') | |
| weather_str = "The weather is {0} and {1}C now in {2}, {3}.\n".format(string.lower(result['condition']['text']), result['condition']['temp'], result['location']['city'], result['location']['region']) | |
| try: | |
| api.update_status(weather_str) | |
| except Exception: | |
| # Most likely status was a duplicate because weather didn't change. | |
| pass | |
| time.sleep(3600) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment