-
Notifications
You must be signed in to change notification settings - Fork 6
/
reportprofile.py
executable file
·49 lines (40 loc) · 1.47 KB
/
reportprofile.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
#!/usr/bin/env python
import json
import optparse
from profiler import Profiler # local module
from dateutil import parser
import sparkline
import os
from mako.template import Template
import glob
import sys
import re
import humanize
opt_parser = optparse.OptionParser()
opt_parser.add_option("-o", "--output", dest="output", type="str",
help="text | json | html (default: text)", default="text")
opts, args = opt_parser.parse_args()
profiler = Profiler({"extended": True, "blocks": ["all"]})
profiler.gettweets(opts, args)
data = profiler.report()
if (opts.output == "json"):
print(json.dumps(data))
elif (opts.output == "html"):
metadata_file = os.path.join(os.path.dirname(args[0]), "../metadata.json")
with open(metadata_file) as json_data:
metadata = json.load(json_data)
json_data.close()
data['title'] = metadata['title']
data['search'] = metadata['search']
# gather names and sizes of html files
data['reports'] = []
p = re.compile('.*\/html\/(.*)\.html')
for report in sorted(glob.glob(os.path.join(os.path.dirname(args[0]), "../html/*.html"))):
m = p.match(report)
size = os.path.getsize(report)
data['reports'].append({'report': m[1], 'size': humanize.naturalsize(size)})
mytemplate = Template(filename='templates/reportprofile.html')
print(mytemplate.render(data = data))
else:
mytemplate = Template(filename='templates/reportprofile.txt')
print(mytemplate.render(data = data))