feat: only handle 200 OK results, otherwise return empty list
This commit is contained in:
parent
1e569b9e18
commit
6e57c0fa92
1 changed files with 31 additions and 18 deletions
19
threads.py
19
threads.py
|
|
@ -10,7 +10,6 @@ threads = Blueprint('threads', __name__, template_folder='templates', static_fol
|
||||||
|
|
||||||
# TODO: move following to an app config or sqlite #########
|
# TODO: move following to an app config or sqlite #########
|
||||||
thread_ids = [
|
thread_ids = [
|
||||||
'116045566641672623',
|
|
||||||
'115620814664415087',
|
'115620814664415087',
|
||||||
'115090396384901152',
|
'115090396384901152',
|
||||||
'114700726180478526',
|
'114700726180478526',
|
||||||
|
|
@ -68,17 +67,23 @@ def get_account_tagged_statuses(tag_name):
|
||||||
ser = server()
|
ser = server()
|
||||||
url = f'{ser}/api/v1/accounts/{id}/statuses?exclude_replies=true&tagged={tag_name}'
|
url = f'{ser}/api/v1/accounts/{id}/statuses?exclude_replies=true&tagged={tag_name}'
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
|
if response.status_code == 200:
|
||||||
statuses = response.json()
|
statuses = response.json()
|
||||||
statuses = [utils.clean_status(s) for s in statuses]
|
statuses = [utils.clean_status(s) for s in statuses]
|
||||||
return statuses
|
return statuses
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
|
||||||
def get_featured_tags():
|
def get_featured_tags():
|
||||||
id = get_user_id()
|
id = get_user_id()
|
||||||
ser = server()
|
ser = server()
|
||||||
url = f'{ser}/api/v1/accounts/{id}/featured_tags'
|
url = f'{ser}/api/v1/accounts/{id}/featured_tags'
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
|
if response.status_code == 200:
|
||||||
tags = response.json()
|
tags = response.json()
|
||||||
return tags
|
return tags
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
### middleware
|
### middleware
|
||||||
|
|
@ -119,14 +124,20 @@ async def fetch_statuses():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def fetch_thread(id):
|
def fetch_thread(id):
|
||||||
status = requests.get(server() + '/api/v1/statuses/' + id ).json()
|
response = requests.get(server() + '/api/v1/statuses/' + id )
|
||||||
|
if response.status_code == 200:
|
||||||
|
status = response.json()
|
||||||
status = utils.clean_status(status)
|
status = utils.clean_status(status)
|
||||||
status['descendants'] = get_descendants(server(), status)
|
status['descendants'] = get_descendants(server(), status)
|
||||||
return status
|
return status
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def get_descendants(server, status):
|
def get_descendants(server, status):
|
||||||
author_id = status['account']['id']
|
author_id = status['account']['id']
|
||||||
context = requests.get(server + '/api/v1/statuses/' + status['id'] + '/context').json()
|
response = requests.get(server + '/api/v1/statuses/' + status['id'] + '/context')
|
||||||
|
if response.status_code == 200:
|
||||||
|
context = response.json()
|
||||||
descendants = []
|
descendants = []
|
||||||
for reply in context['descendants']:
|
for reply in context['descendants']:
|
||||||
# TODO: the following condition will include a reply to a reply of the author
|
# TODO: the following condition will include a reply to a reply of the author
|
||||||
|
|
@ -134,6 +145,8 @@ def get_descendants(server, status):
|
||||||
if reply['account']['id'] == author_id and reply['in_reply_to_account_id'] == author_id:
|
if reply['account']['id'] == author_id and reply['in_reply_to_account_id'] == author_id:
|
||||||
descendants.append(utils.clean_status(reply))
|
descendants.append(utils.clean_status(reply))
|
||||||
return descendants
|
return descendants
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
|
||||||
### routes
|
### routes
|
||||||
@threads.route('/')
|
@threads.route('/')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue