Update app.py
Browse files
app.py
CHANGED
@@ -29,9 +29,14 @@ def get_backlinks(api_login, api_key, target_url, filters):
|
|
29 |
if response.status_code == 200 and 'results' in response.json():
|
30 |
# Extract the results
|
31 |
results = response.json()['results']
|
32 |
-
#
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
35 |
else:
|
36 |
error_message = response.json().get('status_message', 'No specific error message provided')
|
37 |
st.error(f"Error: Code: {response.status_code} Message: {error_message}")
|
@@ -72,14 +77,9 @@ generate_button = st.sidebar.button("Generate All")
|
|
72 |
reset_button = st.sidebar.button("Reset")
|
73 |
|
74 |
# Generate CSV and download button
|
75 |
-
if generate_button and target_url:
|
76 |
df = get_backlinks(api_login, api_key, target_url, filters)
|
77 |
if df is not None:
|
78 |
-
csv = df.to_csv(index=False)
|
79 |
-
b64 = base64.b64encode(csv.encode()).decode()
|
80 |
-
href = f'<a href="data:file/csv;base64,{b64}" download="backlinks.csv">Download CSV file</a>'
|
81 |
-
st.markdown(href, unsafe_allow_html=True)
|
82 |
-
|
83 |
# Display the DataFrame in the second column
|
84 |
with col2:
|
85 |
st.header("Output")
|
|
|
29 |
if response.status_code == 200 and 'results' in response.json():
|
30 |
# Extract the results
|
31 |
results = response.json()['results']
|
32 |
+
# Check if results are not empty
|
33 |
+
if results:
|
34 |
+
# Convert results to DataFrame
|
35 |
+
df = pd.DataFrame(results)
|
36 |
+
return df
|
37 |
+
else:
|
38 |
+
st.error("Received empty data from API.")
|
39 |
+
return None
|
40 |
else:
|
41 |
error_message = response.json().get('status_message', 'No specific error message provided')
|
42 |
st.error(f"Error: Code: {response.status_code} Message: {error_message}")
|
|
|
77 |
reset_button = st.sidebar.button("Reset")
|
78 |
|
79 |
# Generate CSV and download button
|
80 |
+
if generate_button and target_url:
|
81 |
df = get_backlinks(api_login, api_key, target_url, filters)
|
82 |
if df is not None:
|
|
|
|
|
|
|
|
|
|
|
83 |
# Display the DataFrame in the second column
|
84 |
with col2:
|
85 |
st.header("Output")
|