From 36fda7ac02a8047d11ad4de12161a6ffd1e869ea Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Sat, 22 Sep 2018 12:01:57 -0500 Subject: [PATCH 01/27] Added new endpoints for direct messages --- twython/api.py | 22 +++++++++++++++------- twython/endpoints.py | 12 ++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/twython/api.py b/twython/api.py index 4953129..10c4963 100644 --- a/twython/api.py +++ b/twython/api.py @@ -135,13 +135,13 @@ class Twython(EndpointsMixin, object): def __repr__(self): return '' % (self.app_key) - def _request(self, url, method='GET', params=None, api_call=None): + def _request(self, url, method='GET', params=None, api_call=None, json_encoded=False): """Internal request method""" method = method.lower() params = params or {} func = getattr(self.client, method) - if isinstance(params, dict): + if isinstance(params, dict) and json_encoded == False: params, files = _transparent_params(params) else: params = params @@ -156,8 +156,13 @@ class Twython(EndpointsMixin, object): if method == 'get': requests_args['params'] = params else: + # Check for json_encoded so we will sent params as "data" or "json" + if json_encoded: + data_key = "json" + else: + data_key = "data" requests_args.update({ - 'data': params, + data_key: params, 'files': files, }) try: @@ -230,7 +235,7 @@ class Twython(EndpointsMixin, object): return error_message - def request(self, endpoint, method='GET', params=None, version='1.1'): + def request(self, endpoint, method='GET', params=None, version='1.1', json_encoded=False): """Return dict of response received from Twitter's API :param endpoint: (required) Full url or Twitter API endpoint @@ -246,6 +251,9 @@ class Twython(EndpointsMixin, object): :param version: (optional) Twitter API version to access (default 1.1) :type version: string + :param json_encoded: (optional) Flag to indicate if this method should send data encoded as json + (default False) + :type json_encoded: bool :rtype: dict """ @@ -261,7 +269,7 @@ class Twython(EndpointsMixin, object): url = '%s/%s.json' % (self.api_url % version, endpoint) content = self._request(url, method=method, params=params, - api_call=url) + api_call=url, json_encoded=json_encoded) return content @@ -269,9 +277,9 @@ class Twython(EndpointsMixin, object): """Shortcut for GET requests via :class:`request`""" return self.request(endpoint, params=params, version=version) - def post(self, endpoint, params=None, version='1.1'): + def post(self, endpoint, params=None, version='1.1', json_encoded=False): """Shortcut for POST requests via :class:`request`""" - return self.request(endpoint, 'POST', params=params, version=version) + return self.request(endpoint, 'POST', params=params, version=version, json_encoded=json_encoded) def get_lastfunction_header(self, header, default_return_value=None): """Returns a specific header from the last API call diff --git a/twython/endpoints.py b/twython/endpoints.py index 00392b8..f7e0a5a 100644 --- a/twython/endpoints.py +++ b/twython/endpoints.py @@ -300,10 +300,10 @@ class EndpointsMixin(object): """Returns the 20 most recent direct messages sent to the authenticating user. Docs: - https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/get-messages + https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/list-events """ - return self.get('direct_messages', params=params) + return self.get('direct_messages/events/list', params=params) get_direct_messages.iter_mode = 'id' def get_sent_messages(self, **params): @@ -320,10 +320,10 @@ class EndpointsMixin(object): """Returns a single direct message, specified by an ``id`` parameter. Docs: - https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/get-message + https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/get-event """ - return self.get('direct_messages/show', params=params) + return self.get('direct_messages/events/show', params=params) def destroy_direct_message(self, **params): """Destroys the direct message specified in the required ``id`` parameter @@ -339,10 +339,10 @@ class EndpointsMixin(object): authenticating user. Docs: - https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-message + https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-event """ - return self.post('direct_messages/new', params=params) + return self.post('direct_messages/events/new', params=params, json_encoded=True) # Friends & Followers def get_user_ids_of_blocked_retweets(self, **params): From 340fb4ea162b3e02fb5e245ad8651ec62d34cea5 Mon Sep 17 00:00:00 2001 From: Vishvajit Pathak Date: Sat, 29 Sep 2018 15:18:31 +0530 Subject: [PATCH 02/27] ISSUE-497 : Fixed the api end point in get_oembed_tweet --- twython/endpoints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twython/endpoints.py b/twython/endpoints.py index 00392b8..9da30db 100644 --- a/twython/endpoints.py +++ b/twython/endpoints.py @@ -268,7 +268,7 @@ class EndpointsMixin(object): https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-oembed """ - return self.get('statuses/oembed', params=params) + return self.get('oembed', params=params) def get_retweeters_ids(self, **params): """Returns a collection of up to 100 user IDs belonging to users who From a8a0777f7266f87ca1f6af921c35f573a71f45e3 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Sat, 29 Sep 2018 11:09:00 -0500 Subject: [PATCH 03/27] Added delete methods to Twython's API --- twython/api.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/twython/api.py b/twython/api.py index 10c4963..96d1ae7 100644 --- a/twython/api.py +++ b/twython/api.py @@ -153,7 +153,7 @@ class Twython(EndpointsMixin, object): if k in ('timeout', 'allow_redirects', 'stream', 'verify'): requests_args[k] = v - if method == 'get': + if method == 'get' or method == 'delete': requests_args['params'] = params else: # Check for json_encoded so we will sent params as "data" or "json" @@ -242,7 +242,7 @@ class Twython(EndpointsMixin, object): (e.g. search/tweets) :type endpoint: string :param method: (optional) Method of accessing data, either - GET or POST. (default GET) + GET, POST or DELETE. (default GET) :type method: string :param params: (optional) Dict of parameters (if any) accepted the by Twitter API endpoint you are trying to @@ -281,6 +281,10 @@ class Twython(EndpointsMixin, object): """Shortcut for POST requests via :class:`request`""" return self.request(endpoint, 'POST', params=params, version=version, json_encoded=json_encoded) + def delete(self, endpoint, params=None, version='1.1', json_encoded=False): + """Shortcut for delete requests via :class:`request`""" + return self.request(endpoint, 'DELETE', params=params, version=version, json_encoded=json_encoded) + def get_lastfunction_header(self, header, default_return_value=None): """Returns a specific header from the last API call This will return None if the header is not present From 96dd5b289792fff6b5f438471bc6b2ed21f62bcc Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Sat, 29 Sep 2018 11:09:39 -0500 Subject: [PATCH 04/27] Added support for delete direct_messages/events/destroy endpoint --- twython/endpoints.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/twython/endpoints.py b/twython/endpoints.py index f7e0a5a..9adf800 100644 --- a/twython/endpoints.py +++ b/twython/endpoints.py @@ -329,10 +329,10 @@ class EndpointsMixin(object): """Destroys the direct message specified in the required ``id`` parameter Docs: - https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/delete-message + https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/delete-message-event """ - return self.post('direct_messages/destroy', params=params) + return self.delete('direct_messages/events/destroy', params=params) def send_direct_message(self, **params): """Sends a new direct message to the specified user from the From 449807a75965a583f139df16d5e30c1e0e814613 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Sun, 30 Sep 2018 10:53:08 -0500 Subject: [PATCH 05/27] Fixed code styling --- twython/api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/twython/api.py b/twython/api.py index 96d1ae7..b0b7287 100644 --- a/twython/api.py +++ b/twython/api.py @@ -141,7 +141,7 @@ class Twython(EndpointsMixin, object): params = params or {} func = getattr(self.client, method) - if isinstance(params, dict) and json_encoded == False: + if isinstance(params, dict) and json_encoded is False: params, files = _transparent_params(params) else: params = params @@ -158,9 +158,9 @@ class Twython(EndpointsMixin, object): else: # Check for json_encoded so we will sent params as "data" or "json" if json_encoded: - data_key = "json" + data_key = 'json' else: - data_key = "data" + data_key = 'data' requests_args.update({ data_key: params, 'files': files, From 4f29fd041b960569e46cdf17e08455d40cfc7f66 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Fri, 16 Nov 2018 05:34:52 -0600 Subject: [PATCH 06/27] Fixed indentation --- twython/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twython/api.py b/twython/api.py index b0b7287..bb10db0 100644 --- a/twython/api.py +++ b/twython/api.py @@ -160,7 +160,7 @@ class Twython(EndpointsMixin, object): if json_encoded: data_key = 'json' else: - data_key = 'data' + data_key = 'data' requests_args.update({ data_key: params, 'files': files, From 02995d7e886fa1b01a1bb0ed0b759d75021835db Mon Sep 17 00:00:00 2001 From: Domenico Nappo Date: Mon, 19 Nov 2018 14:37:31 +0100 Subject: [PATCH 07/27] Adding response.headers to on_error method in twython.streaming.api #503 --- twython/streaming/api.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/twython/streaming/api.py b/twython/streaming/api.py index 0195f38..dd4ae89 100644 --- a/twython/streaming/api.py +++ b/twython/streaming/api.py @@ -125,7 +125,7 @@ class TwythonStreamer(object): self.on_timeout() else: if response.status_code != 200: - self.on_error(response.status_code, response.content) + self.on_error(response.status_code, response.content, response.headers) if self.retry_count and \ (self.retry_count - retry_counter) > 0: @@ -178,7 +178,7 @@ class TwythonStreamer(object): """ return True - def on_error(self, status_code, data): # pragma: no cover + def on_error(self, status_code, data, headers=None): # pragma: no cover """Called when stream returns non-200 status code Feel free to override this to handle your streaming data how you @@ -189,6 +189,9 @@ class TwythonStreamer(object): :param data: Error message sent from stream :type data: dict + + :param headers: Response headers sent from the stream (i.e. Retry-After) + :type headers: dict """ return From 554fba43575e61c46e6e4b583484697fccf4a172 Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Sun, 10 Mar 2019 20:01:14 +0700 Subject: [PATCH 08/27] MANIFEST.in: Add docs, examples and tests Closes https://github.com/ryanmcgrath/twython/issues/507 --- MANIFEST.in | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MANIFEST.in b/MANIFEST.in index eae175a..bcfd314 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,9 @@ include README.rst HISTORY.rst LICENSE requirements.txt + +recursive-include docs * +prune docs/_build + +recursive-include examples *.py + +recursive-include tests *.py +recursive-include tests/tweets *.json From a029433247c4bdd15d56e27f4463a6a8a3ad503f Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Sat, 30 Mar 2019 11:03:51 +0700 Subject: [PATCH 09/27] Add Python 3.7 support Also remove branch restriction in .travis.yml which prevents contributors from seeing builds on their forks. --- .travis.yml | 9 ++++++--- setup.py | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8da6c43..6ec2958 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,12 @@ python: - 2.7 - 3.5 - 3.6 +# Enable 3.7 without globally enabling sudo and dist: xenial for other build jobs +matrix: + include: + - python: 3.7 + dist: xenial + sudo: true env: global: - secure: USjLDneiXlVvEjkUVqTt+LBi0XJ4QhkRcJzqVXA9gEau1NTjAkNTPmHjUbOygp0dkfoV0uWrZKCw6fL1g+HJgWl0vHeHzcNl4mUkA+OwkGFHgaeIhvUfnyyJA8P3Zm21XHC+ehzMpEFN5fVNNhREjnRj+CXMc0FgA6knwBRobu4= @@ -24,9 +30,6 @@ install: script: nosetests -v -w tests/ --logging-filter="twython" --with-cov --cov twython --cov-config .coveragerc --cov-report term-missing notifications: email: false -branches: - only: - - master after_success: - coveralls before_script: diff --git a/setup.py b/setup.py index 11cc2b4..3300b4d 100755 --- a/setup.py +++ b/setup.py @@ -47,5 +47,6 @@ setup( 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', ] ) From d05fe7516e5a3cd09656ccce6f0a7276dff9e0c6 Mon Sep 17 00:00:00 2001 From: AnnaYasenova Date: Tue, 20 Aug 2019 12:38:20 +0300 Subject: [PATCH 10/27] Update compat.py --- twython/compat.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/twython/compat.py b/twython/compat.py index 7c049b0..2ee7d37 100644 --- a/twython/compat.py +++ b/twython/compat.py @@ -9,6 +9,7 @@ Python 3 compatibility. """ import sys +import numpy as np _ver = sys.version_info @@ -29,7 +30,7 @@ if is_py2: str = unicode basestring = basestring - numeric_types = (int, long, float) + numeric_types = (int, long, float, np.int64, np.float64) elif is_py3: @@ -37,4 +38,4 @@ elif is_py3: str = str basestring = (str, bytes) - numeric_types = (int, float) + numeric_types = (int, float, np.int64, np.float64) From 1b085180ff6d9cb4e395551682c5a628545cb70c Mon Sep 17 00:00:00 2001 From: Tim Gates Date: Fri, 28 Feb 2020 05:37:05 +1100 Subject: [PATCH 11/27] Fix simple typo: specifcally -> specifically Closes #526 --- twython/advisory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twython/advisory.py b/twython/advisory.py index 31657ee..9a0863a 100644 --- a/twython/advisory.py +++ b/twython/advisory.py @@ -17,6 +17,6 @@ only TwythonDeprecationWarnings. class TwythonDeprecationWarning(DeprecationWarning): """Custom DeprecationWarning to be raised when methods/variables are being deprecated in Twython. Python 2.7 > ignores DeprecationWarning - so we want to specifcally bubble up ONLY Twython Deprecation Warnings + so we want to specifically bubble up ONLY Twython Deprecation Warnings """ pass From 33fccac46b89262d5f41aee7d2e7a82c0891ae26 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Thu, 2 Apr 2020 22:48:57 -0700 Subject: [PATCH 12/27] Fix this so Pypi publishing works again --- HISTORY.rst | 86 ++++--------- README.md | 163 +++++++++++++++++++++++ README.rst | 222 -------------------------------- examples/get_direct_messages.py | 14 +- examples/get_user_timeline.py | 2 +- setup.py | 5 +- 6 files changed, 193 insertions(+), 299 deletions(-) create mode 100644 README.md delete mode 100644 README.rst diff --git a/HISTORY.rst b/HISTORY.rst index 75964ff..fd2b8ee 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,10 +1,10 @@ -.. :changelog: +# History -History -------- +## 3.8.0 (2020-04-02) +- Bump release with latest patches from GitHub. +- Fix Direct Messages with patches from @manuelcortez. -3.7.0 (2018-07-05) -++++++++++++++++++ +## 3.7.0 (2018-07-05) - Fixes for cursoring API endpoints - Improve `html_for_tweet()` parsing - Documentation cleanup @@ -13,32 +13,27 @@ History - Added `create_metadata` endpoint - Raise error for when cursor is not provided a callable -3.6.0 (2017-23-08) -++++++++++++++++++ +## 3.6.0 (2017-23-08) - Improve replacing of entities with links in `html_for_tweet()` - Update classifiers for PyPI -3.5.0 (2017-06-06) -++++++++++++++++++ +## 3.5.0 (2017-06-06) - Added support for "symbols" in `Twython.html_for_tweet()` - Added support for extended tweets in `Twython.html_for_tweet()` - You can now check progress of video uploads to Twitter when using `Twython.upload_video()` -3.4.0 (2016-30-04) -++++++++++++++++++ +## 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) -++++++++++++++++++ +## 3.3.0 (2015-18-07) - Added support for muting users - Fix typos in documentation - Updated documentation examples - Added dynamic filtering to streamer -3.2.0 (2014-10-30) -++++++++++++++++++ +## 3.2.0 (2014-10-30) - PEP8'd some code - Added `lookup_status` function to `endpoints.py` - Added keyword argument to `cursor` to return full pages rather than individual results @@ -51,23 +46,16 @@ History - Deprecating `update_with_media` per Twitter API 1.1 (https://dev.twitter.com/rest/reference/post/statuses/update_with_media) - Unpin `requests` and `requests-oauthlib` in `requirements.txt` - -3.1.2 (2013-12-05) -++++++++++++++++++ - +## 3.1.2 (2013-12-05) - Fixed Changelog (HISTORY.rst) -3.1.1 (2013-12-05) -++++++++++++++++++ - +## 3.1.1 (2013-12-05) - Update `requests` version to 2.1.0. - Fixed: Streaming issue where `Exceptions` in handlers or `on_success` which subclass `ValueError` would previously be caught and reported as a JSON decoding problem, and `on_error()` would be called (with status_code=200) - Fixed issue where XML was returned when bad tokens were passed to `get_authorized_tokens` - Fixed import for `setup` causing installation to fail on some devices (eg. Nokia N9/MeeGo) -3.1.0 (2013-09-25) -++++++++++++++++++ - +## 3.1.0 (2013-09-25) - Added ``html_for_tweet`` static method. This method accepts a tweet object returned from a Twitter API call and will return a string with urls, mentions and hashtags in the tweet replaced with HTML. - Pass ``client_args`` to the streaming ``__init__``, much like in core Twython (you can pass headers, timeout, hooks, proxies, etc.). - Streamer has new parameter ``handlers`` which accepts a list of strings related to functions that are apart of the Streaming class and start with "on\_". i.e. ['delete'] is passed, when 'delete' is received from a stream response; ``on_delete`` will be called. @@ -79,9 +67,7 @@ History - Fixed streaming issue where results wouldn't be returned for streams that weren't so active (See https://github.com/ryanmcgrath/twython/issues/202#issuecomment-19915708) - Streaming API now uses ``_transparent_params`` so when passed ``True`` or ``False`` or an array, etc. Twython formats it to meet Twitter parameter standards (i.e. ['ryanmcgrath', 'mikehelmick', 'twitterapi'] would convert to string 'ryanmcgrath,mikehelmick,twitterapi') -3.0.0 (2013-06-18) -++++++++++++++++++ - +## 3.0.0 (2013-06-18) - Changed ``twython/twython.py`` to ``twython/api.py`` in attempt to make structure look a little neater - Removed all camelCase function access (anything like ``getHomeTimeline`` is now ``get_home_timeline``) - Removed ``shorten_url``. With the ``requests`` library, shortening a URL on your own is simple enough @@ -100,9 +86,7 @@ History - Added ``invalidate_token`` API method which allows registed apps to revoke an access token presenting its client credentials - ``get_lastfunction_header`` now accepts a ``default_return_value`` parameter. This means that if you pass a second value (ex. ``Twython.get_lastfunction_header('x-rate-limit-remaining', 0)``) and the value is not found, it returns your default value -2.10.1 (2013-05-29) -++++++++++++++++++ - +## 2.10.1 (2013-05-29) - More test coverage! - Fix ``search_gen`` - Fixed ``get_lastfunction_header`` to actually do what its docstring says, returns ``None`` if header is not found @@ -112,9 +96,7 @@ History - No longer raise ``TwythonStreamError`` when stream line can't be decoded. Instead, sends signal to ``TwythonStreamer.on_error`` - Allow for (int, long, float) params to be passed to Twython Twitter API functions in Python 2, and (int, float) in Python 3 -2.10.0 (2013-05-21) -++++++++++++++++++ - +## 2.10.0 (2013-05-21) - Added ``get_retweeters_ids`` method - Fixed ``TwythonDeprecationWarning`` on camelCase functions if the camelCase was the same as the PEP8 function (i.e. ``Twython.retweet`` did not change) - Fixed error message bubbling when error message returned from Twitter was not an array (i.e. if you try to retweet something twice, the error is not found at index 0) @@ -125,20 +107,14 @@ History - Cleaned up ``Twython.construct_api_url``, uses "transparent" parameters (see 4th bullet in this version for explaination) - Update ``requests`` and ``requests-oauthlib`` requirements, fixing posting files AND post data together, making authenticated requests in general in Python 3.3 -2.9.1 (2013-05-04) -++++++++++++++++++ - +## 2.9.1 (2013-05-04) - "PEP8" all the functions. Switch functions from camelCase() to underscore_funcs(). (i.e. ``updateStatus()`` is now ``update_status()``) -2.9.0 (2013-05-04) -++++++++++++++++++ - +## 2.9.0 (2013-05-04) - Fixed streaming issue #144, added ``TwythonStreamer`` to aid users in a friendly streaming experience (streaming examples in ``examples`` and README's have been updated as well) - ``Twython`` now requires ``requests-oauthlib`` 0.3.1, fixes #154 (unable to upload media when sending POST data with the file) -2.8.0 (2013-04-29) -++++++++++++++++++ - +## 2.8.0 (2013-04-29) - Added a ``HISTORY.rst`` to start tracking history of changes - Updated ``twitter_endpoints.py`` to ``endpoints.py`` for cleanliness - Removed twython3k directory, no longer needed @@ -161,36 +137,24 @@ History - Twython now takes ``ssl_verify`` parameter, defaults True. Set False if you're having development server issues - Removed internal ``_media_update`` function, we could have always just used ``self.post`` -2.7.3 (2013-04-12) -++++++++++++++++++ - +## 2.7.3 (2013-04-12) - Fixed issue where Twython Exceptions were not being logged correctly -2.7.2 (2013-04-08) -++++++++++++++++++ - +## 2.7.2 (2013-04-08) - Fixed ``AttributeError`` when trying to decode the JSON response via ``Response.json()`` -2.7.1 (2013-04-08) -++++++++++++++++++ - +## 2.7.1 (2013-04-08) - Removed ``simplejson`` dependency - Fixed ``destroyDirectMessage``, ``createBlock``, ``destroyBlock`` endpoints in ``twitter_endpoints.py`` - Added ``getProfileBannerSizes`` method to ``twitter_endpoints.py`` - Made oauth_verifier argument required in ``get_authorized_tokens`` - Update ``updateProfileBannerImage`` to use v1.1 endpoint -2.7.0 (2013-04-04) -++++++++++++++++++ - +## 2.7.0 (2013-04-04) - New ``showOwnedLists`` method -2.7.0 (2013-03-31) -++++++++++++++++++ - +## 2.7.0 (2013-03-31) - Added missing slash to ``getMentionsTimeline`` in ``twitter_endpoints.py`` -2.6.0 (2013-03-29) -++++++++++++++++++ - +## 2.6.0 (2013-03-29) - Updated ``twitter_endpoints.py`` to better reflect order of API endpoints on the Twitter API v1.1 docs site diff --git a/README.md b/README.md new file mode 100644 index 0000000..fe0aa1b --- /dev/null +++ b/README.md @@ -0,0 +1,163 @@ +# Twython + + + + + + +`Twython` is a Python library providing an easy way to access Twitter data. Supports Python 3. It's been battle tested by companies, educational institutions and individuals alike. Try it today! + +**Note**: As of Twython 3.7.0, there's a general call for maintainers put out. If you find the project useful and want to help out, reach out to Ryan with the info from the bottom of this README. Great open source project to get your feet wet with! + +## Features +- Query data for: + - User information + - Twitter lists + - Timelines + - Direct Messages + - and anything found in [the docs](https://developer.twitter.com/en/docs) +- Image Uploading: + - Update user status with an image + - Change user avatar + - Change user background image + - Change user banner image +- OAuth 2 Application Only (read-only) Support +- Support for Twitter's Streaming API +- Seamless Python 3 support! + +## Installation +Install Twython via pip: + +```bash +$ pip install twython +``` + +Or, if you want the code that is currently on GitHub + +```bash +git clone git://github.com/ryanmcgrath/twython.git +cd twython +python setup.py install +``` + +## Documentation +Documentation is available at https://twython.readthedocs.io/en/latest/ + +## Starting Out +First, you'll want to head over to https://apps.twitter.com and register an application! + +After you register, grab your applications `Consumer Key` and `Consumer Secret` from the application details tab. + +The most common type of authentication is Twitter user authentication using OAuth 1. If you're a web app planning to have users sign up with their Twitter account and interact with their timelines, updating their status, and stuff like that this **is** the authentication for you! + +First, you'll want to import Twython + +```python +from twython import Twython +``` + +## Obtain Authorization URL +Now, you'll want to create a Twython instance with your `Consumer Key` and `Consumer Secret`: + +- Only pass *callback_url* to *get_authentication_tokens* if your application is a Web Application +- Desktop and Mobile Applications **do not** require a callback_url + +```python +APP_KEY = 'YOUR_APP_KEY' +APP_SECRET = 'YOUR_APP_SECRET' + +twitter = Twython(APP_KEY, APP_SECRET) + +auth = twitter.get_authentication_tokens(callback_url='http://mysite.com/callback') +``` + +From the `auth` variable, save the `oauth_token` and `oauth_token_secret` for later use (these are not the final auth tokens). In Django or other web frameworks, you might want to store it to a session variable + +```python +OAUTH_TOKEN = auth['oauth_token'] +OAUTH_TOKEN_SECRET = auth['oauth_token_secret'] +``` + +Send the user to the authentication url, you can obtain it by accessing + +```python +auth['auth_url'] +``` + +## Handling the Callback +If your application is a Desktop or Mobile Application *oauth_verifier* will be the PIN code + +After they authorize your application to access some of their account details, they'll be redirected to the callback url you specified in `get_authentication_tokens`. + +You'll want to extract the `oauth_verifier` from the url. + +Django example: + +```python +oauth_verifier = request.GET['oauth_verifier'] +``` + +Now that you have the `oauth_verifier` stored to a variable, you'll want to create a new instance of Twython and grab the final user tokens + +```python +twitter = Twython( + APP_KEY, APP_SECRET, + OAUTH_TOKEN, OAUTH_TOKEN_SECRET +) + +final_step = twitter.get_authorized_tokens(oauth_verifier) +``` + +Once you have the final user tokens, store them in a database for later use:: + +```python + 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.io/en/latest/usage/starting_out.html#oauth-2-application-authentication). + +## Dynamic Function Arguments +Keyword arguments to functions are mapped to the functions available for each endpoint in the Twitter API docs. 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. + +Basic Usage +----------- + +**Function definitions (i.e. get_home_timeline()) can be found by reading over twython/endpoints.py** + +Create a Twython instance with your application keys and the users OAuth tokens + +```python +from twython import Twython +twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) +``` + +## Authenticated Users Home Timeline +```python +twitter.get_home_timeline() +``` + +## Updating Status +This method makes use of dynamic arguments, [read more about them](https://twython.readthedocs.io/en/latest/usage/starting_out.html#dynamic-function-arguments). + +```python +twitter.update_status(status='See how easy using Twython is!') +``` + +## Advanced Usage +- [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) + + +## 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. + +Or if I'm to busy to answer, feel free to ping mikeh@ydekproductions.com as well. + +Follow us on Twitter: + +- [@ryanmcgrath](https://twitter.com/ryanmcgrath) +- [@mikehelmick](https://twitter.com/mikehelmick) + +## Want to help? +Twython is useful, but ultimately only as useful as the people using it (say that ten times fast!). If you'd like to help, write example code, contribute patches, document things on the wiki, tweet about it. Your help is always appreciated! diff --git a/README.rst b/README.rst deleted file mode 100644 index edddacc..0000000 --- a/README.rst +++ /dev/null @@ -1,222 +0,0 @@ -Twython -======= - - -.. image:: https://img.shields.io/pypi/v/twython.svg?style=flat-square - :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 - -.. image:: https://img.shields.io/travis/ryanmcgrath/twython.svg?style=flat-square - :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 - -``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! - -Features --------- - -- Query data for: - - User information - - Twitter lists - - Timelines - - Direct Messages - - and anything found in `the docs `_ -- Image Uploading: - - Update user status with an image - - Change user avatar - - Change user background image - - Change user banner image -- OAuth 2 Application Only (read-only) Support -- Support for Twitter's Streaming API -- Seamless Python 3 support! - -Installation ------------- - -Install Twython via `pip `_ - -.. code-block:: bash - - $ pip install twython - -or, with `easy_install `_ - -.. code-block:: bash - - $ easy_install twython - -But, hey... `that's up to you `_. - -Or, if you want the code that is currently on GitHub - -.. code-block:: bash - - git clone git://github.com/ryanmcgrath/twython.git - cd twython - python setup.py install - -Documentation -------------- - -Documentation is available at https://twython.readthedocs.io/en/latest/ - -Starting Out ------------- - -First, you'll want to head over to https://apps.twitter.com and register an application! - -After you register, grab your applications ``Consumer Key`` and ``Consumer Secret`` from the application details tab. - -The most common type of authentication is Twitter user authentication using OAuth 1. If you're a web app planning to have users sign up with their Twitter account and interact with their timelines, updating their status, and stuff like that this **is** the authentication for you! - -First, you'll want to import Twython - -.. code-block:: python - - from twython import Twython - -Authentication -~~~~~~~~~~~~~~ - -Obtain Authorization URL -^^^^^^^^^^^^^^^^^^^^^^^^ - -Now, you'll want to create a Twython instance with your ``Consumer Key`` and ``Consumer Secret`` - - Only pass *callback_url* to *get_authentication_tokens* if your application is a Web Application - - Desktop and Mobile Applications **do not** require a callback_url - -.. code-block:: python - - APP_KEY = 'YOUR_APP_KEY' - APP_SECRET = 'YOUR_APP_SECRET' - - twitter = Twython(APP_KEY, APP_SECRET) - - auth = twitter.get_authentication_tokens(callback_url='http://mysite.com/callback') - -From the ``auth`` variable, save the ``oauth_token`` and ``oauth_token_secret`` for later use (these are not the final auth tokens). In Django or other web frameworks, you might want to store it to a session variable - -.. code-block:: python - - OAUTH_TOKEN = auth['oauth_token'] - OAUTH_TOKEN_SECRET = auth['oauth_token_secret'] - -Send the user to the authentication url, you can obtain it by accessing - -.. code-block:: python - - auth['auth_url'] - -Handling the Callback -^^^^^^^^^^^^^^^^^^^^^ - - If your application is a Desktop or Mobile Application *oauth_verifier* will be the PIN code - -After they authorize your application to access some of their account details, they'll be redirected to the callback url you specified in ``get_authentication_tokens`` - -You'll want to extract the ``oauth_verifier`` from the url. - -Django example: - -.. code-block:: python - - oauth_verifier = request.GET['oauth_verifier'] - -Now that you have the ``oauth_verifier`` stored to a variable, you'll want to create a new instance of Twython and grab the final user tokens - -.. code-block:: python - - twitter = Twython(APP_KEY, APP_SECRET, - OAUTH_TOKEN, OAUTH_TOKEN_SECRET) - - final_step = twitter.get_authorized_tokens(oauth_verifier) - -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 `_ - -Dynamic Function Arguments -~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Keyword arguments to functions are mapped to the functions available for each endpoint in the Twitter API docs. 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. - -Basic Usage ------------ - -**Function definitions (i.e. get_home_timeline()) can be found by reading over twython/endpoints.py** - -Create a Twython instance with your application keys and the users OAuth tokens - -.. code-block:: python - - from twython import Twython - twitter = Twython(APP_KEY, APP_SECRET, - OAUTH_TOKEN, OAUTH_TOKEN_SECRET) - -Authenticated Users Home Timeline -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Documentation: https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-home_timeline - -.. code-block:: python - - twitter.get_home_timeline() - -Updating Status -~~~~~~~~~~~~~~~ - -This method makes use of dynamic arguments, `read more about them `_ - -Documentation: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update - -.. code-block:: python - - twitter.update_status(status='See how easy using Twython is!') - -Searching -~~~~~~~~~ - - https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets says it takes "q" and "result_type" amongst other arguments - -.. code-block:: python - - twitter.search(q='twitter') - twitter.search(q='twitter', result_type='popular') - -Advanced Usage --------------- - -- `Advanced Twython Usage `_ -- `Streaming with Twython `_ - - -Notes ------ - -- Twython 3.0.0 has been injected with 1000mgs of pure awesomeness! OAuth 2 application authentication is now supported. And a *whole lot* more! See the `CHANGELOG `_ for more details! - -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. - -Or if I'm to busy to answer, feel free to ping mikeh@ydekproductions.com as well. - -Follow us on Twitter: - -- `@ryanmcgrath `_ -- `@mikehelmick `_ - -Want to help? -------------- - -Twython is useful, but ultimately only as useful as the people using it (say that ten times fast!). If you'd like to help, write example code, contribute patches, document things on the wiki, tweet about it. Your help is always appreciated! diff --git a/examples/get_direct_messages.py b/examples/get_direct_messages.py index 5a27a06..fa80865 100644 --- a/examples/get_direct_messages.py +++ b/examples/get_direct_messages.py @@ -1,17 +1,5 @@ from twython import Twython, TwythonError twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) - get_list = twitter.get_direct_messages() -#Returns All Twitter DM information which is a lot in a list format - -dm_dict = get_list[0] -#Sets get_list to a dictionary, the number in the list is the direct message retrieved -#That means that 0 is the most recent and n-1 is the last DM revieved. -#You can cycle through all the numbers and it will return the text and the sender id of each - -print dm_dict['text'] -#Gets the text from the dictionary - -print dm_dict['sender']['id'] -#Gets the ID of the sender +print(get_list) diff --git a/examples/get_user_timeline.py b/examples/get_user_timeline.py index 0a1f4df..55ab427 100644 --- a/examples/get_user_timeline.py +++ b/examples/get_user_timeline.py @@ -7,4 +7,4 @@ try: except TwythonError as e: print e -print user_timeline +print(user_timeline) diff --git a/setup.py b/setup.py index 11cc2b4..0531221 100755 --- a/setup.py +++ b/setup.py @@ -31,8 +31,9 @@ setup( keywords='twitter search api tweet twython stream', description='Actively maintained, pure Python wrapper for the \ Twitter API. Supports both normal and streaming Twitter APIs', - long_description=open('README.rst').read() + '\n\n' + - open('HISTORY.rst').read(), + long_description=open('README.md').read() + '\n\n' + + open('HISTORY.md').read(), + long_description_content_type='text/markdown', include_package_data=True, packages=packages, classifiers=[ From 7ce058e6fd3a7307e4ac88e855257a9e99cc7163 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Thu, 2 Apr 2020 22:58:15 -0700 Subject: [PATCH 13/27] Resolve issues with Pypi publishing (RST -> MD) and bump to 3.8.0 --- HISTORY.rst => HISTORY.md | 0 setup.py | 12 +++++------- 2 files changed, 5 insertions(+), 7 deletions(-) rename HISTORY.rst => HISTORY.md (100%) diff --git a/HISTORY.rst b/HISTORY.md similarity index 100% rename from HISTORY.rst rename to HISTORY.md diff --git a/setup.py b/setup.py index 0531221..0c0e758 100755 --- a/setup.py +++ b/setup.py @@ -8,8 +8,8 @@ try: except ImportError: from distutils.core import setup -__author__ = 'Ryan McGrath ' -__version__ = '3.7.0' +__author__ = 'Ryan McGrath ' +__version__ = '3.8.0' packages = [ 'twython', @@ -26,13 +26,11 @@ setup( install_requires=['requests>=2.1.0', 'requests_oauthlib>=0.4.0'], author='Ryan McGrath', author_email='ryan@venodesigns.net', - license=open('LICENSE').read(), + license='MIT', url='https://github.com/ryanmcgrath/twython/tree/master', keywords='twitter search api tweet twython stream', - description='Actively maintained, pure Python wrapper for the \ - Twitter API. Supports both normal and streaming Twitter APIs', - long_description=open('README.md').read() + '\n\n' + - open('HISTORY.md').read(), + description='Actively maintained, pure Python wrapper for the Twitter API. Supports both normal and streaming Twitter APIs', + long_description=open('README.md', encoding='utf-8').read() + '\n\n' +open('HISTORY.md', encoding='utf-8').read(), long_description_content_type='text/markdown', include_package_data=True, packages=packages, From ea2979c75f8f771a70617e607b8398809dba8dac Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Thu, 2 Apr 2020 23:02:01 -0700 Subject: [PATCH 14/27] Remove this merge as numpy shouldn't be a dependency --- twython/compat.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/twython/compat.py b/twython/compat.py index 2ee7d37..7c049b0 100644 --- a/twython/compat.py +++ b/twython/compat.py @@ -9,7 +9,6 @@ Python 3 compatibility. """ import sys -import numpy as np _ver = sys.version_info @@ -30,7 +29,7 @@ if is_py2: str = unicode basestring = basestring - numeric_types = (int, long, float, np.int64, np.float64) + numeric_types = (int, long, float) elif is_py3: @@ -38,4 +37,4 @@ elif is_py3: str = str basestring = (str, bytes) - numeric_types = (int, float, np.int64, np.float64) + numeric_types = (int, float) From b8d927df8eeff88717f3b7547461b637de87caf7 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Thu, 2 Apr 2020 23:08:52 -0700 Subject: [PATCH 15/27] Kill 2.6/2.7 --- .travis.yml | 3 --- tests/config.py | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6ec2958..231b15c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: python python: - - 2.6 - - 2.7 - 3.5 - 3.6 # Enable 3.7 without globally enabling sudo and dist: xenial for other build jobs @@ -26,7 +24,6 @@ env: - ACCESS_TOKEN_B64=U2FsdGVkX18QdBhvMNshM4PGy04tU3HLwKP+nNSoNZHKsvGLjELcWEXN2LIu/T+yngX1vGONf9lo14ElnfS4k7sfhiru8phR4+rZuBVP3bDvC2A6fXJuhuLqNhBrWqg32WQewvxLWDWBoKmnvRHg5b74GHh+IN/12tU0cBF2HK8= install: - pip install -r requirements.txt - - if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install unittest2; fi script: nosetests -v -w tests/ --logging-filter="twython" --with-cov --cov twython --cov-config .coveragerc --cov-report term-missing notifications: email: false diff --git a/tests/config.py b/tests/config.py index 8812b81..10ab3ea 100644 --- a/tests/config.py +++ b/tests/config.py @@ -2,10 +2,7 @@ import os import sys -if sys.version_info[0] == 2 and sys.version_info[1] == 6: - import unittest2 as unittest -else: - import unittest +import unittest app_key = os.environ.get('APP_KEY') app_secret = os.environ.get('APP_SECRET') From cbfec150dfffb63abae8c0e6edd137d02a0fe417 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Thu, 2 Apr 2020 23:28:35 -0700 Subject: [PATCH 16/27] Close #486 - given how long ago this was deprecated I'll assume it's not even used --- twython/streaming/types.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/twython/streaming/types.py b/twython/streaming/types.py index 81c5c07..27c9ea8 100644 --- a/twython/streaming/types.py +++ b/twython/streaming/types.py @@ -20,26 +20,6 @@ class TwythonStreamerTypes(object): self.streamer = streamer self.statuses = TwythonStreamerTypesStatuses(streamer) - def user(self, **params): - """Stream user - - Accepted params found at: - https://dev.twitter.com/docs/api/1.1/get/user - """ - url = 'https://userstream.twitter.com/%s/user.json' \ - % self.streamer.api_version - self.streamer._request(url, params=params) - - def site(self, **params): - """Stream site - - Accepted params found at: - https://dev.twitter.com/docs/api/1.1/get/site - """ - url = 'https://sitestream.twitter.com/%s/site.json' \ - % self.streamer.api_version - self.streamer._request(url, params=params) - class TwythonStreamerTypesStatuses(object): """Class for different statuses endpoints From 74c72f88fddf2623e23601785d8a80c1152989eb Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Thu, 2 Apr 2020 23:39:07 -0700 Subject: [PATCH 17/27] Remove old links in docs --- docs/_themes/basicstrap/customsidebar.html | 15 +-------------- docs/conf.py | 4 ++-- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/docs/_themes/basicstrap/customsidebar.html b/docs/_themes/basicstrap/customsidebar.html index ac8c583..dbeab99 100644 --- a/docs/_themes/basicstrap/customsidebar.html +++ b/docs/_themes/basicstrap/customsidebar.html @@ -1,18 +1,5 @@ -

