Permalink
Browse files

Make sure the server responds with an html page

  • Loading branch information...
paolobarbolini committed Sep 12, 2017
1 parent 4763083 commit ca0c43d457ea18e261dbec43c49c0ee4054c707e
Showing with 15 additions and 3 deletions.
  1. +15 −3 telegramschoolbot/tasks.py
@@ -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")

@@ -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")
@@ -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

0 comments on commit ca0c43d

Please sign in to comment.