-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextractor.py
More file actions
41 lines (25 loc) · 878 Bytes
/
extractor.py
File metadata and controls
41 lines (25 loc) · 878 Bytes
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
import sys
import time
import tarfile
from ast import literal_eval
filename = sys.argv[1]
out_filename = filename.replace(".tar.gz", ".txt")
out_f_p = open(out_filename, "wt")
start_time = time.time()
with tarfile.open(filename, "r:gz") as f_p:
members = f_p.getmembers()
print("Extracting:", members)
assert len(members) == 1
extracted_file = f_p.extractfile(members[0])
file_content = extracted_file.read().decode('utf-8')
file_content = file_content.replace("}{'url'", "}\n{'url'")
for line in file_content.split("\n"):
try:
data = literal_eval(line)
language_score = data["language_score"]
if language_score > 0.98:
out_f_p.write(line + "\n")
except:
continue
print("Extraction took:", round(time.time() - start_time, 2), "seconds.")
out_f_p.close()