From 2ce39ea06fb0d2c1a9e92a3ae4735d8e9615338c Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sun, 17 Jan 2021 21:45:50 -0800 Subject: [PATCH] fix link references for api v1 --- pnut-matrix.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pnut-matrix.py b/pnut-matrix.py index c3eb2db..997a2b8 100644 --- a/pnut-matrix.py +++ b/pnut-matrix.py @@ -58,7 +58,7 @@ def new_message(msg): logger.debug('-set_display-') avatar = Avatars.query.filter(Avatars.pnut_user == msg.user.username).one_or_none() - if avatar is None or avatar.avatar != msg.user.content.avatar_image.link: + if avatar is None or avatar.avatar != msg.user.content.avatar_image.url: set_matrix_avatar(msg.user) logger.debug('-set_avatar-') @@ -76,8 +76,8 @@ def new_message(msg): for link in msg.content.entities.links: if 'title' in link: lnktext += link.title + "\n" - if 'link' in link: - lnktext += link.link + "\n" + if 'url' in link: + lnktext += link.url + "\n" if len(lnktext) > 0: text += "\n" + lnktext @@ -189,7 +189,7 @@ def set_matrix_avatar(user): token=config['MATRIX_AS_TOKEN'], identity=matrix_id) - dl = requests.get(user.content.avatar_image.link, stream=True) + dl = requests.get(user.content.avatar_image.url, stream=True) dl.raise_for_status() with magic.Magic(flags=magic.MAGIC_MIME_TYPE) as m: mtype = m.id_buffer(dl.content) @@ -199,10 +199,10 @@ def set_matrix_avatar(user): matrix_api.set_avatar_url(matrix_id, ul['content_uri']) avatar = Avatars.query.filter(Avatars.pnut_user == user.username).one_or_none() if avatar is None: - avatar = Avatars(pnut_user=user.username, avatar=user.content.avatar_image.link) + avatar = Avatars(pnut_user=user.username, avatar=user.content.avatar_image.url) db_session.add(avatar) else: - avatar.avatar = user.content.avatar_image.link + avatar.avatar = user.content.avatar_image.url db_session.commit() except MatrixRequestError: @@ -309,6 +309,7 @@ if __name__ == '__main__': '-d', action='store_true', dest='debug', help="debug logging" ) + # TODO: solve the database.py problem and enable this # a_parser.add_argument( # '-c', '--config', default="config.yaml", # help="configuration file" @@ -321,9 +322,6 @@ if __name__ == '__main__': else: logging.basicConfig(level=logging.INFO) - # with open(args.config, 'rb') as config_file: - # config = yaml.load(config_file, Loader=yaml.SafeLoader) - configyaml = os.environ.get("CONFIG_FILE") with open(configyaml, "rb") as config_file: