Added posts nuke API function

This commit is contained in:
Bofh 2021-02-08 21:07:49 +01:00
parent cb74d89ad5
commit 9414a6adc6
2 changed files with 36 additions and 1 deletions

View File

@ -90,6 +90,39 @@ def update_allaccounts():
print()
print('I| done updating all accounts')
def delete_statuses(acc_id):
accdata = db_get('accounts', acc_id)
if not pixelfed_islogged(acc_id, accdata):
print('E| user "{}" is not logged in. Please log in'.format(acc_id))
return 1
r = requests.get( 'https://'+config()['instance']+'/api/pixelfed/v1/accounts/verify_credentials', cookies=accdata['cookie'])
pixdata = json.loads(r.text)
if not 'id' in pixdata:
print('E| fatal! API is not working!. Might be a connectivity issue or the Account does Not Exist??'.format(acc_id))
return 2
_, _token = pixelfed_token_url('', accdata['cookie'])
_headers = {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'X-CSRF-TOKEN': _token,
'X-XSRF-TOKEN': accdata['cookie']['XSRF-TOKEN']
}
while True:
r2 = requests.get('https://'+config()['instance']+'/api/pixelfed/v1/accounts/{}/statuses?min_id=1'.format(pixdata['id']),\
cookies=accdata['cookie'] )
jsdata = json.loads(r2.text)
if not jsdata:
break
for status in jsdata:
print('I| deleting status "{}" for account "{}"... '.format(status['id'], acc_id), end='')
r3 = requests.post('https://'+config()['instance']+'/i/delete', json={'item': status['id'], 'type': 'status'},\
cookies=accdata['cookie'], headers=_headers)
print(r3.status_code)
print('I| done nuking account posts for "{}"'.format(acc_id))
return 0
def logout_account(acc_id):
accdata = db_get('accounts', acc_id)
del accdata['cookie']
@ -155,7 +188,7 @@ def pixelfed_dlposts(acc_id, data):
accdata = db_get('accounts', acc_id)
for item in items:
if item['shortcode'] in accposts and not item['is_video']:
if item['shortcode'] in accposts:
print('I| skipping IG post {}:{}. Already added'.format(acc_id, item['shortcode']))
continue

View File

@ -28,6 +28,8 @@ class MyServer(BaseHTTPRequestHandler):
igmirror.update_igaccount_async(accname)
elif parts[1].lower() == 'logout':
igmirror.logout_account(accname)
elif parts[1].lower() == 'nuke':
igmirror.delete_statuses(accname)
self.wfile.write(bytes('{"status": "ok"}', "utf-8"))
else:
self.wfile.write(bytes('{"status": "parameters are not correct"}', "utf-8"))