joshuadunlop commited on
Commit
b7d9073
·
verified ·
1 Parent(s): ba3ff9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -46,14 +46,6 @@ def get_backlinks(api_login, api_key, target_url, filters):
46
  st.error(f"Error: Code: {response.status_code} Message: {error_message}")
47
  return None
48
 
49
-
50
- # Function to add filter condition with logical operator
51
- def add_filter_condition(filters, condition, operator=None):
52
- if filters and operator:
53
- filters.append(operator)
54
- filters.append(condition)
55
- return filters
56
-
57
  # Streamlit layout
58
  st.sidebar.title("DataForSEO API Parameters")
59
  api_login = st.sidebar.text_input("API Login", value="[email protected]")
@@ -69,22 +61,26 @@ page_from_language = st.sidebar.selectbox("Page From Language", ['en', 'other'])
69
  # Prepare filters for API call
70
  filters = []
71
 
72
- # Applying filters with logical 'and' operator between them
73
  if url_from_not_contain:
74
  for url in url_from_not_contain.split(','):
75
- filters = add_filter_condition(filters, ["url_from", "not_like", url.strip()], "and")
 
76
 
77
  if is_lost:
78
- filters = add_filter_condition(filters, ["is_lost", "=", is_lost], "and")
 
79
 
80
  if dofollow:
81
- filters = add_filter_condition(filters, ["dofollow", "=", dofollow], "and")
 
82
 
83
- filters = add_filter_condition(filters, ["backlink_spam_score", "<=", backlink_spam_score], "and")
84
- filters = add_filter_condition(filters, ["page_from_language", "=", page_from_language])
 
85
 
86
- # Wrapping the entire filters in an outer list
87
- filters = [filters] if filters else []
 
88
 
89
  # Main app layout
90
  col1, col2 = st.columns(2)
 
46
  st.error(f"Error: Code: {response.status_code} Message: {error_message}")
47
  return None
48
 
 
 
 
 
 
 
 
 
49
  # Streamlit layout
50
  st.sidebar.title("DataForSEO API Parameters")
51
  api_login = st.sidebar.text_input("API Login", value="[email protected]")
 
61
  # Prepare filters for API call
62
  filters = []
63
 
 
64
  if url_from_not_contain:
65
  for url in url_from_not_contain.split(','):
66
+ filters.append(["url_from", "not_like", url.strip()])
67
+ filters.append("and")
68
 
69
  if is_lost:
70
+ filters.append(["is_lost", "=", is_lost])
71
+ filters.append("and")
72
 
73
  if dofollow:
74
+ filters.append(["dofollow", "=", dofollow])
75
+ filters.append("and")
76
 
77
+ filters.append(["backlink_spam_score", "<=", backlink_spam_score])
78
+ filters.append("and")
79
+ filters.append(["page_from_language", "=", page_from_language])
80
 
81
+ # Remove the last "and" if it's the last element
82
+ if filters and filters[-1] == "and":
83
+ filters.pop()
84
 
85
  # Main app layout
86
  col1, col2 = st.columns(2)