codextj

koozie_decider

Oct 3rd, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | None | 0 0
  1. import datetime
  2. from time import localtime
  3. from weather import Weather, Unit
  4.  
  5. def getTemp( location_name):
  6.      weather = Weather(unit=Unit.FAHRENHEIT)
  7.      location = weather.lookup_by_location('dublin')
  8.      return int(location.condition.temp)
  9.  
  10. def koozie_decider(day_idx = localtime().tm_wday, day_hr = localtime().tm_hour, temp = None, location = 'dublin'):
  11.  
  12.      if temp == None:
  13.           temp = getTemp( location)
  14.          
  15.      if day_idx > 4:
  16.          drink_type = "It's the weekend - grab your favorite Beverage! :D"
  17.      else:
  18.          if 8 < day_hr < 17 :
  19.              drink_type = "Dude it's past 5 somewhere - grab your favorite Beverage, but no Alcohol :( still at work!"
  20.          else:
  21.              drink_type = "Outside of working hours - grab your favorite drink! :D"
  22.  
  23.      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 ;)"
  24.      
  25.      return drink_type, need_kozi
  26.  
  27. drink_suggested, kozi_req =  koozie_decider()
  28. print( drink_suggested, kozi_req, sep = '\n') #1
  29.  
  30. drink_suggested, kozi_req =  koozie_decider(location = 'sydney') # device on which this code is going to be executed is also in sydney.
  31. print( drink_suggested, kozi_req, sep = '\n') #2
  32.  
  33. # order doesn't matters if you are passing arguements like this
  34. drink_suggested, kozi_req =  koozie_decider(location = 'newyork', day_idx = 5, day_hr = 23, temp = None)
  35. print( drink_suggested, kozi_req, sep = '\n') #3
  36.  
  37. '''
  38. output:
  39. 1
  40.     Outside of working hours - grab your favorite drink! :D
  41.     And grab a koozie anyway - coz koozie is lub ;)
  42. 2    
  43.     Outside of working hours - grab your favorite drink! :D
  44.     And grab a koozie anyway - coz koozie is lub ;)
  45. 3    
  46.     It's the weekend - grab your favorite Beverage! :D
  47.     And grab a koozie anyway - coz koozie is lub ;)
  48.  
  49. '''
Add Comment
Please, Sign In to add comment