Update app.py
Browse files
app.py
CHANGED
@@ -28,27 +28,20 @@ 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 |
|
33 |
-
if 'results' in response_data:
|
34 |
results = response_data['results']
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
st.write("DataFrame:", df) # Display the DataFrame for debugging
|
39 |
-
return df
|
40 |
-
else:
|
41 |
-
st.error("Received empty data from API.")
|
42 |
-
return None
|
43 |
else:
|
44 |
-
|
45 |
-
|
46 |
-
st.error(f"Internal Status Code: {internal_status_code}, Message: {internal_status_message}")
|
47 |
-
return None
|
48 |
else:
|
49 |
-
|
50 |
-
|
51 |
-
return None
|
52 |
|
53 |
# Streamlit layout
|
54 |
st.sidebar.title("DataForSEO API Parameters")
|
@@ -99,12 +92,12 @@ reset_button = st.sidebar.button("Reset")
|
|
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
|
103 |
with col2:
|
104 |
st.header("Output")
|
105 |
-
st.dataframe(df) #
|
106 |
-
|
107 |
-
st.write("
|
108 |
|
109 |
# Reset functionality
|
110 |
if reset_button:
|
|
|
28 |
# Check if the response contains 'results' key
|
29 |
if response.status_code == 200:
|
30 |
response_data = response.json()
|
31 |
+
# Debugging line: uncomment below to see the response data structure
|
32 |
+
# st.write("API Response:", response_data)
|
33 |
|
34 |
+
if 'results' in response_data and response_data['results']:
|
35 |
results = response_data['results']
|
36 |
+
# Assuming 'results' is a list of dictionaries
|
37 |
+
df = pd.json_normalize(results)
|
38 |
+
return df
|
|
|
|
|
|
|
|
|
|
|
39 |
else:
|
40 |
+
st.error("No results found in API response.")
|
41 |
+
return pd.DataFrame() # Return an empty DataFrame
|
|
|
|
|
42 |
else:
|
43 |
+
st.error(f"API request failed with status code {response.status_code}")
|
44 |
+
return pd.DataFrame() # Return an empty DataFrame
|
|
|
45 |
|
46 |
# Streamlit layout
|
47 |
st.sidebar.title("DataForSEO API Parameters")
|
|
|
92 |
# Generate CSV and download button
|
93 |
if generate_button and target_url:
|
94 |
df = get_backlinks(api_login, api_key, target_url, filters)
|
95 |
+
if not df.empty:
|
96 |
with col2:
|
97 |
st.header("Output")
|
98 |
+
st.dataframe(df) # Display the DataFrame
|
99 |
+
else:
|
100 |
+
st.write("No data available to display.")
|
101 |
|
102 |
# Reset functionality
|
103 |
if reset_button:
|