refactor: extrace get_descendants to function
This commit is contained in:
parent
7e6c9d5e77
commit
b20cb6b48e
1 changed files with 12 additions and 8 deletions
20
app.py
20
app.py
|
@ -11,19 +11,23 @@ def home():
|
||||||
threads = []
|
threads = []
|
||||||
for id in thread_ids:
|
for id in thread_ids:
|
||||||
status = requests.get(server + '/api/v1/statuses/' + id ).json()
|
status = requests.get(server + '/api/v1/statuses/' + id ).json()
|
||||||
author = status['account']['id']
|
|
||||||
context = requests.get(server + '/api/v1/statuses/' + id + '/context').json()
|
|
||||||
descendants = []
|
|
||||||
for reply in context['descendants']:
|
|
||||||
if reply['account']['id'] == author and reply['in_reply_to_account_id'] == author:
|
|
||||||
descendants.append(clean_status(reply))
|
|
||||||
status = clean_status(status)
|
status = clean_status(status)
|
||||||
status['descendants'] = descendants
|
status['descendants'] = get_descendants(server, status)
|
||||||
threads.append(status)
|
threads.append(status)
|
||||||
return threads
|
return threads
|
||||||
|
|
||||||
def clean_status(status):
|
def clean_status(status):
|
||||||
return {k: status[k] for k in {'content', 'created_at', 'url', 'media_attachments', 'card'}}
|
return {k: status[k] for k in ['id', 'account', 'content', 'created_at', 'url', 'media_attachments', 'card']}
|
||||||
|
|
||||||
|
def get_descendants(server, status):
|
||||||
|
author_id = status['account']['id']
|
||||||
|
context = requests.get(server + '/api/v1/statuses/' + status['id'] + '/context').json()
|
||||||
|
descendants = []
|
||||||
|
for reply in context['descendants']:
|
||||||
|
if reply['account']['id'] == author_id and reply['in_reply_to_account_id'] == author_id:
|
||||||
|
descendants.append(clean_status(reply))
|
||||||
|
return descendants
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0')
|
app.run(host='0.0.0.0')
|
||||||
|
|
Loading…
Reference in a new issue