-
Notifications
You must be signed in to change notification settings - Fork 2
/
bonus.py
83 lines (67 loc) · 2.19 KB
/
bonus.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
80
81
82
83
#!/usr/bin/env python3
import json
from padutil import output_table
import limited_bonus_data
from limited_bonus_data import Bonus
import dungeon_data
def tolist(self):
# lst = list(map(lambda dt: dt.strftime('%Y%m%d_%H:%M:%S'), (self.s, self.e)))
# lst = list(map(DT.isoformat, (self.s, self.e)))
duration = self.e - self.s
lst = [self.s.strftime('%Y%m%d_%H:%M:%S'), duration_to_string(duration)]
for k in Bonus.keys[2:]:
if hasattr(self, k):
lst.append(getattr(self, k))
else:
lst.append('')
return lst
def show_timediff(start, end):
"""Given start and end time, show the differences.
E.g.
- If start and end are in the same Time, but different Date, show the new date.
+ Date:
- If same month, but different day, show the day.
- If different month, show both month and day.
+ Time:
- If different hour, show hours.
! Coin dungeon bonuses are an hour longer than event.
"""
def duration_to_string(duration):
"""Output a timedelta in a useful format.
"""
days = duration.days
seconds = duration.seconds
assert not duration.microseconds
# assert bool(days) == (not seconds)
# if bool(days) != (not seconds):
# days, seconds = 0, days*24*60*60 + seconds
hours, seconds = divmod(seconds, 60*60)
#assert seconds == 0
s = ''
s += "%4dD" % days if days else ' '*5
s += "%4dH" % hours if hours else ' '*5
return s
# if days:
# return "%4dD" % days
# else:
# hours, seconds = divmod(seconds, 60*60)
# assert seconds == 0
# return "%4dH" % hours
def main():
try:
import sys
try:
fname = sys.argv[1]
except IndexError:
fname = 'bonus.in'
with open(fname) as f:
j = json.load(f)
data = j['bonuses']
limited_bonus_data.dungeons = dungeon_data.load()
output_table(map(tolist, map(Bonus, data)), fpath='bonus.out')
except:
import atexit
atexit.register(input, 'Press Enter to continue...')
raise
if __name__ == '__main__':
main()