Advertisement
acclivity

pyWeatherReports

Jan 27th, 2022
1,159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.41 KB | None | 0 0
  1. w_data = [{'date': ['may','mon',2],'temp': [20,10,12],'cover':[90,30,'N',15]},
  2.           {'date': ['june','tues',21],'temp': [28,14,17],'cover':[30,2,'W',5]},
  3.           {'date': ['july','wednes',20],'temp': [32,21,24],'cover':[0,0,'S',2]},
  4.           {'date': ['august','thurs',25],'temp': [36,24,26],'cover':[0,0,'W',1]}]
  5.  
  6. greetings = ["G'Day all. ", "Hello Campers! ", "Hello you lucky people! ", "Good Day fellow sufferers. "]
  7.  
  8. midlist = ["It's rather a cool day, only reaching %s degrees. \n",
  9.            "It'll be warm and humid today, reaching %s degrees! \n",
  10.            "Here comes the sun! Expect temperatures up to %s degrees. \n",
  11.            "It's a belter today! Better cover up as the temperatures could reach %s degrees! \n"]
  12.  
  13. for adict in w_data:
  14.     month, day, daynum = adict['date']
  15.     tempmax, tempmin, tempmid = adict['temp']
  16.     cloudmax, cloudmin, windir, winspeed = adict['cover']
  17.  
  18.     suffix = "th"
  19.     if daynum in [1, 21, 31]:
  20.         suffix = "st"
  21.     if daynum in [2, 22]:
  22.         suffix = "nd"
  23.     if daynum in [3, 23]:
  24.         suffix = "rd"
  25.  
  26.     idx1 = 0
  27.     if tempmax > 33:
  28.         idx1 = 3
  29.     elif tempmax > 30:
  30.         idx1 = 2
  31.     elif tempmax > 25:
  32.         idx1 = 1
  33.  
  34.     daydict = {"mon": "back-to-work Monday,", "tue": "Tuesday,", "wed": "Wednesday, yep, mid-week,",
  35.                "thu": "Thursday, weekend is coming!",
  36.                "fri": "Friday,", "sat": "Saturday. Enjoy your weekend!", "sun": "stay-in-bed Sunday,"}
  37.     daykey = day[:3].lower()
  38.     dayfull = daydict[daykey]
  39.  
  40.     msgcloud = "Expect a large amount of cloud cover. \n"
  41.     if cloudmax < 50:
  42.         msgcloud = "But there will be a few clouds around. \n"
  43.     if cloudmax < 25:
  44.         msgcloud = "There may be the odd cloud to be seen.\n"
  45.     if cloudmax < 10:
  46.         msgcloud = "And not a cloud in the sky! \n"
  47.  
  48.     msgwind = "It will be breezy, with winds from the %s.\n"
  49.     if winspeed < 15:
  50.         msgwind = "Winds will be very light, coming from the %s.\n"
  51.     if winspeed < 5:
  52.         msgwind = "It will be very still, with hardly a breeze to refresh us from the %s. \n"
  53.  
  54.     windict = {"N": "north", "E": "east", "S": "south", "W": "west"}
  55.     wind = windict[windir]
  56.  
  57.     msg = greetings[idx1]
  58.     msg += "Today is " + dayfull + " " + month.title() + " " + str(daynum) + suffix + ",\n"
  59.     msg += midlist[idx1]
  60.     msg += msgcloud
  61.     msg += msgwind
  62.     print(msg % (tempmax, wind))
  63.  
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement