-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrandline.py
41 lines (35 loc) · 951 Bytes
/
randline.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
import random
import sys
import datetime
def timeOfDay(time):
if time.hour <= 2 or time.hour >= 18:
return 'evening'
elif time.hour <= 12:
return 'morning'
else:
return 'afternoon'
def dayOrNight(time):
if time.hour <= 4 or time.hour >= 20:
return 'night'
else:
return 'day'
def todayOrTonight(time):
if time.hour <= 4 or time.hour >= 20:
return 'tonight'
else:
return 'today'
def dayOfWeek(time):
return time.strftime('%A')
def main():
lines = open(sys.argv[1]).readlines()
name = sys.argv[2] if len(sys.argv) > 2 else 'stranger'
now = datetime.datetime.now()
print(lines[random.randrange(len(lines))].strip() % {
'timeOfDay': timeOfDay(now),
'dayOrNight': dayOrNight(now),
'todayOrTonight': todayOrTonight(now),
'dayOfWeek': dayOfWeek(now),
'name': name
})
if __name__ == "__main__":
main()