diff --git a/alternativeWeather.py b/alternativeWeather.py index 830c23c..93518ac 100644 --- a/alternativeWeather.py +++ b/alternativeWeather.py @@ -1,15 +1,26 @@ -from selenium import webdriver +#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() - #city = str(input("Which city would you like me to check?")).lo 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() + 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)