Skip to content

Instantly share code, notes, and snippets.

@urschrei
Created February 1, 2011 00:14
Show Gist options
  • Save urschrei/805129 to your computer and use it in GitHub Desktop.
Save urschrei/805129 to your computer and use it in GitHub Desktop.
retrieve trending topics from a WOEID location
#!/usr/bin/env python
# encoding: utf-8
"""
twitrend.py
"""
import sys
import os
import tweepy
import json
def main():
""" main function
"""
# own OAuth consumer key, secret, and access key and token required
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth, secure = True)
woeid = 23424977
retrieved = api.trends_location(woeid)
# gives us full output:
print retrieved[0]
# gives us '0':
print retrieved[0][0]
if __name__ == "__main__":
try:
main()
except (KeyboardInterrupt, SystemExit):
# actually raise these, for a clean exit
raise
except Exception, error:
# all other exceptions: display the error
print error
else:
pass
finally:
# exit cleanly once we've done everything else
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment