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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -4,6 +4,7 @@ import requests
4
  import base64
5
 
6
  # Function to call the DataForSEO API with Basic Authentication
 
7
  def get_backlinks(api_login, api_key, target_url, filters):
8
  # Encoding credentials
9
  encoded_credentials = base64.b64encode(f"{api_login}:{api_key}".encode()).decode()
@@ -26,10 +27,12 @@ def get_backlinks(api_login, api_key, target_url, filters):
26
  # Making the API request
27
  response = requests.post("https://api.dataforseo.com/v3/backlinks/backlinks/live", json=post_data, headers=headers)
28
 
29
- if response.status_code == 200:
 
30
  return response.json()['results']
31
  else:
32
- st.error(f"Error: Code: {response.status_code} Message: {response.json().get('status_message')}")
 
33
  return None
34
 
35
  # Streamlit layout
@@ -78,7 +81,11 @@ if generate_button and target_url: # Check after target_url is defined
78
 
79
  with col2:
80
  st.header("Output")
81
- # [Your code for displaying output]
 
 
 
 
82
 
83
  # Reset functionality
84
  if reset_button:
 
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()
 
27
  # Making the API request
28
  response = requests.post("https://api.dataforseo.com/v3/backlinks/backlinks/live", json=post_data, headers=headers)
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}")
36
  return None
37
 
38
  # Streamlit layout
 
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
91
  if reset_button: