Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Updated- Comments added
Comments were added to show why certain steps in the code happened
- Loading branch information
Showing
1 changed file
with
14 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |