-
Notifications
You must be signed in to change notification settings - Fork 6
/
d3times.py
executable file
·51 lines (41 loc) · 1.69 KB
/
d3times.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
#!/usr/bin/env python
import optparse
import pytz # $ pip install pytz
from tzlocal import get_localzone # $ pip install tzlocal
import d3output # local module
from profiler import TimeProfiler # local module
opt_parser = optparse.OptionParser()
opt_parser.add_option("-t", "--timezone", type=str, default="",
help="output timezone (e.g. 'America/New_York' or 'local'; default: UTC)")
opt_parser.add_option('-a', '--aggregate', action='store_true', default=False,
help="Aggregate the values to produce key-value pairs with counts")
opt_parser.add_option("-o", "--output", dest="output", type="str",
help="html | csv | json (default: html)", default="html")
opt_parser.add_option("-p", "--template", dest="template", type="str",
help="name of template in utils/template (default: timebar.html)", default="timebar.html")
opt_parser.add_option("-i", "--interval", dest="intervalStr", type="str",
help="interval for grouping timestamps, in seconds, minutes or hours, e.g. 15M (default: 1S)", default="1S")
opts, args = opt_parser.parse_args()
aggregate = opts.aggregate
tzname = opts.timezone
# determine output time zone
if tzname == "":
tz = pytz.UTC
elif tzname == "local":
tz = get_localzone() # system timezone, from tzlocal
else:
tz = pytz.timezone(tzname)
# if an interval is provided in the options, use it; otherwise
# determine the interval from the datetime format
intervalStr = opts.intervalStr # e.g. 15M
profiler = TimeProfiler({
"tz": tz,
"output": opts.output,
"aggregate": aggregate,
"intervalStr": intervalStr})
profiler.gettweets(opts, args)
data = profiler.report()
if opts.output == "html":
d3output.embed(opts.template, data)
else:
print(data)