Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- from time import localtime
- from weather import Weather, Unit
- def getTemp( location_name):
- weather = Weather(unit=Unit.FAHRENHEIT)
- location = weather.lookup_by_location('dublin')
- return int(location.condition.temp)
- def koozie_decider(day_idx = localtime().tm_wday, day_hr = localtime().tm_hour, temp = None, location = 'dublin'):
- if temp == None:
- temp = getTemp( location)
- if day_idx > 4:
- drink_type = "It's the weekend - grab your favorite Beverage! :D"
- else:
- if 8 < day_hr < 17 :
- drink_type = "Dude it's past 5 somewhere - grab your favorite Beverage, but no Alcohol :( still at work!"
- else:
- drink_type = "Outside of working hours - grab your favorite drink! :D"
- need_kozi = "And it's hot out - grab a koozie, you're going to need one ASAP!" if temp > 71 else "And grab a koozie anyway - coz koozie is lub ;)"
- return drink_type, need_kozi
- drink_suggested, kozi_req = koozie_decider()
- print( drink_suggested, kozi_req, sep = '\n') #1
- drink_suggested, kozi_req = koozie_decider(location = 'sydney') # device on which this code is going to be executed is also in sydney.
- print( drink_suggested, kozi_req, sep = '\n') #2
- # order doesn't matters if you are passing arguements like this
- drink_suggested, kozi_req = koozie_decider(location = 'newyork', day_idx = 5, day_hr = 23, temp = None)
- print( drink_suggested, kozi_req, sep = '\n') #3
- '''
- output:
- 1
- Outside of working hours - grab your favorite drink! :D
- And grab a koozie anyway - coz koozie is lub ;)
- 2
- Outside of working hours - grab your favorite drink! :D
- And grab a koozie anyway - coz koozie is lub ;)
- 3
- It's the weekend - grab your favorite Beverage! :D
- And grab a koozie anyway - coz koozie is lub ;)
- '''
Add Comment
Please, Sign In to add comment