Skip to content
Permalink
Browse files
Updated- Comments added
Comments were added to show why certain steps in the code happened
  • Loading branch information
mirikip committed Nov 28, 2018
1 parent c22b16f commit 624d674a8cda97f50f6050f3a5addcf8e7f15372
Showing 1 changed file with 14 additions and 3 deletions.
@@ -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)

0 comments on commit 624d674

Please sign in to comment.