sort functions alphabetically and handle rate limit more gracefully

This commit is contained in:
Marco Lents 2025-11-15 15:35:11 +01:00
parent 3f0130c75b
commit be2371e0f5

View file

@ -112,7 +112,7 @@ def funcs_to_str(funcs):
out = "" out = ""
for func in funcs: for func in funcs:
out += f"\n- {func[0]}" out += f"\n- {func[0]}"
for loc in func[1]: for loc in sorted(func[1]):
out += f"\n - {loc}" out += f"\n - {loc}"
return out return out
@ -184,7 +184,12 @@ def get_bio(url, name, sleep_for):
name, party = name name, party = name
name = name.split(", ") name = name.split(", ")
print(f"Getting {url} for {name[1]} {name[0]}") print(f"Getting {url} for {name[1]} {name[0]}")
for _ in range(5):
try:
response = requests.get(url) response = requests.get(url)
except:
print("Rate limit! waiting 5min")
sleep(300)
soup = BeautifulSoup(response.content) soup = BeautifulSoup(response.content)
cv = soup.find(class_="m-biography__biography").text.strip() cv = soup.find(class_="m-biography__biography").text.strip()
ajax_divs = soup.find_all(class_="m-ajaxLoadedContent") ajax_divs = soup.find_all(class_="m-ajaxLoadedContent")
@ -314,7 +319,13 @@ def get_ajax(elem):
for key, value in filters.items() for key, value in filters.items()
] ]
url = url + "?" + "&".join(f"{key}={val}" for key, val in sanitized_filters) url = url + "?" + "&".join(f"{key}={val}" for key, val in sanitized_filters)
return requests.get(url) for _ in range(5):
try:
response = requests.get(url)
except:
print("Rate limit! waiting 5min")
sleep(300)
return response
def common_suffix(strings): def common_suffix(strings):