From cd0147562b410a99d0ab3d79eaedae091fbbc44d Mon Sep 17 00:00:00 2001 From: Bofh Date: Mon, 8 Feb 2021 10:07:20 +0100 Subject: [PATCH] Change avatar and profile information on update too * It was only setting this information on //add --- igmirror.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/igmirror.py b/igmirror.py index b84c2bb..70baf25 100644 --- a/igmirror.py +++ b/igmirror.py @@ -70,8 +70,10 @@ def update_igaccount(acc_id): print('E| User "'+acc_id+'" has not been created yet, maybe you wanted to call //add ?') return 1 - # do it on a thread because it might take long to download the latest posts data = getig_user_data(acc_id) + pixelfed_setpic(acc_id, data['graphql']['user']['profile_pic_url']) + pixelfed_setinfo(acc_id, data['graphql']['user']['biography'],\ + data['graphql']['user']['external_url']) pixelfed_dlposts(acc_id, data['graphql']['user']) def update_allaccounts_async(): @@ -261,6 +263,7 @@ def pixelfed_setpic(acc_id, pic_url, count=0): cachef = pixelfed_cacheimg(pic_url) accdata = db_get('accounts', acc_id) + print('I| setting avatar for "{}" '.format(acc_id), end="") _, _token = pixelfed_token_url('/settings/home', accdata['cookie']) r = requests.post( 'https://'+config()['instance']+'/settings/avatar',\ data={'_token': _token}, cookies=accdata['cookie'], files={'avatar': open(cachef, 'rb')} @@ -268,9 +271,12 @@ def pixelfed_setpic(acc_id, pic_url, count=0): # try to login if the upload failed if r.status_code == 419 and count < 3: + print('err (login required)') pixelfed_login(acc_id, True) return pixelfed_setpic(acc_id, pic_url, count) + print('ok') + return True def pixelfed_setinfo(acc_id, bio, website, count=0): @@ -278,6 +284,7 @@ def pixelfed_setinfo(acc_id, bio, website, count=0): pixelfed_login(acc_id) accdata = db_get('accounts', acc_id) + print('I| setting account-info for "{}" '.format(acc_id), end="") _, _token = pixelfed_token_url('/settings/home', accdata['cookie']) r = requests.post( 'https://'+config()['instance']+'/settings/home',\ data={ @@ -289,9 +296,12 @@ def pixelfed_setinfo(acc_id, bio, website, count=0): # try to login if the upload failed if r.status_code == 419 and count < 3: + print('err (login required)') pixelfed_login(acc_id, True) return pixelfed_setinfo(acc_id, bio, website, count) + print('ok') + return True