currentWeather()

Programming Language: Python 3 (As of Jan 2022)

Description


Travel() must be initialized first before calling currentWeather(). This function connects to Google.com to grab the F and C temperature values. The location is concatenated with the URL variable that is in the function. Example of URL variable: "https://www.google.com/search?q=weather+" + self.location +"+March+20+-+March+21". This currently only gets the weather for one day. In the future, this can be for a specifc day.

Parameters


self (None; however read description)

  Values of these must be a string of a correctly spelled location.

  From, To: string needs to be a city or IATA Code

Calling Example


        
            atlanta.currentWeather()
        
        
    

Class Code


        
            def currentWeather():
              URL = ""https://www.google.com/search?q=weather+" + self.location +"+March+20+-+March+21"
              headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0'}
              page = requests.get(URL, headers=headers)
              soup = BeautifulSoup(page.content, "html.parser")
              location_site_string = soup.find('div', class_='vk_bk TylWce')
              f_weather = soup.find('span',id = 'wob_tm')
              c_weather = soup.find('span', id = 'wob_ttm')
              location_name = soup.find('div', id = 'wob_loc')
              print( location_name.text)
              print ("Fahrenheit:",f_weather.text)
              print ('Celsius:',c_weather.text)
              print('\n')
        
    

Additional Information


Access to internet is needed to run this function when called.