Skip to content
This repository has been archived by the owner on Nov 12, 2020. It is now read-only.

Commit

Permalink
Make sure the server responds with an html page
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini committed Sep 12, 2017
1 parent 4763083 commit ca0c43d
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions telegramschoolbot/tasks.py
Expand Up @@ -29,7 +29,11 @@ def __init__(self, config, db):
def query_main_page(self):
response = requests.get(self.config["school_website"], headers=utils.REQUESTS_HEADERS)
if response.status_code != 200:
raise ValueError("Failed to query the main page, website responded with response code: %i" % (response.status_code,))
raise ValueError("Failed to query the main page, server responded with response code: %i" % (response.status_code,))

if "text/html" not in response.headers['Content-Type']:
print("Failed to query the main page, server responded with content type: %s" % (response.headers['Content-Type'],))
return None

parsed_html = BeautifulSoup(response.text, "html.parser")

Expand Down Expand Up @@ -64,7 +68,11 @@ def query_main_page(self):
def query_calendar_article(self, url):
response = requests.get(url, headers=utils.REQUESTS_HEADERS)
if response.status_code != 200:
raise ValueError("Failed to query the calendar article page, website responded with response code: %i" % (response.status_code,))
raise ValueError("Failed to query the calendar article page, server responded with response code: %i" % (response.status_code,))

if "text/html" not in response.headers['Content-Type']:
print("Failed to query the calendar article page, server responded with content type: %s" % (response.headers['Content-Type'],))
return None

# Find the url of the orario facile page
parsed_html = BeautifulSoup(response.text, "html.parser")
Expand All @@ -83,7 +91,11 @@ def query_calendar_article(self, url):
def query_calendar(self, url):
response = requests.get(url, headers=utils.REQUESTS_HEADERS)
if response.status_code != 200:
raise ValueError("Failed to query the calendar page, website responded with response code: %i" % (response.status_code,))
raise ValueError("Failed to query the calendar page, server responded with response code: %i" % (response.status_code,))

if "text/html" not in response.headers['Content-Type']:
print("Failed to query the calendar page, server responded with content type: %s" % (response.headers['Content-Type'],))
return None

pages = []
# Generate the list of pages about classes, teachers and classrooms
Expand Down

0 comments on commit ca0c43d

Please sign in to comment.