joshuadunlop commited on
Commit
53590af
·
verified ·
1 Parent(s): 47e2fc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -27,7 +27,15 @@ def get_backlinks(api_login, api_key, target_url, filters):
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:
@@ -54,6 +62,10 @@ def get_backlinks(api_login, api_key, target_url, filters):
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]")
@@ -104,9 +116,15 @@ reset_button = st.sidebar.button("Reset")
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:
 
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
+ # For debugging: Display the status code and any text
33
+ st.text(f"Response Status Code: {response.status_code}")
34
+ st.text(f"Response Headers: {response.headers}")
35
+ try:
36
+ st.text(f"Response Body: {response.json()}")
37
+ except ValueError:
38
+ st.text("Response Body: <Not a JSON response>")
39
 
40
  # Check if the response contains 'results' key
41
  if response.status_code == 200:
 
62
  st.error(f"Error: Code: {response.status_code} Message: {error_message}")
63
  return None
64
 
65
+ def convert_df_to_csv(df):
66
+ # Convert DataFrame to CSV
67
+ return df.to_csv().encode('utf-8')
68
+
69
  # Streamlit layout
70
  st.sidebar.title("DataForSEO API Parameters")
71
  api_login = st.sidebar.text_input("API Login", value="[email protected]")
 
116
  if generate_button and target_url:
117
  df = get_backlinks(api_login, api_key, target_url, filters)
118
  if df is not None:
119
+ # Convert DataFrame to CSV
120
+ csv = convert_df_to_csv(df)
121
+ # Create download link
122
+ st.download_button(
123
+ label="Download data as CSV",
124
+ data=csv,
125
+ file_name='backlinks.csv',
126
+ mime='text/csv',
127
+ )
128
 
129
  # Reset functionality
130
  if reset_button: