Skip to content

Commit

Permalink
bug fix missing attachments from kobo POST request
Browse files Browse the repository at this point in the history
  • Loading branch information
jmargutt committed Mar 20, 2024
1 parent f1bef02 commit 40e0926
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ def get_kobo_attachment(URL, kobo_token):
def get_attachment_dict(kobo_data, kobotoken=None, koboasset=None):
"""Create a dictionary that maps the attachment filenames to their URL."""
attachments = {}
if kobotoken and koboasset and '_id' in kobo_data.keys():
headers = {'Authorization': f'Token {kobotoken}'}
URL = f"https://kobo.ifrc.org/api/v2/assets/{koboasset}/data/{kobo_data['_id']}/?format=json"
data_request = requests.get(URL, headers=headers)
data = data_request.json()
if '_attachments' in data.keys():
attachments = data['_attachments']
if len(attachments) == 0:
if '_attachments' in kobo_data.keys():
attachments = kobo_data['_attachments']
# if kobotoken and koboasset and '_id' in kobo_data.keys():
# headers = {'Authorization': f'Token {kobotoken}'}
# URL = f"https://kobo.ifrc.org/api/v2/assets/{koboasset}/data/{kobo_data['_id']}/?format=json"
# data_request = requests.get(URL, headers=headers)
# data = data_request.json()
# if '_attachments' in data.keys():
# attachments = data['_attachments']
# if len(attachments) == 0:
if '_attachments' in kobo_data.keys():
attachments = kobo_data['_attachments']
for attachment in attachments:
filename = attachment['filename'].split('/')[-1]
downloadurl = attachment['download_url']
Expand Down

0 comments on commit 40e0926

Please sign in to comment.