-
Notifications
You must be signed in to change notification settings - Fork 0
/
timelineDay
executable file
·37 lines (32 loc) · 1.48 KB
/
timelineDay
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
#!/usr/bin/env python3
import sys
from mcserverstats import logalyzer, timeline, timeutils
if len(sys.argv) <= 2:
print('Usage: %s <path/to/logs> <path/to/output> [<from-date> [to-date]]' % sys.argv[0])
print(' date format is "YYYY-MM-DD" or "YYYY-MM-DD HH:MM:SS"')
print(' output can be *.png or *.html, get timeline from...')
print(' - no dates: the 24h before the last log event,')
print(' - from only: the 24h after that date,')
print(' - from and to: time between from and to, to is exclusive')
sys.exit(0)
logs = logalyzer.LogDirectory(sys.argv[1])
out_path = sys.argv[2]
from_date = timeutils.add_to_date_str(
timeutils.latest_log_date_str(logs.logs_dir), days=-1)
to_date = None
if len(sys.argv) > 3:
from_date = timeutils.ensure_full_date(sys.argv[3])
to_date = timeutils.add_to_date_str(from_date, days=1)
if len(sys.argv) > 4:
to_date = timeutils.ensure_full_date(sys.argv[4])
title = '%s to %s' % (timeutils.human_date_str(from_date),
timeutils.human_date_str(to_date) or 'last activity')
print('Creating timeline', '"%s"' % title, 'as', out_path)
timeline_data = timeline.get_timeline_data(logs, from_date, to_date)
out_type = out_path.lower().rsplit('.', 1)[-1]
if out_type in ('html', 'htm'):
timeline.write_timeline_html_page(timeline_data, out_path, title)
elif out_type == 'png':
timeline.draw_timeline(timeline_data, out_path, title)
else:
print('Error: Unknown output type', out_type, file=sys.stderr)