From 405e01bef9461b1f53994425318ac27f293f46cb Mon Sep 17 00:00:00 2001 From: halcy Date: Thu, 1 Dec 2022 21:44:57 +0200 Subject: Minor fixes, document some return values --- docs/02_return_values.rst | 52 ++++++++++++++++++++++++++++++++++++++++------- mastodon/internals.py | 7 ++++--- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/docs/02_return_values.rst b/docs/02_return_values.rst index 9cc1e77..94d2943 100644 --- a/docs/02_return_values.rst +++ b/docs/02_return_values.rst @@ -24,6 +24,10 @@ you can also just write and everything will work as intended. The class used for this is exposed as `AttribAccessDict`. +Currently, some of these may be out of date - refer to the Mastodon documentation at +https://docs.joinmastodon.org/entities/ for when fields seem to be missing. This will +be addressed in the next version of Mastodon.py. + User / account dicts -------------------- .. _user dict: @@ -133,7 +137,13 @@ Status edit dicts mastodonstatus_history(id)[0] # Returns the following dictionary { - TODO + 'content': # Content for this version of the status + 'spoiler_text': # CW / Spoiler text for this version of the status + 'sensitive': # Whether media in this version of the status is marked as sensitive + 'created_at': # Time at which this version of the status was posted + 'account': # Account dict of the user that posted the status + 'media_attachments': # List of media dicts with the attached media for this version of the status + 'emojis'# List of emoji dicts for this version of the status } Mention dicts @@ -658,7 +668,8 @@ Familiar follower dicts mastodon.account_familiar_followers(1)[0] # Returns the following dictionary: { - + 'id': # ID of the account for which the familiar followers are being returned + 'accounts': # List of account dicts of the familiar followers } Admin account dicts @@ -683,7 +694,7 @@ Admin account dicts 'disabled': # For local users, boolean indicating whether the user has had their login disabled 'approved': # For local users, False if the user is pending, True otherwise 'locale': # For local users, the locale the user has set, - 'invite_request': # If the user requested an invite, the invite request comment of that user. (TODO permanent?) + 'invite_request': # If the user requested an invite, the invite request comment of that user. 'invited_by_account_id': # Present if the user was invited by another user and set to the inviting users id. 'account': # The user's account, as a standard user dict } @@ -717,7 +728,17 @@ Admin measure dicts api.admin_measures(datetime.now() - timedelta(hours=24*5), datetime.now(), active_users=True) # Returns the following dictionary { - TODO + 'key': # Name of the measure returned + 'unit': # Unit for the measure, if available + 'total': # Value of the measure returned + 'human_value': # Human readable variant of the measure returned + 'data': # A list of dicts with the measure broken down by date, as below + } + + # The data dicts: + [ + 'date': # Date for this row + 'value': # Value of the measure for this row } Admin dimension dicts @@ -729,9 +750,16 @@ Admin dimension dicts api.admin_dimensions(datetime.now() - timedelta(hours=24*5), datetime.now(), languages=True) # Returns the following dictionary { - TODO + 'key': # Name of the dimension returned + 'data': # A list of data dicts, as below } - + + # the data dicts: + { + 'key': # category for this row + 'human_key': # Human readable name for the category for this row, when available + 'value': # Numeric value for the category + }, Admin retention dicts --------------------- .. _admin retention dict: @@ -741,5 +769,15 @@ Admin retention dicts api.admin_retention(datetime.now() - timedelta(hours=24*5), datetime.now()) # Returns the following dictionary { - TODO + 'period': # Starting time of the period that the data is being returned for + 'frequency': # Time resolution (day or month) for the returned data + 'data': # List of data dicts, as below + } + + # the data dicts: + { + 'date': # Date for this entry + 'rate': # Fraction of users retained + 'value': # Absolute number of users retained } + \ No newline at end of file diff --git a/mastodon/internals.py b/mastodon/internals.py index aa82553..758a1d4 100644 --- a/mastodon/internals.py +++ b/mastodon/internals.py @@ -62,7 +62,7 @@ class Mastodon(): Parse dates in certain known json fields, if possible. """ known_date_fields = ["created_at", "week", "day", "expires_at", "scheduled_at", - "updated_at", "last_status_at", "starts_at", "ends_at", "published_at", "edited_at"] + "updated_at", "last_status_at", "starts_at", "ends_at", "published_at", "edited_at", "date", "period"] mark_delete = [] for k, v in json_object.items(): if k in known_date_fields: @@ -85,7 +85,7 @@ class Mastodon(): """ Parse 'True' / 'False' strings in certain known fields """ - for key in ('follow', 'favourite', 'reblog', 'mention'): + for key in ('follow', 'favourite', 'reblog', 'mention', 'confirmed', 'suspended', 'silenced', 'disabled', 'approved', 'all_day'): if (key in json_object and isinstance(json_object[key], six.text_type)): if json_object[key].lower() == 'true': json_object[key] = True @@ -98,7 +98,8 @@ class Mastodon(): """ Converts json string numerals to native python bignums. """ - for key in ('id', 'week', 'in_reply_to_id', 'in_reply_to_account_id', 'logins', 'registrations', 'statuses', 'day', 'last_read_id'): + for key in ('id', 'week', 'in_reply_to_id', 'in_reply_to_account_id', 'logins', 'registrations', 'statuses', + 'day', 'last_read_id', 'value', 'frequency', 'rate', 'invited_by_account_id', 'count'): if (key in json_object and isinstance(json_object[key], six.text_type)): try: json_object[key] = int(json_object[key]) -- cgit v1.2.3