joshuadunlop commited on
Commit
f85e62e
·
verified ·
1 Parent(s): 1e10a71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -28,12 +28,14 @@ def get_backlinks(api_login, api_key, target_url, filters):
28
  # Check if the response contains 'results' key
29
  if response.status_code == 200:
30
  response_data = response.json()
31
-
 
32
  if 'results' in response_data:
33
  results = response_data['results']
34
  if results:
35
  # Normalize the JSON data into a pandas DataFrame
36
  df = pd.json_normalize(results)
 
37
  return df
38
  else:
39
  st.error("Received empty data from API.")
@@ -47,7 +49,7 @@ def get_backlinks(api_login, api_key, target_url, filters):
47
  error_message = response.json().get('status_message', 'No specific error message provided')
48
  st.error(f"Error: Code: {response.status_code} Message: {error_message}")
49
  return None
50
-
51
  # Streamlit layout
52
  st.sidebar.title("DataForSEO API Parameters")
53
  api_login = st.sidebar.text_input("API Login", value="[email protected]")
@@ -97,10 +99,12 @@ reset_button = st.sidebar.button("Reset")
97
  # Generate CSV and download button
98
  if generate_button and target_url:
99
  df = get_backlinks(api_login, api_key, target_url, filters)
100
- if df is not None:
101
  with col2:
102
  st.header("Output")
103
  st.dataframe(df) # This displays the DataFrame as a table
 
 
104
 
105
  # Reset functionality
106
  if reset_button:
 
28
  # Check if the response contains 'results' key
29
  if response.status_code == 200:
30
  response_data = response.json()
31
+ st.write("API Response:", response_data) # Display the full JSON response for debugging
32
+
33
  if 'results' in response_data:
34
  results = response_data['results']
35
  if results:
36
  # Normalize the JSON data into a pandas DataFrame
37
  df = pd.json_normalize(results)
38
+ st.write("DataFrame:", df) # Display the DataFrame for debugging
39
  return df
40
  else:
41
  st.error("Received empty data from API.")
 
49
  error_message = response.json().get('status_message', 'No specific error message provided')
50
  st.error(f"Error: Code: {response.status_code} Message: {error_message}")
51
  return None
52
+
53
  # Streamlit layout
54
  st.sidebar.title("DataForSEO API Parameters")
55
  api_login = st.sidebar.text_input("API Login", value="[email protected]")
 
99
  # Generate CSV and download button
100
  if generate_button and target_url:
101
  df = get_backlinks(api_login, api_key, target_url, filters)
102
+ if df is not None and not df.empty:
103
  with col2:
104
  st.header("Output")
105
  st.dataframe(df) # This displays the DataFrame as a table
106
+ elif df is not None and df.empty:
107
+ st.write("The DataFrame is empty. No data to display.")
108
 
109
  # Reset functionality
110
  if reset_button: