aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2018-01-29 14:14:58 +0100
committerLorenz Diener <[email protected]>2018-01-29 14:14:58 +0100
commit569a13ee80304f4d9ef94cc4a116db78a9cb7583 (patch)
tree85cfec0ca945e54f833d6aa44e144bbcd1d9d211
parent838b85133106ff5ef918cbe01e67f26b5655d3bc (diff)
downloadmastodon.py-569a13ee80304f4d9ef94cc4a116db78a9cb7583.tar.gz
Add 2.1.2 functions
-rw-r--r--docs/index.rst19
-rw-r--r--mastodon/Mastodon.py39
2 files changed, 48 insertions, 10 deletions
diff --git a/docs/index.rst b/docs/index.rst
index 4e79032..2a64a02 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -454,6 +454,21 @@ Instance dicts
454 # stream websocket address. 454 # stream websocket address.
455 } 455 }
456 456
457Activity dicts
458~~~~~~~~~~~~~~
459.. _activity dict:
460
461.. code-block:: python
462
463 mastodon.instance_activity()[0]
464 # Returns the following dictionary
465 {
466 'week': # Date of the first day of the week the stats were collected for
467 'logins': # Number of users that logged in that week
468 'registrations': # Number of new users that week
469 'statuses': # Number of statuses posted that week
470 }
471
457Report dicts 472Report dicts
458~~~~~~~~~~~~ 473~~~~~~~~~~~~
459.. _report dict: 474.. _report dict:
@@ -517,10 +532,12 @@ version or explicitly determine if a specific minimum Version is available.
517 532
518Reading data: Instances 533Reading data: Instances
519----------------------- 534-----------------------
520This function allows you to fetch information associated with the 535These functions allow you to fetch information associated with the
521current instance. 536current instance.
522 537
523.. automethod:: Mastodon.instance 538.. automethod:: Mastodon.instance
539.. automethod:: Mastodon.instance_activity
540.. automethod:: Mastodon.instance_peers
524 541
525Reading data: Timelines 542Reading data: Timelines
526----------------------- 543-----------------------
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 0329c10..80960b9 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -89,7 +89,7 @@ class Mastodon:
89 """ 89 """
90 __DEFAULT_BASE_URL = 'https://mastodon.social' 90 __DEFAULT_BASE_URL = 'https://mastodon.social'
91 __DEFAULT_TIMEOUT = 300 91 __DEFAULT_TIMEOUT = 300
92 __SUPPORTED_MASTODON_VERSION = "2.1.0" 92 __SUPPORTED_MASTODON_VERSION = "2.1.2"
93 93
94 ### 94 ###
95 # Registering apps 95 # Registering apps
@@ -360,7 +360,29 @@ class Mastodon:
360 """ 360 """
361 Internal, non-version-checking helper that does the same as instance() 361 Internal, non-version-checking helper that does the same as instance()
362 """ 362 """
363 return self.__api_request('GET', '/api/v1/instance/') 363 return self.__api_request('GET', '/api/v1/instance')
364
365 @api_version("2.1.2", "2.1.2")
366 def instance_activity(self):
367 """
368 Retrieve activity stats about the instance. May be disabled by the instance administrator - throws
369 a MastodonNotFoundError in that case.
370
371 Activity is returned for 12 weeks going back from the current week.
372
373 Returns a list `activity dicts`_.
374 """
375 return self.__api_request('GET', '/api/v1/instance/activity')
376
377 @api_version("2.1.2", "2.1.2")
378 def instance_peers(self):
379 """
380 Retrieve the instances that this instance knows about. May be disabled by the instance administrator - throws
381 a MastodonNotFoundError in that case.
382
383 Returns a list of URL strings.
384 """
385 return self.__api_request('GET', '/api/v1/instance/peers')
364 386
365 ### 387 ###
366 # Reading data: Timelines 388 # Reading data: Timelines
@@ -1434,7 +1456,7 @@ class Mastodon:
1434 """ 1456 """
1435 Parse dates in certain known json fields, if possible. 1457 Parse dates in certain known json fields, if possible.
1436 """ 1458 """
1437 known_date_fields = ["created_at"] 1459 known_date_fields = ["created_at", "week"]
1438 for k, v in json_object.items(): 1460 for k, v in json_object.items():
1439 if k in known_date_fields: 1461 if k in known_date_fields:
1440 try: 1462 try:
@@ -1447,13 +1469,12 @@ class Mastodon:
1447 return json_object 1469 return json_object
1448 1470
1449 @staticmethod 1471 @staticmethod
1450 def __json_id_to_bignum(json_object): 1472 def __json_strnum_to_bignum(json_object):
1451 """ 1473 """
1452 Converts json string IDs to native python bignums. 1474 Converts json string numerals to native python bignums.
1453 """ 1475 """
1454 for key in ('id', 'in_reply_to_id', 'in_reply_to_account_id'): 1476 for key in ('id', 'week', 'in_reply_to_id', 'in_reply_to_account_id', 'logins', 'registrations', 'statuses'):
1455 if (key in json_object and 1477 if (key in json_object and isinstance(json_object[key], six.text_type)):
1456 isinstance(json_object[key], six.text_type)):
1457 try: 1478 try:
1458 json_object[key] = int(json_object[key]) 1479 json_object[key] = int(json_object[key])
1459 except ValueError: 1480 except ValueError:
@@ -1463,8 +1484,8 @@ class Mastodon:
1463 1484
1464 @staticmethod 1485 @staticmethod
1465 def __json_hooks(json_object): 1486 def __json_hooks(json_object):
1487 json_object = Mastodon.__json_strnum_to_bignum(json_object)
1466 json_object = Mastodon.__json_date_parse(json_object) 1488 json_object = Mastodon.__json_date_parse(json_object)
1467 json_object = Mastodon.__json_id_to_bignum(json_object)
1468 json_object = Mastodon.__json_allow_dict_attrs(json_object) 1489 json_object = Mastodon.__json_allow_dict_attrs(json_object)
1469 return json_object 1490 return json_object
1470 1491
Powered by cgit v1.2.3 (git 2.41.0)