diff options
-rw-r--r-- | README.rst | 2 | ||||
-rw-r--r-- | docs/index.rst | 2 | ||||
-rw-r--r-- | mastodon/Mastodon.py | 27 |
3 files changed, 28 insertions, 3 deletions
@@ -35,7 +35,7 @@ Mastodon.py | |||
35 | mastodon.toot('Tooting from python using #mastodonpy !') | 35 | mastodon.toot('Tooting from python using #mastodonpy !') |
36 | 36 | ||
37 | Python wrapper for the Mastodon ( https://github.com/tootsuite/mastodon/ ) API. | 37 | Python wrapper for the Mastodon ( https://github.com/tootsuite/mastodon/ ) API. |
38 | Feature complete for public API as of version v1.6 and easy to get started with. | 38 | Feature complete for public API as of version v2.0 and easy to get started with. |
39 | 39 | ||
40 | You can install Mastodon.py via pypi: | 40 | You can install Mastodon.py via pypi: |
41 | 41 | ||
diff --git a/docs/index.rst b/docs/index.rst index fae8b2d..34b7b38 100644 --- a/docs/index.rst +++ b/docs/index.rst | |||
@@ -46,7 +46,7 @@ node running Mastodon by setting api_base_url when creating the | |||
46 | api object (or creating an app). | 46 | api object (or creating an app). |
47 | 47 | ||
48 | Mastodon.py aims to implement the complete public Mastodon API. As | 48 | Mastodon.py aims to implement the complete public Mastodon API. As |
49 | of this time, it is feature complete for Mastodon version 1.6. | 49 | of this time, it is feature complete for Mastodon version 2.0. |
50 | 50 | ||
51 | A note about rate limits | 51 | A note about rate limits |
52 | ------------------------ | 52 | ------------------------ |
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 8c2bf8c..d57fb91 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -16,6 +16,7 @@ import dateutil.parser | |||
16 | import re | 16 | import re |
17 | import copy | 17 | import copy |
18 | import threading | 18 | import threading |
19 | import sys | ||
19 | try: | 20 | try: |
20 | from urllib.parse import urlparse | 21 | from urllib.parse import urlparse |
21 | except ImportError: | 22 | except ImportError: |
@@ -971,6 +972,7 @@ class Mastodon: | |||
971 | 972 | ||
972 | return (date_time_utc - epoch_utc).total_seconds() | 973 | return (date_time_utc - epoch_utc).total_seconds() |
973 | 974 | ||
975 | |||
974 | def __json_date_parse(self, json_object): | 976 | def __json_date_parse(self, json_object): |
975 | """ | 977 | """ |
976 | Parse dates in certain known json fields, if possible. | 978 | Parse dates in certain known json fields, if possible. |
@@ -987,6 +989,29 @@ class Mastodon: | |||
987 | raise MastodonAPIError('Encountered invalid date.') | 989 | raise MastodonAPIError('Encountered invalid date.') |
988 | return json_object | 990 | return json_object |
989 | 991 | ||
992 | def __json_id_to_bignum(self, json_object): | ||
993 | """ | ||
994 | Converts json string IDs to native python bignums. | ||
995 | """ | ||
996 | if sys.version_info.major >= 3: | ||
997 | str_type = str | ||
998 | else: | ||
999 | str_type = unicode | ||
1000 | |||
1001 | if ('id' in json_object and | ||
1002 | isinstance(json_object['id'], str_type)): | ||
1003 | try: | ||
1004 | json_object['id'] = int(json_object['id']) | ||
1005 | except ValueError: | ||
1006 | pass | ||
1007 | |||
1008 | return json_object | ||
1009 | |||
1010 | def __json_hooks(self, json_object): | ||
1011 | json_object = self.__json_date_parse(json_object) | ||
1012 | json_object = self.__json_id_to_bignum(json_object) | ||
1013 | return json_object | ||
1014 | |||
990 | def __api_request(self, method, endpoint, params={}, files={}, do_ratelimiting=True): | 1015 | def __api_request(self, method, endpoint, params={}, files={}, do_ratelimiting=True): |
991 | """ | 1016 | """ |
992 | Internal API request helper. | 1017 | Internal API request helper. |
@@ -1105,7 +1130,7 @@ class Mastodon: | |||
1105 | continue | 1130 | continue |
1106 | 1131 | ||
1107 | try: | 1132 | try: |
1108 | response = response_object.json(object_hook=self.__json_date_parse) | 1133 | response = response_object.json(object_hook=self.__json_hooks) |
1109 | except: | 1134 | except: |
1110 | raise MastodonAPIError( | 1135 | raise MastodonAPIError( |
1111 | "Could not parse response as JSON, response code was %s, " | 1136 | "Could not parse response as JSON, response code was %s, " |