Update app.py
Browse files
app.py
CHANGED
@@ -25,30 +25,35 @@ def get_backlinks(api_login, api_key, target_url, filters):
|
|
25 |
# Making the API request
|
26 |
response = requests.post("https://api.dataforseo.com/v3/backlinks/backlinks/live", json=post_data, headers=headers)
|
27 |
|
28 |
-
#
|
29 |
-
st.
|
|
|
30 |
|
31 |
# Check if the response contains 'results' key
|
32 |
if response.status_code == 200:
|
33 |
response_data = response.json()
|
34 |
-
|
|
|
35 |
if 'results' in response_data:
|
36 |
results = response_data['results']
|
37 |
-
# Check if results is not empty
|
38 |
if results:
|
39 |
-
#
|
40 |
df = pd.json_normalize(results)
|
41 |
return df
|
42 |
else:
|
43 |
st.error("Received empty data from API.")
|
44 |
-
return
|
45 |
else:
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
48 |
else:
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
52 |
# Streamlit layout
|
53 |
st.sidebar.title("DataForSEO API Parameters")
|
54 |
api_login = st.sidebar.text_input("API Login", value="[email protected]")
|
@@ -98,12 +103,10 @@ reset_button = st.sidebar.button("Reset")
|
|
98 |
# Generate CSV and download button
|
99 |
if generate_button and target_url:
|
100 |
df = get_backlinks(api_login, api_key, target_url, filters)
|
101 |
-
if not
|
102 |
with col2:
|
103 |
st.header("Output")
|
104 |
-
st.dataframe(df) #
|
105 |
-
else:
|
106 |
-
st.write("No data available to display.")
|
107 |
|
108 |
# Reset functionality
|
109 |
if reset_button:
|
|
|
25 |
# Making the API request
|
26 |
response = requests.post("https://api.dataforseo.com/v3/backlinks/backlinks/live", json=post_data, headers=headers)
|
27 |
|
28 |
+
# Log the full response for debugging
|
29 |
+
st.text("API Response:")
|
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')
|
54 |
+
st.error(f"Error: Code: {response.status_code} Message: {error_message}")
|
55 |
+
return None
|
56 |
+
|
57 |
# Streamlit layout
|
58 |
st.sidebar.title("DataForSEO API Parameters")
|
59 |
api_login = st.sidebar.text_input("API Login", value="[email protected]")
|
|
|
103 |
# Generate CSV and download button
|
104 |
if generate_button and target_url:
|
105 |
df = get_backlinks(api_login, api_key, target_url, filters)
|
106 |
+
if df is not None:
|
107 |
with col2:
|
108 |
st.header("Output")
|
109 |
+
st.dataframe(df) # This will display the DataFrame as a table
|
|
|
|
|
110 |
|
111 |
# Reset functionality
|
112 |
if reset_button:
|