-
Notifications
You must be signed in to change notification settings - Fork 134
/
gen-json.py
31 lines (25 loc) · 1.05 KB
/
gen-json.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
#!/usr/bin/python
import os, argparse, json, time, sys
from datetime import datetime
from collections import OrderedDict
now = datetime.now()
directory = sys.argv[1]
filelist = os.listdir(directory)
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)
def modification_date(filename):
t = os.path.getmtime(filename)
return t
files_json = {"data":[]}
for item in filelist:
full_path = "{}/{}".format(directory, item)
num_lines = sum(1 for line in open(full_path))
file_size = sizeof_fmt(os.path.getsize(full_path))
modification_time = modification_date(full_path)
obj = OrderedDict([("Filename", item), ("Line Count", num_lines), ("File Size", file_size), ("Date", modification_time), ("Download", "<a href='https://wordlists-cdn.assetnote.io/{0}{1}'>Download</a>".format(directory, item))])
files_json["data"].append(obj)
print(json.dumps(files_json,indent=4,ensure_ascii=False))