From 4ac6436901d16394e264cd36234e55d24e4dba28 Mon Sep 17 00:00:00 2001 From: Mike Helmick Date: Thu, 18 Apr 2013 22:21:32 -0400 Subject: [PATCH] Update Examples and LICENSE Some examples were out of date (any trends example) Renamed the core_examples dir. to examples --- LICENSE | 2 +- README.md | 11 ++++++----- core_examples/current_trends.py | 7 ------- core_examples/daily_trends.py | 7 ------- core_examples/get_user_timeline.py | 7 ------- core_examples/search_results.py | 9 --------- core_examples/update_profile_image.py | 9 --------- core_examples/update_status.py | 14 -------------- core_examples/weekly_trends.py | 7 ------- examples/get_user_timeline.py | 10 ++++++++++ examples/search_results.py | 12 ++++++++++++ {core_examples => examples}/shorten_url.py | 2 +- examples/update_profile_image.py | 5 +++++ examples/update_status.py | 9 +++++++++ 14 files changed, 44 insertions(+), 67 deletions(-) delete mode 100644 core_examples/current_trends.py delete mode 100644 core_examples/daily_trends.py delete mode 100644 core_examples/get_user_timeline.py delete mode 100644 core_examples/search_results.py delete mode 100644 core_examples/update_profile_image.py delete mode 100644 core_examples/update_status.py delete mode 100644 core_examples/weekly_trends.py create mode 100644 examples/get_user_timeline.py create mode 100644 examples/search_results.py rename {core_examples => examples}/shorten_url.py (64%) create mode 100644 examples/update_profile_image.py create mode 100644 examples/update_status.py diff --git a/LICENSE b/LICENSE index cd5b253..f723943 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License -Copyright (c) 2009 - 2010 Ryan McGrath +Copyright (c) 2013 Ryan McGrath Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 4c8fe3b..38205f9 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Installation Usage ----- -###### Authorization URL +##### Authorization URL ```python from twython import Twython @@ -49,7 +49,7 @@ print 'Connect to Twitter via: %s' % auth_props['auth_url'] Be sure you have a URL set up to handle the callback after the user has allowed your app to access their data, the callback can be used for storing their final OAuth Token and OAuth Token Secret in a database for use at a later date. -###### Handling the callback +##### Handling the callback ```python from twython import Twython @@ -72,7 +72,7 @@ print auth_tokens *Function definitions (i.e. getHomeTimeline()) can be found by reading over twython/endpoints.py* -###### Getting a user home timeline +##### Getting a user home timeline ```python from twython import Twython @@ -87,8 +87,9 @@ t = Twython(app_key, app_secret, print t.getHomeTimeline() ``` -###### Catching exceptions +##### Catching exceptions > Twython offers three Exceptions currently: TwythonError, TwythonAuthError and TwythonRateLimitError + ```python from twython import Twython, TwythonAuthError @@ -101,7 +102,7 @@ except TwythonAuthError as e: print e ``` -###### Streaming API +##### Streaming API *Usage is as follows; it's designed to be open-ended enough that you can adapt it to higher-level (read: Twitter must give you access) streams.* diff --git a/core_examples/current_trends.py b/core_examples/current_trends.py deleted file mode 100644 index 53f64f1..0000000 --- a/core_examples/current_trends.py +++ /dev/null @@ -1,7 +0,0 @@ -from twython import Twython - -""" Instantiate Twython with no Authentication """ -twitter = Twython() -trends = twitter.getCurrentTrends() - -print trends diff --git a/core_examples/daily_trends.py b/core_examples/daily_trends.py deleted file mode 100644 index d4acc66..0000000 --- a/core_examples/daily_trends.py +++ /dev/null @@ -1,7 +0,0 @@ -from twython import Twython - -""" Instantiate Twython with no Authentication """ -twitter = Twython() -trends = twitter.getDailyTrends() - -print trends diff --git a/core_examples/get_user_timeline.py b/core_examples/get_user_timeline.py deleted file mode 100644 index 9dd27e8..0000000 --- a/core_examples/get_user_timeline.py +++ /dev/null @@ -1,7 +0,0 @@ -from twython import Twython - -# We won't authenticate for this, but sometimes it's necessary -twitter = Twython() -user_timeline = twitter.getUserTimeline(screen_name="ryanmcgrath") - -print user_timeline diff --git a/core_examples/search_results.py b/core_examples/search_results.py deleted file mode 100644 index 57b4c51..0000000 --- a/core_examples/search_results.py +++ /dev/null @@ -1,9 +0,0 @@ -from twython import Twython - -""" Instantiate Twython with no Authentication """ -twitter = Twython() -search_results = twitter.search(q="WebsDotCom", rpp="50") - -for tweet in search_results["results"]: - print "Tweet from @%s Date: %s" % (tweet['from_user'].encode('utf-8'),tweet['created_at']) - print tweet['text'].encode('utf-8'),"\n" \ No newline at end of file diff --git a/core_examples/update_profile_image.py b/core_examples/update_profile_image.py deleted file mode 100644 index 857140a..0000000 --- a/core_examples/update_profile_image.py +++ /dev/null @@ -1,9 +0,0 @@ -from twython import Twython - -""" - You'll need to go through the OAuth ritual to be able to successfully - use this function. See the example oauth django application included in - this package for more information. -""" -twitter = Twython() -twitter.updateProfileImage("myImage.png") diff --git a/core_examples/update_status.py b/core_examples/update_status.py deleted file mode 100644 index 9b7deca..0000000 --- a/core_examples/update_status.py +++ /dev/null @@ -1,14 +0,0 @@ -from twython import Twython - -""" - Note: for any method that'll require you to be authenticated (updating - things, etc) - you'll need to go through the OAuth authentication ritual. See the example - Django application that's included with this package for more information. -""" -twitter = Twython() - -# OAuth ritual... - - -twitter.updateStatus(status="See how easy this was?") diff --git a/core_examples/weekly_trends.py b/core_examples/weekly_trends.py deleted file mode 100644 index d457242..0000000 --- a/core_examples/weekly_trends.py +++ /dev/null @@ -1,7 +0,0 @@ -from twython import Twython - -""" Instantiate Twython with no Authentication """ -twitter = Twython() -trends = twitter.getWeeklyTrends() - -print trends diff --git a/examples/get_user_timeline.py b/examples/get_user_timeline.py new file mode 100644 index 0000000..19fb031 --- /dev/null +++ b/examples/get_user_timeline.py @@ -0,0 +1,10 @@ +from twython import Twython, TwythonError + +# Requires Authentication as of Twitter API v1.1 +twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) +try: + user_timeline = twitter.getUserTimeline(screen_name='ryanmcgrath') +except TwythonError as e: + print e + +print user_timeline diff --git a/examples/search_results.py b/examples/search_results.py new file mode 100644 index 0000000..6d4dc7c --- /dev/null +++ b/examples/search_results.py @@ -0,0 +1,12 @@ +from twython import Twython, TwythonError + +# Requires Authentication as of Twitter API v1.1 +twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) +try: + search_results = twitter.search(q="WebsDotCom", rpp="50") +except TwythonError as e: + print e + +for tweet in search_results["results"]: + print "Tweet from @%s Date: %s" % (tweet['from_user'].encode('utf-8'),tweet['created_at']) + print tweet['text'].encode('utf-8'),"\n" \ No newline at end of file diff --git a/core_examples/shorten_url.py b/examples/shorten_url.py similarity index 64% rename from core_examples/shorten_url.py rename to examples/shorten_url.py index 8ca57ba..42d0f40 100644 --- a/core_examples/shorten_url.py +++ b/examples/shorten_url.py @@ -1,6 +1,6 @@ from twython import Twython # Shortening URLs requires no authentication, huzzah -shortURL = Twython.shortenURL("http://www.webs.com/") +shortURL = Twython.shortenURL('http://www.webs.com/') print shortURL diff --git a/examples/update_profile_image.py b/examples/update_profile_image.py new file mode 100644 index 0000000..1bb9782 --- /dev/null +++ b/examples/update_profile_image.py @@ -0,0 +1,5 @@ +from twython import Twython + +# Requires Authentication as of Twitter API v1.1 +twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) +twitter.updateProfileImage('myImage.png') diff --git a/examples/update_status.py b/examples/update_status.py new file mode 100644 index 0000000..1ecfcba --- /dev/null +++ b/examples/update_status.py @@ -0,0 +1,9 @@ +from twython import Twython, TwythonError + +# Requires Authentication as of Twitter API v1.1 +twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) + +try: + twitter.updateStatus(status='See how easy this was?') +except TwythonError as e: + print e