aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mastodon/Mastodon.py60
1 files changed, 48 insertions, 12 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 4357975..1cbb750 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -90,7 +90,7 @@ class Mastodon:
90 __DEFAULT_BASE_URL = 'https://mastodon.social' 90 __DEFAULT_BASE_URL = 'https://mastodon.social'
91 __DEFAULT_TIMEOUT = 300 91 __DEFAULT_TIMEOUT = 300
92 __DEFAULT_STREAM_RECONNECT_WAIT_SEC = 5 92 __DEFAULT_STREAM_RECONNECT_WAIT_SEC = 5
93 __SUPPORTED_MASTODON_VERSION = "2.2.0" 93 __SUPPORTED_MASTODON_VERSION = "2.3.0"
94 94
95 ### 95 ###
96 # Registering apps 96 # Registering apps
@@ -892,7 +892,7 @@ class Mastodon:
892 ### 892 ###
893 @api_version("1.0.0", "2.0.0") 893 @api_version("1.0.0", "2.0.0")
894 def status_post(self, status, in_reply_to_id=None, media_ids=None, 894 def status_post(self, status, in_reply_to_id=None, media_ids=None,
895 sensitive=False, visibility='', spoiler_text=None): 895 sensitive=False, visibility=None, spoiler_text=None):
896 """ 896 """
897 Post a status. Can optionally be in reply to another status and contain 897 Post a status. Can optionally be in reply to another status and contain
898 media. 898 media.
@@ -930,11 +930,14 @@ class Mastodon:
930 params_initial = locals() 930 params_initial = locals()
931 931
932 # Validate visibility parameter 932 # Validate visibility parameter
933 valid_visibilities = ['private', 'public', 'unlisted', 'direct', ''] 933 valid_visibilities = ['private', 'public', 'unlisted', 'direct']
934 params_initial['visibility'] = params_initial['visibility'].lower() 934 if params_initial['visibility'] == None:
935 if params_initial['visibility'] not in valid_visibilities: 935 del params_initial['visibility']
936 raise ValueError('Invalid visibility value! Acceptable ' 936 else:
937 'values are %s' % valid_visibilities) 937 params_initial['visibility'] = params_initial['visibility'].lower()
938 if params_initial['visibility'] not in valid_visibilities:
939 raise ValueError('Invalid visibility value! Acceptable '
940 'values are %s' % valid_visibilities)
938 941
939 if params_initial['sensitive'] is False: 942 if params_initial['sensitive'] is False:
940 del [params_initial['sensitive']] 943 del [params_initial['sensitive']]
@@ -1145,21 +1148,54 @@ class Mastodon:
1145 1148
1146 @api_version("1.1.1", "2.3.0") 1149 @api_version("1.1.1", "2.3.0")
1147 def account_update_credentials(self, display_name=None, note=None, 1150 def account_update_credentials(self, display_name=None, note=None,
1148 avatar=None, header=None, locked=None): 1151 avatar=None, avatar_mime_type=None,
1152 header=None, header_mime_type=None, locked=None):
1149 """ 1153 """
1150 Update the profile for the currently logged-in user. 1154 Update the profile for the currently logged-in user.
1151 1155
1152 'note' is the user's bio. 1156 'note' is the user's bio.
1153 1157
1154 'avatar' and 'header' are images encoded in base64, prepended by a content-type 1158 'avatar' and 'header' are images. As with media uploads, it is possible to either
1155 (for example: 'data:image/png;base64,iVBORw0KGgoAAAA[...]') 1159 pass image data and a mime type, or a filename of an image file, for either.
1156 1160
1157 'locked' specifies whether the user needs to manually approve follow requests. 1161 'locked' specifies whether the user needs to manually approve follow requests.
1158 1162
1159 Returns the updated `user dict` of the logged-in user. 1163 Returns the updated `user dict` of the logged-in user.
1160 """ 1164 """
1161 params = self.__generate_params(locals()) 1165 params_initial = locals()
1162 return self.__api_request('PATCH', '/api/v1/accounts/update_credentials', params) 1166
1167 # Load avatar, if specified
1168 if avatar_mime_type is None and os.path.isfile(avatar):
1169 avatar_mime_type = mimetypes.guess_type(avatar)[0]
1170 avatar = open(avatar, 'rb')
1171
1172 if (not avatar is None and avatar_mime_type is None):
1173 raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.')
1174
1175 # Load header, if specified
1176 if header_mime_type is None and os.path.isfile(header):
1177 header_mime_type = mimetypes.guess_type(header)[0]
1178 header = open(header, 'rb')
1179
1180 if (not header is None and header_mime_type is None):
1181 raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.')
1182
1183 # Clean up params
1184 for param in ["avatar", "avatar_mime_type", "header", "header_mime_type"]:
1185 if param in params_initial:
1186 del params_initial[param]
1187
1188 # Create file info
1189 files = {}
1190 if not avatar is None:
1191 avatar_file_name = "mastodonpyupload_" + mimetypes.guess_extension(avatar_mime_type)
1192 files["avatar"] = (avatar_file_name, avatar, avatar_mime_type)
1193 if not header is None:
1194 header_file_name = "mastodonpyupload_" + mimetypes.guess_extension(avatar_mime_type)
1195 files["header"] = (header_file_name, header, header_mime_type)
1196
1197 params = self.__generate_params(params_initial)
1198 return self.__api_request('PATCH', '/api/v1/accounts/update_credentials', params, files=files)
1163 1199
1164 ### 1200 ###
1165 # Writing data: Lists 1201 # Writing data: Lists
Powered by cgit v1.2.3 (git 2.41.0)