Fetching data from the weather website

We are going to add a class named Request that will be responsible for getting the data from the weather website. Let's add a file named request.py in the weatherterm/core directory with the following content:

import osfrom selenium import webdriverclass Request:    def __init__(self, base_url):        self._phantomjs_path = os.path.join(os.curdir,                                          'phantomjs/bin/phantomjs')        self._base_url = base_url        self._driver = webdriver.PhantomJS(self._phantomjs_path)    def fetch_data(self, forecast, area):        url = self._base_url.format(forecast=forecast, area=area)        self._driver.get(url)        if self._driver.title == '404 Not Found':            error_message = ('Could not find the area that you '                             'searching for') raise Exception(error_message) ...

Get Python Programming Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.