joshuadunlop commited on
Commit
6abe217
·
verified ·
1 Parent(s): a02be6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -30,17 +30,24 @@ def get_backlinks(api_login, api_key, target_url, filters):
30
  st.json(response.json()) # This will display the full JSON response in the Streamlit app
31
 
32
  # Check if the response contains 'results' key
33
- if response.status_code == 200 and 'results' in response.json():
34
- # Extract the results
35
- results = response.json()['results']
36
- if results:
37
- # Assuming 'results' contains a list of backlink information,
38
- # we need to convert this list to a DataFrame.
39
- # Modify the line below according to the actual structure of 'results'
40
- df = pd.json_normalize(results) # Adjust this line as per the actual JSON structure
41
- return df
 
 
 
 
42
  else:
43
- st.error("Received empty data from API.")
 
 
 
44
  return None
45
  else:
46
  error_message = response.json().get('status_message', 'No specific error message provided')
 
30
  st.json(response.json()) # This will display the full JSON response in the Streamlit app
31
 
32
  # Check if the response contains 'results' key
33
+ if response.status_code == 200:
34
+ response_data = response.json()
35
+
36
+ # Check if 'results' key is in the response
37
+ if 'results' in response_data:
38
+ results = response_data['results']
39
+ if results:
40
+ # Adjust the following line based on the actual JSON structure
41
+ df = pd.json_normalize(results)
42
+ return df
43
+ else:
44
+ st.error("Received empty data from API.")
45
+ return None
46
  else:
47
+ # Handle other internal status codes here
48
+ internal_status_code = response_data.get('status_code', None)
49
+ internal_status_message = response_data.get('status_message', 'No specific message provided')
50
+ st.error(f"Internal Status Code: {internal_status_code}, Message: {internal_status_message}")
51
  return None
52
  else:
53
  error_message = response.json().get('status_message', 'No specific error message provided')