{{ _('Donate') }}

- -

-Find Twython useful? Consider supporting the author on Gittip: -

- -

- -

-

{{ _('Links') }}

\ No newline at end of file + diff --git a/docs/conf.py b/docs/conf.py index 8f3c3d2..3ffa5b5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -50,9 +50,9 @@ copyright = u'2013, Ryan McGrath' # built documents. # # The short X.Y version. -version = '3.7.0' +version = '3.8.0' # The full version, including alpha/beta/rc tags. -release = '3.7.0' +release = '3.8.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. From ba1110d4b8c6c385bf59fe5318b4aa4726ca00f7 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Fri, 3 Apr 2020 02:22:17 -0700 Subject: [PATCH 18/27] Update Manifest to fix installation --- MANIFEST.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index bcfd314..79f570a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include README.rst HISTORY.rst LICENSE requirements.txt +include README.md HISTORY.md LICENSE requirements.txt recursive-include docs * prune docs/_build From e6b5364d28ba3e7f3688bcdbdb8441e2d33d3ecf Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Fri, 3 Apr 2020 02:22:33 -0700 Subject: [PATCH 19/27] Bump version for patching manifest --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index bff13d7..ff6dee8 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ except ImportError: from distutils.core import setup __author__ = 'Ryan McGrath ' -__version__ = '3.8.0' +__version__ = '3.8.1' packages = [ 'twython', From 02fb35651dd253254ff22c51c591d1bd0c9cf807 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Sat, 4 Apr 2020 16:21:59 -0700 Subject: [PATCH 20/27] Fixes #530, bump version to 3.8.2 --- setup.py | 2 +- twython/streaming/api.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.py b/setup.py index ff6dee8..3742f24 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ except ImportError: from distutils.core import setup __author__ = 'Ryan McGrath ' -__version__ = '3.8.1' +__version__ = '3.8.2' packages = [ 'twython', diff --git a/twython/streaming/api.py b/twython/streaming/api.py index dd4ae89..6073abb 100644 --- a/twython/streaming/api.py +++ b/twython/streaming/api.py @@ -86,8 +86,6 @@ class TwythonStreamer(object): # Set up type methods StreamTypes = TwythonStreamerTypes(self) self.statuses = StreamTypes.statuses - self.user = StreamTypes.user - self.site = StreamTypes.site self.connected = False From 233b20a71057c98cba6f745ecfeada47c76bb67d Mon Sep 17 00:00:00 2001 From: Karthikeyan Singaravelan Date: Sun, 12 Apr 2020 05:25:01 +0000 Subject: [PATCH 21/27] Fix deprecation warning regarding invalid escape sequences. --- twython/api.py | 4 ++-- twython/streaming/types.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/twython/api.py b/twython/api.py index bb10db0..76b6f28 100644 --- a/twython/api.py +++ b/twython/api.py @@ -430,7 +430,7 @@ class Twython(EndpointsMixin, object): @staticmethod def construct_api_url(api_url, **params): - """Construct a Twitter API url, encoded, with parameters + r"""Construct a Twitter API url, encoded, with parameters :param api_url: URL of the Twitter API endpoint you are attempting to construct @@ -469,7 +469,7 @@ class Twython(EndpointsMixin, object): return self.cursor(self.search, q=search_query, **params) def cursor(self, function, return_pages=False, **params): - """Returns a generator for results that match a specified query. + r"""Returns a generator for results that match a specified query. :param function: Instance of a Twython function (Twython.get_home_timeline, Twython.search) diff --git a/twython/streaming/types.py b/twython/streaming/types.py index 27c9ea8..5042d29 100644 --- a/twython/streaming/types.py +++ b/twython/streaming/types.py @@ -35,7 +35,7 @@ class TwythonStreamerTypesStatuses(object): self.params = None def filter(self, **params): - """Stream statuses/filter + r"""Stream statuses/filter :param \*\*params: Parameters to send with your stream request @@ -47,7 +47,7 @@ class TwythonStreamerTypesStatuses(object): self.streamer._request(url, 'POST', params=params) def sample(self, **params): - """Stream statuses/sample + r"""Stream statuses/sample :param \*\*params: Parameters to send with your stream request @@ -59,7 +59,7 @@ class TwythonStreamerTypesStatuses(object): self.streamer._request(url, params=params) def firehose(self, **params): - """Stream statuses/firehose + r"""Stream statuses/firehose :param \*\*params: Parameters to send with your stream request @@ -71,7 +71,7 @@ class TwythonStreamerTypesStatuses(object): self.streamer._request(url, params=params) def set_dynamic_filter(self, **params): - """Set/update statuses/filter + r"""Set/update statuses/filter :param \*\*params: Parameters to send with your stream request From 33f46c087ec6c92dd325101169f3c5c0894d3b7c Mon Sep 17 00:00:00 2001 From: Hannes Date: Fri, 17 Jul 2020 11:50:06 +0200 Subject: [PATCH 22/27] update example for a post involving image editing Python 2 support was dropped from Twython, thanks! In Python3 we actually have to use BytesIO, see https://github.com/python-pillow/Pillow/issues/2205 --- docs/usage/advanced_usage.rst | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/docs/usage/advanced_usage.rst b/docs/usage/advanced_usage.rst index bdb0b23..df3bc48 100644 --- a/docs/usage/advanced_usage.rst +++ b/docs/usage/advanced_usage.rst @@ -59,15 +59,10 @@ with a status update. .. code-block:: python - # Assume you are working with a JPEG + # Assuming that you are working with a JPEG from PIL import Image - try: - # Python 3 - from io import StringIO - except ImportError: - # Python 2 - from StringIO import StringIO + from io import BytesIO photo = Image.open('/path/to/file/image.jpg') @@ -76,14 +71,13 @@ with a status update. height = int((float(photo.size[1]) * float(wpercent))) photo = photo.resize((basewidth, height), Image.ANTIALIAS) - image_io = StringIO.StringIO() + image_io = BytesIO() photo.save(image_io, format='JPEG') # If you do not seek(0), the image will be at the end of the file and # unable to be read image_io.seek(0) - response = twitter.upload_media(media=image_io) twitter.update_status(status='Checkout this cool image!', media_ids=[response['media_id']]) From 1a54c15a71d054c6421e29cbcefcb9f2186cad49 Mon Sep 17 00:00:00 2001 From: Erik Zscheile Date: Tue, 26 Jan 2021 22:19:13 +0100 Subject: [PATCH 23/27] PEP 479: Change StopIteration handling inside generators --- twython/api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/twython/api.py b/twython/api.py index bb10db0..bd49c49 100644 --- a/twython/api.py +++ b/twython/api.py @@ -501,7 +501,7 @@ class Twython(EndpointsMixin, object): content = function(**params) if not content: - raise StopIteration + return if hasattr(function, 'iter_key'): results = content.get(function.iter_key) @@ -516,7 +516,7 @@ class Twython(EndpointsMixin, object): if function.iter_mode == 'cursor' and \ content['next_cursor_str'] == '0': - raise StopIteration + return try: if function.iter_mode == 'id': @@ -529,7 +529,7 @@ class Twython(EndpointsMixin, object): params = dict(parse_qsl(next_results.query)) else: # No more results - raise StopIteration + return else: # Twitter gives tweets in reverse chronological order: params['max_id'] = str(int(content[-1]['id_str']) - 1) From 61c1ba9600986d8263af81b8cee954828bb7ce7c Mon Sep 17 00:00:00 2001 From: Erik Zscheile Date: Tue, 26 Jan 2021 22:22:56 +0100 Subject: [PATCH 24/27] PEP 479: add appropriate __future__ tag --- twython/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/twython/api.py b/twython/api.py index bd49c49..5de6c67 100644 --- a/twython/api.py +++ b/twython/api.py @@ -9,6 +9,7 @@ Twitter Authentication, and miscellaneous methods that are useful when dealing with the Twitter API """ +from __future__ import generator_stop import warnings import re From 0b6f372620e864055f9c141c5d72b85a93230d50 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Sat, 6 Feb 2021 17:47:42 -0500 Subject: [PATCH 25/27] Update metadata to describe present support and CI testing --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 3742f24..39a8e5f 100755 --- a/setup.py +++ b/setup.py @@ -24,6 +24,7 @@ setup( name='twython', version=__version__, install_requires=['requests>=2.1.0', 'requests_oauthlib>=0.4.0'], + python_requires='>=3.5', author='Ryan McGrath', author_email='ryan@venodesigns.net', license='MIT', @@ -41,9 +42,8 @@ setup( 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Communications :: Chat', 'Topic :: Internet', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3 :: Only', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', From 4be4a504a30ad5e1b2ade398582e6a09e7d97759 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Fri, 16 Jul 2021 14:32:48 -0700 Subject: [PATCH 26/27] Push 3.9.0 --- setup.py | 4 ++-- twython/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 3742f24..307ad8b 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ except ImportError: from distutils.core import setup __author__ = 'Ryan McGrath ' -__version__ = '3.8.2' +__version__ = '3.9.0' packages = [ 'twython', @@ -25,7 +25,7 @@ setup( version=__version__, install_requires=['requests>=2.1.0', 'requests_oauthlib>=0.4.0'], author='Ryan McGrath', - author_email='ryan@venodesigns.net', + author_email='ryan@rymc.io', license='MIT', url='https://github.com/ryanmcgrath/twython/tree/master', keywords='twitter search api tweet twython stream', diff --git a/twython/__init__.py b/twython/__init__.py index dc161d1..e01d85d 100644 --- a/twython/__init__.py +++ b/twython/__init__.py @@ -19,7 +19,7 @@ Questions, comments? ryan@venodesigns.net """ __author__ = 'Ryan McGrath ' -__version__ = '3.7.0' +__version__ = '3.9.0' from .api import Twython from .streaming import TwythonStreamer From 0c405604285364457f3c309969f11ba68163bd05 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Fri, 16 Jul 2021 15:33:17 -0700 Subject: [PATCH 27/27] 3.9.1 --- README.md | 8 +++++++- setup.py | 2 +- twython/__init__.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fe0aa1b..853136e 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,13 @@ Install Twython via pip: $ pip install twython ``` -Or, if you want the code that is currently on GitHub +If you're on a legacy project that needs Python 2.7 support, you can install the last version of Twython that supported 2.7: + +``` +pip install twython==3.7.0` +``` + +Or, if you want the code that is currently on GitHub: ```bash git clone git://github.com/ryanmcgrath/twython.git diff --git a/setup.py b/setup.py index 4c0cc12..a3600de 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ except ImportError: from distutils.core import setup __author__ = 'Ryan McGrath ' -__version__ = '3.9.0' +__version__ = '3.9.1' packages = [ 'twython', diff --git a/twython/__init__.py b/twython/__init__.py index e01d85d..7d25ef3 100644 --- a/twython/__init__.py +++ b/twython/__init__.py @@ -19,7 +19,7 @@ Questions, comments? ryan@venodesigns.net """ __author__ = 'Ryan McGrath ' -__version__ = '3.9.0' +__version__ = '3.9.1' from .api import Twython from .streaming import TwythonStreamer