-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_message.py
executable file
·79 lines (60 loc) · 2.29 KB
/
build_message.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# encoding: utf-8
from yr import *
import numpy as np
import datetime
import math
def build_sentence(sets, triangular=False):
lengths = map(lambda wordset: len(wordset), sets)
if triangular:
random = map(lambda length: int(np.random.triangular(0, 0, length)), lengths)
else:
random = map(lambda length: np.random.randint(0, high=length), lengths)
sentence = map(lambda (index, wordset): wordset[random[index]], enumerate(sets))
return "".join(sentence)
def add_space(s):
return s + " "
def add_comma(s):
return s + ", "
def add_shout(s):
return s + "! "
def add_dot(s):
return s + ". "
def greeting():
now = datetime.datetime.now()
greetings = map(add_space, ["Good morning", "Rise and shine", "Wake up"])
titles = map(add_shout, ["Sir", "Master", "Hero", "Commander", "Handsome", "Great leader", "Comrade"])
extras = map(add_space, ["I hope you slept well.", "How are you today?", "I honestly thought you were dead."])
if int(now.minute) is 0:
time = ["The time is {} o clock. ".format(now.hour)]
else:
time = ["The time is {} minutes past {}. ".format(now.minute, now.hour)]
return build_sentence([greetings, titles, extras, time], triangular=True)
def forecast(report):
temp = report[2]
weather_type = report[3]
rain_amount = report[4]
wind_type = report[5]
wind_speed = report[6]
message = ""
if temp < 0:
message += "You better turn the heat up, because the temperature is expected to reach {} degrees. ".format(temp)
else:
message += "Todays forecast for Oslo is {} degrees. ".format(temp)
if "rain" in weather_type.lower() or "snow" in weather_type.lower():
if rain_amount > 4:
message += "Best bring your umbrella today. "
message += "Expect around {} mm of {}. ".format(rain_amount, weather_type)
else:
message += "Expect a {} weather type today. ".format(weather_type)
message += "The weather is accompanied with a {} of {} m/s. " .format(wind_type, wind_speed)
return message
def news():
message = "Here's your favorite radio channel."
return message
def wake():
message = greeting()
morning = weather_update("Oslo", 9, 00)
message += forecast(morning)
message += news()
return message
print "\"" + wake() + "\""