Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#Programmed by Premo
#Simple weather program gets the current temperature in a given city directly
#from a given website and returns the information it found from a given part
#of the same website
from selenium import webdriver
#Selenium web driver imported
def weather(city):
#The instance of chrome Web driver is created
driver = webdriver.Chrome()
day = str(input("What day would you like to know the forecast for?")).lower()
#driver will get
driver.get("https://www.timeanddate.com/weather/uk/"+city+"")
#Program can only get weather forecast for the day if the day is not today it will return nothing
if "today" in day:
#the element we require will be found by its class name which we have defined
#the class name can be located by inspecting html source of the webpage
#and finding the relevant region
return("It is " + driver.find_elements_by_class_name("h2")[0].text + " now.")
else:
return None
#Prompts the user to put in a given city which will be used in the function defined above
city = str(input("Which city would you like me to check?")).lower()
weather(city)