Update from 3.4.0 master
This commit is contained in:
parent
af6262ef80
commit
6eda734082
9 changed files with 44 additions and 19 deletions
|
|
@ -3,6 +3,12 @@
|
|||
History
|
||||
-------
|
||||
|
||||
3.4.0 (2016-30-04)
|
||||
++++++++++++++++++
|
||||
- Added `upload_video` endpoint
|
||||
- Fix quoted status checks in `html_for_tweet`
|
||||
- Fix `html_for_tweet` method response when hashtag/mention is a substring of another
|
||||
|
||||
3.3.0 (2015-18-07)
|
||||
++++++++++++++++++
|
||||
- Added support for muting users
|
||||
|
|
|
|||
20
README.rst
20
README.rst
|
|
@ -3,16 +3,16 @@ Twython
|
|||
|
||||
|
||||
.. image:: https://img.shields.io/pypi/v/twython.svg?style=flat-square
|
||||
:target: https://pypi.python.org/pypi/twython
|
||||
:target: https://pypi.python.org/pypi/twython
|
||||
|
||||
.. image:: https://img.shields.io/pypi/dw/twython.svg?style=flat-square
|
||||
:target: https://pypi.python.org/pypi/twython
|
||||
|
||||
:target: https://pypi.python.org/pypi/twython
|
||||
|
||||
.. image:: https://img.shields.io/travis/ryanmcgrath/twython.svg?style=flat-square
|
||||
:target: https://travis-ci.org/ryanmcgrath/twython
|
||||
:target: https://travis-ci.org/ryanmcgrath/twython
|
||||
|
||||
.. image:: https://img.shields.io/coveralls/ryanmcgrath/twython/master.svg?style=flat-square
|
||||
:target: https://coveralls.io/r/ryanmcgrath/twython?branch=master
|
||||
:target: https://coveralls.io/r/ryanmcgrath/twython?branch=master
|
||||
|
||||
``Twython`` is the premier Python library providing an easy (and up-to-date) way to access Twitter data. Actively maintained and featuring support for Python 2.6+ and Python 3. It's been battle tested by companies, educational institutions and individuals alike. Try it today!
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ Or, if you want the code that is currently on GitHub
|
|||
Documentation
|
||||
-------------
|
||||
|
||||
Documentation is available at https://twython.readthedocs.org/en/latest/
|
||||
Documentation is available at https://twython.readthedocs.io/en/latest/
|
||||
|
||||
Starting Out
|
||||
------------
|
||||
|
|
@ -142,7 +142,7 @@ Once you have the final user tokens, store them in a database for later use::
|
|||
OAUTH_TOKEN = final_step['oauth_token']
|
||||
OAUTH_TOKEN_SECRET = final_step['oauth_token_secret']
|
||||
|
||||
For OAuth 2 (Application Only, read-only) authentication, see `our documentation <https://twython.readthedocs.org/en/latest/usage/starting_out.html#oauth-2-application-authentication>`_
|
||||
For OAuth 2 (Application Only, read-only) authentication, see `our documentation <https://twython.readthedocs.io/en/latest/usage/starting_out.html#oauth-2-application-authentication>`_
|
||||
|
||||
Dynamic Function Arguments
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
@ -174,7 +174,7 @@ Documentation: https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
|
|||
Updating Status
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
This method makes use of dynamic arguments, `read more about them <https://twython.readthedocs.org/en/latest/usage/starting_out.html#dynamic-function-arguments>`_
|
||||
This method makes use of dynamic arguments, `read more about them <https://twython.readthedocs.io/en/latest/usage/starting_out.html#dynamic-function-arguments>`_
|
||||
|
||||
Documentation: https://dev.twitter.com/docs/api/1/post/statuses/update
|
||||
|
||||
|
|
@ -195,8 +195,8 @@ Searching
|
|||
Advanced Usage
|
||||
--------------
|
||||
|
||||
- `Advanced Twython Usage <https://twython.readthedocs.org/en/latest/usage/advanced_usage.html>`_
|
||||
- `Streaming with Twython <https://twython.readthedocs.org/en/latest/usage/streaming_api.html>`_
|
||||
- `Advanced Twython Usage <https://twython.readthedocs.io/en/latest/usage/advanced_usage.html>`_
|
||||
- `Streaming with Twython <https://twython.readthedocs.io/en/latest/usage/streaming_api.html>`_
|
||||
|
||||
|
||||
Notes
|
||||
|
|
|
|||
|
|
@ -50,9 +50,9 @@ copyright = u'2013, Ryan McGrath'
|
|||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '3.3.0'
|
||||
version = '3.4.0'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '3.3.0'
|
||||
release = '3.4.0'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
|
|
|||
|
|
@ -72,11 +72,11 @@ The above code takes all the tweets from a specific users timeline, loops over t
|
|||
|
||||
So:
|
||||
|
||||
http://t.co/FCmXyI6VHd is a #cool site, lol! @mikehelmick shd #checkitout. Love, @__twython__ https://t.co/67pwRvY6z9 http://t.co/N6InAO4B71
|
||||
http://t.co/FCmXyI6VHd is #cool, lol! @mikehelmick shd #checkitout. Love, @__twython__ $IBM https://t.co/67pwRvY6z9 http://t.co/N6InAO4B71
|
||||
|
||||
will be replaced with:
|
||||
|
||||
<a href="http://t.co/FCmXyI6VHd" class="twython-url">google.com</a> is a <a href="https://twitter.com/search?q=%23cool" class="twython-hashtag">#cool</a> site, lol! <a href="https://twitter.com/mikehelmick" class="twython-mention">@mikehelmick</a> shd <a href="https://twitter.com/search?q=%23checkitout" class="twython-hashtag">#checkitout</a>. Love, <a href="https://twitter.com/__twython__" class="twython-mention">@__twython__</a> <a href="https://t.co/67pwRvY6z9" class="twython-url">github.com</a> <a href="http://t.co/N6InAO4B71" class="twython-media">pic.twitter.com/N6InAO4B71</a>
|
||||
<a href="http://t.co/FCmXyI6VHd" class="twython-url">google.com</a> is <a href="https://twitter.com/search?q=%23cool" class="twython-hashtag">#cool</a>, lol! <a href="https://twitter.com/mikehelmick" class="twython-mention">@mikehelmick</a> shd <a href="https://twitter.com/search?q=%23checkitout" class="twython-hashtag">#checkitout</a>. Love, <a href="https://twitter.com/__twython__" class="twython-mention">@__twython__</a> <a href="https://twitter.com/?q=%24IBM" class="twython-symbol">$IBM</a> <a href="https://t.co/67pwRvY6z9" class="twython-url">github.com</a> <a href="http://t.co/N6InAO4B71" class="twython-media">pic.twitter.com/N6InAO4B71</a>
|
||||
|
||||
.. note:: When converting the string to HTML we add a class to each HTML tag so that you can maninpulate the DOM later on.
|
||||
|
||||
|
|
@ -84,6 +84,7 @@ will be replaced with:
|
|||
- For media urls that are replaced we add ``class="twython-media"`` to the anchor tag
|
||||
- For user mentions that are replaced we add ``class="twython-mention"`` to the anchor tag
|
||||
- For hashtags that are replaced we add ``class="twython-hashtag"`` to the anchor tag
|
||||
- For symbols that are replaced we add ``class="twython-symbol"`` to the anchor tag
|
||||
|
||||
This function accepts two parameters: ``use_display_url`` and ``use_expanded_url``
|
||||
By default, ``use_display_url`` is ``True``. Meaning the link displayed in the tweet text will appear as (ex. google.com, github.com)
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -9,7 +9,7 @@ except ImportError:
|
|||
from distutils.core import setup
|
||||
|
||||
__author__ = 'Ryan McGrath <ryan@venodesigns.net>'
|
||||
__version__ = '3.3.0'
|
||||
__version__ = '3.4.0'
|
||||
|
||||
packages = [
|
||||
'twython',
|
||||
|
|
|
|||
|
|
@ -28,3 +28,5 @@ test_list_owner_screen_name = os.environ.get('TEST_LIST_OWNER_SCREEN_NAME',
|
|||
|
||||
test_tweet_object = {u'contributors': None, u'truncated': False, u'text': u'http://t.co/FCmXyI6VHd is a #cool site, lol! @mikehelmick shd #checkitout. Love, @__twython__ https://t.co/67pwRvY6z9 http://t.co/N6InAO4B71', u'in_reply_to_status_id': None, u'id': 349683012054683648, u'favorite_count': 0, u'source': u'web', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [{u'id': 29251354, u'indices': [45, 57], u'id_str': u'29251354', u'screen_name': u'mikehelmick', u'name': u'Mike Helmick'}, {u'id': 1431865928, u'indices': [81, 93], u'id_str': u'1431865928', u'screen_name': u'__twython__', u'name': u'Twython'}], u'hashtags': [{u'indices': [28, 33], u'text': u'cool'}, {u'indices': [62, 73], u'text': u'checkitout'}], u'urls': [{u'url': u'http://t.co/FCmXyI6VHd', u'indices': [0, 22], u'expanded_url': u'http://google.com', u'display_url': u'google.com'}, {u'url': u'https://t.co/67pwRvY6z9', u'indices': [94, 117], u'expanded_url': u'https://github.com', u'display_url': u'github.com'}], u'media': [{u'id': 537884378513162240, u'id_str': u'537884378513162240', u'indices': [118, 140], u'media_url': u'http://pbs.twimg.com/media/B3by_g-CQAAhrO5.jpg', u'media_url_https': u'https://pbs.twimg.com/media/B3by_g-CQAAhrO5.jpg', u'url': u'http://t.co/N6InAO4B71', u'display_url': u'pic.twitter.com/N6InAO4B71', u'expanded_url': u'http://twitter.com/pingofglitch/status/537884380060844032/photo/1', u'type': u'photo', u'sizes': {u'large': {u'w': 1024, u'h': 640, u'resize': u'fit'}, u'thumb': {u'w': 150, u'h': 150, u'resize': u'crop'}, u'medium': {u'w': 600, u'h': 375, u'resize': u'fit'}, u'small': {u'w': 340, u'h': 212, u'resize': u'fit'}}}]}, u'in_reply_to_screen_name': None, u'id_str': u'349683012054683648', u'retweet_count': 0, u'in_reply_to_user_id': None, u'favorited': False, u'user': {u'follow_request_sent': False, u'profile_use_background_image': True, u'default_profile_image': True, u'id': 1431865928, u'verified': False, u'profile_text_color': u'333333', u'profile_image_url_https': u'https://si0.twimg.com/sticky/default_profile_images/default_profile_3_normal.png', u'profile_sidebar_fill_color': u'DDEEF6', u'entities': {u'description': {u'urls': []}}, u'followers_count': 1, u'profile_sidebar_border_color': u'C0DEED', u'id_str': u'1431865928', u'profile_background_color': u'3D3D3D', u'listed_count': 0, u'profile_background_image_url_https': u'https://si0.twimg.com/images/themes/theme1/bg.png', u'utc_offset': None, u'statuses_count': 2, u'description': u'', u'friends_count': 1, u'location': u'', u'profile_link_color': u'0084B4', u'profile_image_url': u'http://a0.twimg.com/sticky/default_profile_images/default_profile_3_normal.png', u'following': False, u'geo_enabled': False, u'profile_background_image_url': u'http://a0.twimg.com/images/themes/theme1/bg.png', u'screen_name': u'__twython__', u'lang': u'en', u'profile_background_tile': False, u'favourites_count': 0, u'name': u'Twython', u'notifications': False, u'url': None, u'created_at': u'Thu May 16 01:11:09 +0000 2013', u'contributors_enabled': False, u'time_zone': None, u'protected': False, u'default_profile': False, u'is_translator': False}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'lang': u'en', u'created_at': u'Wed Jun 26 00:18:21 +0000 2013', u'in_reply_to_status_id_str': None, u'place': None}
|
||||
test_tweet_html = '<a href="http://t.co/FCmXyI6VHd" class="twython-url">google.com</a> is a <a href="https://twitter.com/search?q=%23cool" class="twython-hashtag">#cool</a> site, lol! <a href="https://twitter.com/mikehelmick" class="twython-mention">@mikehelmick</a> shd <a href="https://twitter.com/search?q=%23checkitout" class="twython-hashtag">#checkitout</a>. Love, <a href="https://twitter.com/__twython__" class="twython-mention">@__twython__</a> <a href="https://t.co/67pwRvY6z9" class="twython-url">github.com</a> <a href="http://t.co/N6InAO4B71" class="twython-media">pic.twitter.com/N6InAO4B71</a>'
|
||||
|
||||
test_tweet_symbols_object = {u'text': u'Some symbols: $AAPL and $PEP and $ANOTHER and $A.', u'contributors': None, u'geo': None, u'favorited': True, u'in_reply_to_user_id_str': None, u'user': {u'location': u'', u'id_str': u'2030131', u'protected': False, u'profile_background_tile': False, u'friends_count': 18, u'profile_background_image_url_https': u'https://abs.twimg.com/images/themes/theme1/bg.png', u'entities': {u'description': {u'urls': []}}, u'lang': u'en', u'listed_count': 5, u'default_profile_image': True, u'default_profile': False, u'statuses_count': 447, u'notifications': False, u'profile_background_color': u'9AE4E8', u'profile_sidebar_fill_color': u'E0FF92', u'profile_link_color': u'0000FF', u'profile_image_url_https': u'https://abs.twimg.com/sticky/default_profile_images/default_profile_5_normal.png', u'followers_count': 8, u'geo_enabled': True, u'following': True, u'has_extended_profile': False, u'profile_use_background_image': True, u'profile_text_color': u'000000', u'screen_name': u'philgyfordtest', u'contributors_enabled': False, u'verified': False, u'name': u'Phil Gyford Test', u'profile_sidebar_border_color': u'000000', u'utc_offset': 0, u'profile_image_url': u'http://abs.twimg.com/sticky/default_profile_images/default_profile_5_normal.png', u'id': 2030131, u'favourites_count': 0, u'time_zone': u'London', u'url': None, u'is_translation_enabled': False, u'is_translator': False, u'profile_background_image_url': u'http://abs.twimg.com/images/themes/theme1/bg.png', u'description': u'', u'created_at': u'Fri Mar 23 16:56:52 +0000 2007', u'follow_request_sent': False}, u'in_reply_to_user_id': None, u'retweeted': False, u'coordinates': None, u'place': None, u'in_reply_to_status_id': None, u'lang': u'en', u'in_reply_to_status_id_str': None, u'truncated': False, u'retweet_count': 0, u'is_quote_status': False, u'id': 662694880657989632, u'id_str': u'662694880657989632', u'in_reply_to_screen_name': None, u'favorite_count': 1, u'entities': {u'hashtags': [], u'user_mentions': [], u'symbols': [{u'indices': [14, 19], u'text': u'AAPL'}, {u'indices': [24, 28], u'text': u'PEP'}, {u'indices': [46, 48], u'text': u'A'}], u'urls': []}, u'created_at': u'Fri Nov 06 18:15:46 +0000 2015', u'source': u'<a href="http://tapbots.com/software/tweetbot/mac" rel="nofollow">Tweetbot for Mac</a>'}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from twython import Twython, TwythonError, TwythonAuthError, TwythonRateLimitError
|
||||
|
||||
from .config import (
|
||||
test_tweet_object, test_tweet_html, unittest
|
||||
test_tweet_object, test_tweet_html, test_tweet_symbols_object, unittest
|
||||
)
|
||||
|
||||
import responses
|
||||
|
|
@ -324,3 +324,10 @@ class TwythonAPITestCase(unittest.TestCase):
|
|||
del(tweet['entities'])
|
||||
tweet_text = self.api.html_for_tweet(tweet)
|
||||
self.assertEqual(tweet['text'], tweet_text)
|
||||
|
||||
def test_html_for_tweet_symbols(self):
|
||||
tweet_text = self.api.html_for_tweet(test_tweet_symbols_object)
|
||||
# Should only link symbols listed in entities:
|
||||
self.assertTrue('<a href="https://twitter.com/search?q=%24AAPL" class="twython-symbol">$AAPL</a>' in tweet_text)
|
||||
self.assertTrue('<a href="https://twitter.com/search?q=%24ANOTHER" class="twython-symbol">$ANOTHER</a>' not in tweet_text)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ Questions, comments? ryan@venodesigns.net
|
|||
"""
|
||||
|
||||
__author__ = 'Ryan McGrath <ryan@venodesigns.net>'
|
||||
__version__ = '3.3.0'
|
||||
__version__ = '3.4.0'
|
||||
|
||||
from .api import Twython
|
||||
from .streaming import TwythonStreamer
|
||||
|
|
|
|||
|
|
@ -528,7 +528,7 @@ class Twython(EndpointsMixin, object):
|
|||
|
||||
@staticmethod
|
||||
def html_for_tweet(tweet, use_display_url=True, use_expanded_url=False, expand_quoted_status=False):
|
||||
"""Return HTML for a tweet (urls, mentions, hashtags replaced with links)
|
||||
"""Return HTML for a tweet (urls, mentions, hashtags, symbols replaced with links)
|
||||
|
||||
:param tweet: Tweet object from received from Twitter API
|
||||
:param use_display_url: Use display URL to represent link
|
||||
|
|
@ -567,6 +567,15 @@ class Twython(EndpointsMixin, object):
|
|||
text = re.sub(r'(?<!>)' + tweet['text'][start:end] + '(?!</a>)',
|
||||
hashtag_html % {'hashtag': entity['text']}, text)
|
||||
|
||||
# Symbols
|
||||
for entity in sorted(entities['symbols'],
|
||||
key=lambda symbol: len(symbol['text']), reverse=True):
|
||||
start, end = entity['indices'][0], entity['indices'][1]
|
||||
|
||||
symbol_html = '<a href="https://twitter.com/search?q=%%24%(symbol)s" class="twython-symbol">$%(symbol)s</a>'
|
||||
text = re.sub(r'(?<!>)' + re.escape(tweet['text'][start:end]) + '(?!</a>)',
|
||||
symbol_html % {'symbol': entity['text']}, text)
|
||||
|
||||
# Urls
|
||||
for entity in entities['urls']:
|
||||
start, end = entity['indices'][0], entity['indices'][1]
|
||||
|
|
@ -598,7 +607,7 @@ class Twython(EndpointsMixin, object):
|
|||
text = text.replace(tweet['text'][start:end],
|
||||
url_html % (entity['url'], shown_url))
|
||||
|
||||
if expand_quoted_status and tweet.get('is_quote_status'):
|
||||
if expand_quoted_status and tweet.get('is_quote_status') and tweet.get('quoted_status'):
|
||||
quoted_status = tweet['quoted_status']
|
||||
text += '<blockquote class="twython-quote">%(quote)s<cite><a href="%(quote_tweet_link)s">' \
|
||||
'<span class="twython-quote-user-name">%(quote_user_name)s</span>' \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue