Skip to content

Commit

Permalink
added timeout parameters to every request to ensure stability
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenOrcan committed Mar 3, 2024
1 parent a36a03a commit 44d7d84
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion yirabot/data_extraction_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def parse_sitemap(url, script=False):
# Attempt to parse standard sitemaps
for sitemap_url in sitemap_urls:
try:
response = requests.get(sitemap_url)
response = requests.get(sitemap_url, timeout=10)
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'xml')
return [element.text for element in soup.find_all("loc")]
Expand Down
8 changes: 4 additions & 4 deletions yirabot/seo_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

def check_website_language(url):
try:
response = requests.get(url)
response = requests.get(url, timeout=10)
soup = BeautifulSoup(response.content, 'html.parser')

html_tag = soup.find('html')
Expand All @@ -34,7 +34,7 @@ def check_website_language(url):

def check_social_media_integration(url):
try:
response = requests.get(url)
response = requests.get(url, timeout=10)
soup = BeautifulSoup(response.content, 'html.parser')

social_media = {
Expand Down Expand Up @@ -83,7 +83,7 @@ def check_link_status(url, session=None):
Returns a tuple of (is_broken, status_code, reason).
"""
try:
response = session.head(url, allow_redirects=True) if session else requests.head(url, allow_redirects=True)
response = session.head(url, allow_redirects=True, timeout=10) if session else requests.head(url, allow_redirects=True, timeout=10)
if response.status_code == 404:
return True, 404, "Not Found"
elif 300 <= response.status_code < 400:
Expand Down Expand Up @@ -172,7 +172,7 @@ def analyze_images_for_alt_text(soup):
def seo_error_analysis(url, session=None):
try:
print("YiraBot: Starting SEO Analysis")
response = session.get(url) if session else requests.get(url)
response = session.get(url, timeout=10) if session else requests.get(url, timeout=10)
soup = BeautifulSoup(response.content, 'html.parser')

title_length, title_status = analyze_title(soup)
Expand Down

0 comments on commit 44d7d84

Please sign in to comment.