forked from GFDRR/osm-extract
-
Notifications
You must be signed in to change notification settings - Fork 2
/
stats.py
50 lines (42 loc) · 1.71 KB
/
stats.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
import click
import json
import time
import os
actions="""
var result="%s";
document.write(result);
"""
extentions = ['sql.zip', 'pbf', 'shp.zip', 'json', 'kml']
def sizeof_fmt(num, suffix='B'):
for unit in ['','K','M','G','T','P','E','Z']:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Yi', suffix)
@click.command()
@click.option('--files', help='Filenames.')
@click.option('--name', help='Project Name.')
def stats(name, files):
"""Simple program that generates stats for OSM exports"""
files = files.split(" ")
data = {}
out = "<ul>"
for table in sorted(files):
out = out + "<li><span class='name'>%s</span> " % table.title().replace("_", " ")
files = {}
for extention in extentions:
filename = "%s/%s.%s" % (name, table, extention)
size = os.path.getsize(filename)
date = time.ctime(os.path.getmtime(filename))
download = '%s' % filename.replace(name + '/', '')
files[extention] = ('data/%s' % filename, size, date)
out = out + "<div class='box'>| <a href='%s'>%s</a> <span class='size'>%s</span></div>" % (download, extention.upper(), sizeof_fmt(size))
gpkg_filename = "%s/%s.gpkg" % (name, name)
gpkg_size = os.path.getsize(gpkg_filename)
gpkg_download = '%s' % gpkg_filename.replace(name + '/', '')
out = out + "<div class='box'>| <a href='%s'>%s</a> <span class='size'>%s</span></div>" % (gpkg_download, 'GPKG', sizeof_fmt(gpkg_size))
out = out + "| %s</li>" % date
out= out + "</ul>"
click.echo(actions % out)
if __name__ == '__main__':
stats()