Change avatar and profile information on update too

* It was only setting this information on /<username>/add
This commit is contained in:
Bofh 2021-02-08 10:07:20 +01:00
parent 2051406397
commit cd0147562b
1 changed files with 11 additions and 1 deletions

View File

@ -70,8 +70,10 @@ def update_igaccount(acc_id):
print('E| User "'+acc_id+'" has not been created yet, maybe you wanted to call /<username>/add ?') print('E| User "'+acc_id+'" has not been created yet, maybe you wanted to call /<username>/add ?')
return 1 return 1
# do it on a thread because it might take long to download the latest posts
data = getig_user_data(acc_id) 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']) pixelfed_dlposts(acc_id, data['graphql']['user'])
def update_allaccounts_async(): def update_allaccounts_async():
@ -261,6 +263,7 @@ def pixelfed_setpic(acc_id, pic_url, count=0):
cachef = pixelfed_cacheimg(pic_url) cachef = pixelfed_cacheimg(pic_url)
accdata = db_get('accounts', acc_id) accdata = db_get('accounts', acc_id)
print('I| setting avatar for "{}" '.format(acc_id), end="")
_, _token = pixelfed_token_url('/settings/home', accdata['cookie']) _, _token = pixelfed_token_url('/settings/home', accdata['cookie'])
r = requests.post( 'https://'+config()['instance']+'/settings/avatar',\ r = requests.post( 'https://'+config()['instance']+'/settings/avatar',\
data={'_token': _token}, cookies=accdata['cookie'], files={'avatar': open(cachef, 'rb')} 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 # try to login if the upload failed
if r.status_code == 419 and count < 3: if r.status_code == 419 and count < 3:
print('err (login required)')
pixelfed_login(acc_id, True) pixelfed_login(acc_id, True)
return pixelfed_setpic(acc_id, pic_url, count) return pixelfed_setpic(acc_id, pic_url, count)
print('ok')
return True return True
def pixelfed_setinfo(acc_id, bio, website, count=0): 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) pixelfed_login(acc_id)
accdata = db_get('accounts', 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']) _, _token = pixelfed_token_url('/settings/home', accdata['cookie'])
r = requests.post( 'https://'+config()['instance']+'/settings/home',\ r = requests.post( 'https://'+config()['instance']+'/settings/home',\
data={ data={
@ -289,9 +296,12 @@ def pixelfed_setinfo(acc_id, bio, website, count=0):
# try to login if the upload failed # try to login if the upload failed
if r.status_code == 419 and count < 3: if r.status_code == 419 and count < 3:
print('err (login required)')
pixelfed_login(acc_id, True) pixelfed_login(acc_id, True)
return pixelfed_setinfo(acc_id, bio, website, count) return pixelfed_setinfo(acc_id, bio, website, count)
print('ok')
return True return True