#! /usr/bin/env python3 # Time-stamp: <2019-07-18 15:12:18 christophe@pallier.org> """ take a list of tables (.tsv, .csv, .rds, ... ) as arguments and generates the embryon of the json file for openlexicon. """ import os import sys import hashlib def md5(fname): hash_md5 = hashlib.md5() with open(fname, "rb") as f: for chunk in iter(lambda: f.read(4096), b""): hash_md5.update(chunk) return hash_md5.hexdigest() HEADER=""" { "_comment": "generated by create_json.py", "name": "XXXX", "description": "XXXXXX", "website": "XXXXXX", "readme": "XXXXXX", "urls" : [ """ FOOTER=""" ], "type": "tsv", "tags": [] } """ if __name__ == '__main__': print(HEADER, end='') first = True for fname in sys.argv[1:]: md5sum = md5(fname) nbytes = os.path.getsize(fname) url = "http://www.lexique.org" + os.path.abspath(fname).replace('/var/www','') if not first: print(',') first = False print(' {') print(f' "url": "{url}",') print(f' "bytes": {nbytes},') print(f' "md5sum": "{md5sum}"') print(' }',end='') print(FOOTER)