diff --git a/app.py b/app.py index 3b022f1..28951c7 100755 --- a/app.py +++ b/app.py @@ -11,19 +11,23 @@ def home(): threads = [] for id in thread_ids: 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['descendants'] = descendants + status['descendants'] = get_descendants(server, status) threads.append(status) return threads 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__': app.run(host='0.0.0.0')