Redid some examples, moved examples to core_examples to differentiate from oauth_django_example, version bump to 1.3.2 to fix distribution errors with Pip/etc (dumb binaries were being created earlier, just throwing out the source now and letting pip handle it)
This commit is contained in:
parent
25eda807ab
commit
3cef1a463f
22 changed files with 138 additions and 72 deletions
|
|
@ -1,3 +1,3 @@
|
||||||
include LICENSE README.markdown
|
include LICENSE README.markdown README.txt
|
||||||
recursive-include examples *
|
recursive-include examples *
|
||||||
recursive-exclude examples *.pyc
|
recursive-exclude examples *.pyc
|
||||||
|
|
|
||||||
86
README.txt
Normal file
86
README.txt
Normal file
|
|
@ -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.
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import twython.core as twython
|
from twython import Twython
|
||||||
|
|
||||||
""" Instantiate Twython with no Authentication """
|
""" Instantiate Twython with no Authentication """
|
||||||
twitter = twython.setup()
|
twitter = Twython()
|
||||||
trends = twitter.getCurrentTrends()
|
trends = twitter.getCurrentTrends()
|
||||||
|
|
||||||
print trends
|
print trends
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import twython.core as twython
|
from twython import Twython
|
||||||
|
|
||||||
""" Instantiate Twython with no Authentication """
|
""" Instantiate Twython with no Authentication """
|
||||||
twitter = twython.setup()
|
twitter = Twython()
|
||||||
trends = twitter.getDailyTrends()
|
trends = twitter.getDailyTrends()
|
||||||
|
|
||||||
print trends
|
print trends
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import twython.core as twython
|
from twython import Twython
|
||||||
|
|
||||||
# We won't authenticate for this, but sometimes it's necessary
|
# We won't authenticate for this, but sometimes it's necessary
|
||||||
twitter = twython.setup()
|
twitter = Twython()
|
||||||
user_timeline = twitter.getUserTimeline(screen_name="ryanmcgrath")
|
user_timeline = twitter.getUserTimeline(screen_name="ryanmcgrath")
|
||||||
|
|
||||||
print user_timeline
|
print user_timeline
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import twython.core as twython
|
from twython import Twython
|
||||||
|
|
||||||
# Getting the public timeline requires no authentication, huzzah
|
# Getting the public timeline requires no authentication, huzzah
|
||||||
twitter = twython.setup()
|
twitter = Twython()
|
||||||
public_timeline = twitter.getPublicTimeline()
|
public_timeline = twitter.getPublicTimeline()
|
||||||
|
|
||||||
for tweet in public_timeline:
|
for tweet in public_timeline:
|
||||||
8
core_examples/search_results.py
Normal file
8
core_examples/search_results.py
Normal file
|
|
@ -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"]
|
||||||
6
core_examples/shorten_url.py
Normal file
6
core_examples/shorten_url.py
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
from twython import Twython
|
||||||
|
|
||||||
|
# Shortening URLs requires no authentication, huzzah
|
||||||
|
shortURL = Twython.shortenURL("http://www.webs.com/")
|
||||||
|
|
||||||
|
print shortURL
|
||||||
9
core_examples/update_profile_image.py
Normal file
9
core_examples/update_profile_image.py
Normal file
|
|
@ -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")
|
||||||
13
core_examples/update_status.py
Normal file
13
core_examples/update_status.py
Normal file
|
|
@ -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?")
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import twython.core as twython
|
from twython import Twython
|
||||||
|
|
||||||
""" Instantiate Twython with no Authentication """
|
""" Instantiate Twython with no Authentication """
|
||||||
twitter = twython.setup()
|
twitter = Twython()
|
||||||
trends = twitter.getWeeklyTrends()
|
trends = twitter.getWeeklyTrends()
|
||||||
|
|
||||||
print trends
|
print trends
|
||||||
|
|
@ -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"]
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
import twython.core as twython
|
|
||||||
|
|
||||||
twitter = twython.setup(username="example", password="example")
|
|
||||||
mentions = twitter.getUserMentions(count="150")
|
|
||||||
|
|
||||||
print mentions
|
|
||||||
|
|
@ -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")
|
|
||||||
|
|
@ -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"]
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -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")
|
|
||||||
|
|
@ -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")
|
|
||||||
|
|
@ -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?")
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -5,7 +5,7 @@ from setuptools import setup
|
||||||
from setuptools import find_packages
|
from setuptools import find_packages
|
||||||
|
|
||||||
__author__ = 'Ryan McGrath <ryan@venodesigns.net>'
|
__author__ = 'Ryan McGrath <ryan@venodesigns.net>'
|
||||||
__version__ = '1.3'
|
__version__ = '1.3.2'
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
# Basic package information.
|
# Basic package information.
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__author__ = "Ryan McGrath <ryan@venodesigns.net>"
|
__author__ = "Ryan McGrath <ryan@venodesigns.net>"
|
||||||
__version__ = "1.3"
|
__version__ = "1.3.2"
|
||||||
|
|
||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__author__ = "Ryan McGrath <ryan@venodesigns.net>"
|
__author__ = "Ryan McGrath <ryan@venodesigns.net>"
|
||||||
__version__ = "1.3"
|
__version__ = "1.3.2"
|
||||||
|
|
||||||
import urllib.request, urllib.parse, urllib.error
|
import urllib.request, urllib.parse, urllib.error
|
||||||
import urllib.request, urllib.error, urllib.parse
|
import urllib.request, urllib.error, urllib.parse
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue