diff --git a/MANIFEST.in b/MANIFEST.in index 0d9cce8..0878b48 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ -include LICENSE README.markdown +include LICENSE README.markdown README.txt recursive-include examples * recursive-exclude examples *.pyc diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..6eb928f --- /dev/null +++ b/README.txt @@ -0,0 +1,86 @@ +Twython - Easy Twitter utilities in Python +========================================================================================= +Ah, Twitter, your API used to be so awesome, before you went and implemented the crap known +as OAuth 1.0. However, since you decided to force your entire development community over a barrel +about it, I suppose Twython has to support this. So, that said... + +If you used this library and it all stopped working, it's because of the Authentication method change. +========================================================================================================= +Twitter recently disabled the use of "Basic Authentication", which is why, if you used Twython previously, +you probably started getting a ton of 401 errors. To fix this, we should note one thing... + +You need to change how authentication works in your program/application. If you're using a command line +application or something, you'll probably languish in hell for a bit, because OAuth wasn't really designed +for those types of use cases. Twython cannot help you with that or fix the annoying parts of OAuth. + +If you need OAuth, though, Twython now supports it, and ships with a skeleton Django application to get you started. +Enjoy! + +Requirements +----------------------------------------------------------------------------------------------------- +Twython (for versions of Python before 2.6) requires a library called +"simplejson". Depending on your flavor of package manager, you can do the following... + + (pip install | easy_install) simplejson + +Twython also requires the (most excellent) OAuth2 library for handling OAuth tokens/signing/etc. Again... + + (pip install | easy_install) oauth2 + +Installation +----------------------------------------------------------------------------------------------------- +Installing Twython is fairly easy. You can... + + (pip install | easy_install) twython + +...or, you can clone the repo and install it the old fashioned way. + + git clone git://github.com/ryanmcgrath/twython.git + cd twython + sudo python setup.py install + +Example Use +----------------------------------------------------------------------------------------------------- + from twython import Twython + + twitter = Twython() + results = twitter.searchTwitter(q="bert") + + # More function definitions can be found by reading over twython/twitter_endpoints.py, as well + # as skimming the source file. Both are kept human-readable, and are pretty well documented or + # very self documenting. + +A note about the development of Twython (specifically, 1.3) +---------------------------------------------------------------------------------------------------- +As of version 1.3, Twython has been extensively overhauled. Most API endpoint definitions are stored +in a separate Python file, and the class itself catches calls to methods that match up in said table. + +Certain functions require a bit more legwork, and get to stay in the main file, but for the most part +it's all abstracted out. + +As of Twython 1.3, the syntax has changed a bit as well. Instead of Twython.core, there's a main +Twython class to import and use. If you need to catch exceptions, import those from twython as well. + +Arguments to functions are now exact keyword matches for the Twitter API documentation - that means that +whatever query parameter arguments you read on Twitter's documentation (http://dev.twitter.com/doc) gets mapped +as a named argument to any Twitter function. + +For example: the search API looks for arguments under the name "q", so you pass q="query_here" to searchTwitter(). + +Doing this allows us to be incredibly flexible in querying the Twitter API, so changes to the API aren't held up +from you using them by this library. + +Twython 3k +----------------------------------------------------------------------------------------------------- +There's an experimental version of Twython that's made for Python 3k. This is currently not guaranteed +to work (especially with regards to OAuth), but it's provided so that others can grab it and hack on it. +If you choose to try it out, be aware of this. + + +Questions, Comments, etc? +----------------------------------------------------------------------------------------------------- +My hope is that Twython is so simple that you'd never *have* to ask any questions, but if +you feel the need to contact me for this (or other) reasons, you can hit me up +at ryan@venodesigns.net. + +Twython is released under an MIT License - see the LICENSE file for more information. diff --git a/examples/current_trends.py b/core_examples/current_trends.py similarity index 64% rename from examples/current_trends.py rename to core_examples/current_trends.py index 8ee4d74..53f64f1 100644 --- a/examples/current_trends.py +++ b/core_examples/current_trends.py @@ -1,7 +1,7 @@ -import twython.core as twython +from twython import Twython """ Instantiate Twython with no Authentication """ -twitter = twython.setup() +twitter = Twython() trends = twitter.getCurrentTrends() print trends diff --git a/examples/daily_trends.py b/core_examples/daily_trends.py similarity index 63% rename from examples/daily_trends.py rename to core_examples/daily_trends.py index 38ca507..d4acc66 100644 --- a/examples/daily_trends.py +++ b/core_examples/daily_trends.py @@ -1,7 +1,7 @@ -import twython.core as twython +from twython import Twython """ Instantiate Twython with no Authentication """ -twitter = twython.setup() +twitter = Twython() trends = twitter.getDailyTrends() print trends diff --git a/examples/get_user_timeline.py b/core_examples/get_user_timeline.py similarity index 72% rename from examples/get_user_timeline.py rename to core_examples/get_user_timeline.py index bdb9200..9dd27e8 100644 --- a/examples/get_user_timeline.py +++ b/core_examples/get_user_timeline.py @@ -1,7 +1,7 @@ -import twython.core as twython +from twython import Twython # We won't authenticate for this, but sometimes it's necessary -twitter = twython.setup() +twitter = Twython() user_timeline = twitter.getUserTimeline(screen_name="ryanmcgrath") print user_timeline diff --git a/examples/public_timeline.py b/core_examples/public_timeline.py similarity index 74% rename from examples/public_timeline.py rename to core_examples/public_timeline.py index 4670037..40d311d 100644 --- a/examples/public_timeline.py +++ b/core_examples/public_timeline.py @@ -1,7 +1,7 @@ -import twython.core as twython +from twython import Twython # Getting the public timeline requires no authentication, huzzah -twitter = twython.setup() +twitter = Twython() public_timeline = twitter.getPublicTimeline() for tweet in public_timeline: diff --git a/core_examples/search_results.py b/core_examples/search_results.py new file mode 100644 index 0000000..54c7dd0 --- /dev/null +++ b/core_examples/search_results.py @@ -0,0 +1,8 @@ +from twython import Twython + +""" Instantiate Twython with no Authentication """ +twitter = Twython() +search_results = twitter.searchTwitter(q="WebsDotCom", rpp="50") + +for tweet in search_results["results"]: + print tweet["text"] diff --git a/core_examples/shorten_url.py b/core_examples/shorten_url.py new file mode 100644 index 0000000..8ca57ba --- /dev/null +++ b/core_examples/shorten_url.py @@ -0,0 +1,6 @@ +from twython import Twython + +# Shortening URLs requires no authentication, huzzah +shortURL = Twython.shortenURL("http://www.webs.com/") + +print shortURL diff --git a/core_examples/update_profile_image.py b/core_examples/update_profile_image.py new file mode 100644 index 0000000..7f3b5ef --- /dev/null +++ b/core_examples/update_profile_image.py @@ -0,0 +1,9 @@ +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 new file mode 100644 index 0000000..52113f1 --- /dev/null +++ b/core_examples/update_status.py @@ -0,0 +1,13 @@ +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("See how easy this was?") diff --git a/examples/weekly_trends.py b/core_examples/weekly_trends.py similarity index 63% rename from examples/weekly_trends.py rename to core_examples/weekly_trends.py index e48fb95..d457242 100644 --- a/examples/weekly_trends.py +++ b/core_examples/weekly_trends.py @@ -1,7 +1,7 @@ -import twython.core as twython +from twython import Twython """ Instantiate Twython with no Authentication """ -twitter = twython.setup() +twitter = Twython() trends = twitter.getWeeklyTrends() print trends diff --git a/examples/get_friends_timeline.py b/examples/get_friends_timeline.py deleted file mode 100644 index 9e67583..0000000 --- a/examples/get_friends_timeline.py +++ /dev/null @@ -1,8 +0,0 @@ -import twython.core as twython, pprint - -# Authenticate using Basic (HTTP) Authentication -twitter = twython.setup(username="example", password="example") -friends_timeline = twitter.getFriendsTimeline(count="150", page="3") - -for tweet in friends_timeline: - print tweet["text"] diff --git a/examples/get_user_mention.py b/examples/get_user_mention.py deleted file mode 100644 index 0db63a0..0000000 --- a/examples/get_user_mention.py +++ /dev/null @@ -1,6 +0,0 @@ -import twython.core as twython - -twitter = twython.setup(username="example", password="example") -mentions = twitter.getUserMentions(count="150") - -print mentions diff --git a/examples/rate_limit.py b/examples/rate_limit.py deleted file mode 100644 index 4b632b0..0000000 --- a/examples/rate_limit.py +++ /dev/null @@ -1,10 +0,0 @@ -import twython.core as twython - -# Instantiate with Basic (HTTP) Authentication -twitter = twython.setup(username="example", password="example") - -# This returns the rate limit for the requesting IP -rateLimit = twitter.getRateLimitStatus() - -# This returns the rate limit for the requesting authenticated user -rateLimit = twitter.getRateLimitStatus(rate_for="user") diff --git a/examples/search_results.py b/examples/search_results.py deleted file mode 100644 index e0df48b..0000000 --- a/examples/search_results.py +++ /dev/null @@ -1,8 +0,0 @@ -import twython.core as twython - -""" Instantiate Tango with no Authentication """ -twitter = twython.setup() -search_results = twitter.searchTwitter("WebsDotCom", rpp="50") - -for tweet in search_results["results"]: - print tweet["text"] diff --git a/examples/shorten_url.py b/examples/shorten_url.py deleted file mode 100644 index f0824bf..0000000 --- a/examples/shorten_url.py +++ /dev/null @@ -1,7 +0,0 @@ -import twython as twython - -# Shortening URLs requires no authentication, huzzah -twitter = twython.setup() -shortURL = twitter.shortenURL("http://www.webs.com/") - -print shortURL diff --git a/examples/twython_setup.py b/examples/twython_setup.py deleted file mode 100644 index 6eea228..0000000 --- a/examples/twython_setup.py +++ /dev/null @@ -1,7 +0,0 @@ -import twython.core as twython - -# Using no authentication -twitter = twython.setup() - -# Using Basic Authentication (core is all about basic auth, look to twython.oauth in the future for oauth) -twitter = twython.setup(username="example", password="example") diff --git a/examples/update_profile_image.py b/examples/update_profile_image.py deleted file mode 100644 index 37ee00e..0000000 --- a/examples/update_profile_image.py +++ /dev/null @@ -1,5 +0,0 @@ -import twython.core as twython - -# Instantiate Twython with Basic (HTTP) Authentication -twitter = twython.setup(username="example", password="example") -twitter.updateProfileImage("myImage.png") diff --git a/examples/update_status.py b/examples/update_status.py deleted file mode 100644 index 0f7fe38..0000000 --- a/examples/update_status.py +++ /dev/null @@ -1,5 +0,0 @@ -import twython.core as twython - -# Create a Twython instance using Basic (HTTP) Authentication and update our Status -twitter = twython.setup(username="example", password="example") -twitter.updateStatus("See how easy this was?") diff --git a/setup.py b/setup.py index 505eea7..e4036e7 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup from setuptools import find_packages __author__ = 'Ryan McGrath ' -__version__ = '1.3' +__version__ = '1.3.2' setup( # Basic package information. diff --git a/twython/twython.py b/twython/twython.py index 4ae4daf..79bf641 100644 --- a/twython/twython.py +++ b/twython/twython.py @@ -9,7 +9,7 @@ """ __author__ = "Ryan McGrath " -__version__ = "1.3" +__version__ = "1.3.2" import urllib import urllib2 @@ -414,4 +414,4 @@ class Twython(object): text = text.encode('utf-8') except: pass - return text \ No newline at end of file + return text diff --git a/twython3k/twython.py b/twython3k/twython.py index 5efa1e7..bdc84ba 100644 --- a/twython3k/twython.py +++ b/twython3k/twython.py @@ -9,7 +9,7 @@ """ __author__ = "Ryan McGrath " -__version__ = "1.3" +__version__ = "1.3.2" import urllib.request, urllib.parse, urllib.error import urllib.request, urllib.error, urllib.parse @@ -414,4 +414,4 @@ class Twython(object): text = text.encode('utf-8') except: pass - return text \ No newline at end of file + return text