joshuadunlop commited on
Commit
9deb76c
·
verified ·
1 Parent(s): b95b7b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -42,20 +42,22 @@ def get_backlinks(api_login, api_key, target_url, filters):
42
  # Debugging: Print out the keys of the response_data
43
  st.text(f"Keys in response JSON: {list(response_data.keys())}")
44
 
45
- if 'results' in response_data:
46
- results = response_data['results']
47
- if results:
48
- # Debugging: print the first few items to inspect the structure
49
- st.text(f"First few results: {results[:5]}") # assuming results is a list
 
 
50
 
51
  # Convert to DataFrame
52
- df = pd.json_normalize(results)
53
  return df
54
  else:
55
- st.error("Received empty 'results' from API.")
56
  return None
57
  else:
58
- st.error(f"No 'results' key in response JSON. Full response: {response_data}")
59
  return None
60
  else:
61
  error_message = response.json().get('status_message', 'No specific error message provided')
 
42
  # Debugging: Print out the keys of the response_data
43
  st.text(f"Keys in response JSON: {list(response_data.keys())}")
44
 
45
+ if 'tasks' in response_data:
46
+ # Assuming there is only one task and one result within each task
47
+ task_result = response_data['tasks'][0]['result']
48
+ if task_result and 'items' in task_result[0]:
49
+ # The actual backlink items are nested within 'items'
50
+ items = task_result[0]['items']
51
+ st.text(f"First few items: {items[:5]}") # Debugging line to show the items structure
52
 
53
  # Convert to DataFrame
54
+ df = pd.json_normalize(items)
55
  return df
56
  else:
57
+ st.error("Received empty 'result' from API or missing 'items'.")
58
  return None
59
  else:
60
+ st.error(f"No 'tasks' key in response JSON. Full response: {response_data}")
61
  return None
62
  else:
63
  error_message = response.json().get('status_message', 'No specific error message provided')