Debian Codegraph @

setup/file-hosting-bw.py

raw
1 #!/usr/bin/env python
2
3
4 __license__ = 'GPL v3'
5 __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
6
7 import os
8 import socket
9 import subprocess
10
11 BASE = '/srv/download/bw'
12
13
14 def main():
15 if not os.path.exists(BASE):
16 os.makedirs(BASE)
17 os.chdir(BASE)
18
19 for name in 'hours days months top10 summary'.split():
20 subprocess.check_call(['vnstati', '--' + name, '-o', name + '.png'])
21
22 html = '''\
23 <!DOCTYPE html>
24 <html>
25 <head><title>Bandwidth usage for {host}</title></head>
26 <body>
27 <style> .float {{ float: left; margin-right:30px; margin-left:30px; text-align:center; width: 500px; }}</style>
28 <h1>Bandwidth usage for {host}</h1>
29 <div class="float">
30 <h2>Summary</h2>
31 <img src="summary.png"/>
32 </div>
33 <div class="float">
34 <h2>Hours</h2>
35 <img src="hours.png"/>
36 </div>
37 <div class="float">
38 <h2>Days</h2>
39 <img src="days.png"/>
40 </div>
41 <div class="float">
42 <h2>Months</h2>
43 <img src="months.png"/>
44 </div>
45 <div class="float">
46 <h2>Top10</h2>
47 <img src="top10.png"/>
48 </div>
49 </body>
50 </html>
51 '''.format(host=socket.gethostname())
52
53 with open('index.html', 'wb') as f:
54 f.write(html.encode('utf-8'))
55
56
57 if __name__ == '__main__':
58 main()