-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv to bz2
36 lines (22 loc) · 804 Bytes
/
csv to bz2
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
csvfile = input("Copy the csv file name here\n")
with open(csvfile, 'rb') as infile:
csv_bytes = infile.read()
import bz2
bz2file = csvfile + '.bz2'
# Compress the csv file into bz2
with bz2.BZ2File(bz2file, 'w') as outfile:
outfile.write(csv_bytes)
# CSV Meta File Generation
import csv
metafile = csvfile[0:-4] + '.meta.csv'
count = len(open(csvfile).readlines())
import hashlib
with open(bz2file, 'rb') as bz2:
byte = bz2.read()
readable_hash = hashlib.sha256(byte).hexdigest()
# generate the meta json file
with open(metafile, 'w', newline = '') as outmeta:
meta = ['META', 'false', csvfile, '', csvfile, '2.2.1',
bz2file + '@' + str(count) + '@@' + readable_hash, ""]
writer = csv.DictWriter(outmeta, fieldnames = meta)
writer.writeheader()