joshuadunlop commited on
Commit
7588655
·
verified ·
1 Parent(s): d964699

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -3,8 +3,6 @@ import pandas as pd
3
  import requests
4
  import base64
5
 
6
- # Function to call the DataForSEO API with Basic Authentication
7
-
8
  def get_backlinks(api_login, api_key, target_url, filters):
9
  # Encoding credentials
10
  encoded_credentials = base64.b64encode(f"{api_login}:{api_key}".encode()).decode()
@@ -29,7 +27,11 @@ def get_backlinks(api_login, api_key, target_url, filters):
29
 
30
  # Check if the response contains 'results' key
31
  if response.status_code == 200 and 'results' in response.json():
32
- return response.json()['results']
 
 
 
 
33
  else:
34
  error_message = response.json().get('status_message', 'No specific error message provided')
35
  st.error(f"Error: Code: {response.status_code} Message: {error_message}")
@@ -71,20 +73,16 @@ reset_button = st.sidebar.button("Reset")
71
 
72
  # Generate CSV and download button
73
  if generate_button and target_url: # Check after target_url is defined
74
- data = get_backlinks(api_login, api_key, target_url, filters)
75
- if data:
76
- df = pd.DataFrame(data)
77
  csv = df.to_csv(index=False)
78
  b64 = base64.b64encode(csv.encode()).decode()
79
  href = f'<a href="data:file/csv;base64,{b64}" download="backlinks.csv">Download CSV file</a>'
80
  st.markdown(href, unsafe_allow_html=True)
81
 
82
- with col2:
83
- st.header("Output")
84
- if generate_button and target_url:
85
- data = get_backlinks(api_login, api_key, target_url, filters)
86
- if data:
87
- df = pd.DataFrame(data)
88
  st.dataframe(df)
89
 
90
  # Reset functionality
 
3
  import requests
4
  import base64
5
 
 
 
6
  def get_backlinks(api_login, api_key, target_url, filters):
7
  # Encoding credentials
8
  encoded_credentials = base64.b64encode(f"{api_login}:{api_key}".encode()).decode()
 
27
 
28
  # Check if the response contains 'results' key
29
  if response.status_code == 200 and 'results' in response.json():
30
+ # Extract the results
31
+ results = response.json()['results']
32
+ # Convert results to DataFrame
33
+ df = pd.DataFrame(results)
34
+ return df
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}")
 
73
 
74
  # Generate CSV and download button
75
  if generate_button and target_url: # Check after target_url is defined
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")
 
 
 
86
  st.dataframe(df)
87
 
88
  # Reset functionality