mirror of
https://github.com/toxic-repos/toxic-repos
synced 2024-10-18 09:40:21 +03:00
update .gitignore & add some .py
This commit is contained in:
parent
6a5d7c7d73
commit
31193157a5
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,4 +1,2 @@
|
||||
.idea/
|
||||
src/
|
||||
converter.py
|
||||
txt-converter.py
|
||||
src/
|
29
utils/converter.py
Normal file
29
utils/converter.py
Normal file
@ -0,0 +1,29 @@
|
||||
import json
|
||||
|
||||
infile = "*.txt"
|
||||
outfile = "*.json"
|
||||
|
||||
dict1 = {}
|
||||
fields = ["datetime", "problemtype", "productname", "url", "comment"]
|
||||
with open(infile, 'r', encoding='utf-8') as fh:
|
||||
l = 1
|
||||
|
||||
for line in fh:
|
||||
description = list(line.strip().split('\t', 4))
|
||||
|
||||
print(description)
|
||||
|
||||
sno = 'field' + str(l)
|
||||
|
||||
i = 0
|
||||
dict2 = {}
|
||||
while i < len(fields):
|
||||
dict2[fields[i]] = description[i]
|
||||
i = i + 1
|
||||
|
||||
dict1[sno] = dict2
|
||||
l = l + 1
|
||||
|
||||
out_file = open(outfile, 'w', encoding='utf-8')
|
||||
json.dump(dict1, out_file, indent='\t')
|
||||
out_file.close()
|
29
utils/txt-converter.py
Normal file
29
utils/txt-converter.py
Normal file
@ -0,0 +1,29 @@
|
||||
import json
|
||||
|
||||
infile = "clean.txt"
|
||||
outfile = "clean.json"
|
||||
|
||||
dict1 = {}
|
||||
fields = ["datetime", "productname", "url"]
|
||||
with open(infile, 'r', encoding='utf-8') as fh:
|
||||
l = 1
|
||||
|
||||
for line in fh:
|
||||
description = list(line.strip().split('\t', 4))
|
||||
|
||||
print(description)
|
||||
|
||||
sno = 'field' + str(l)
|
||||
|
||||
i = 0
|
||||
dict2 = {}
|
||||
while i < len(fields):
|
||||
dict2[fields[i]] = description[i]
|
||||
i = i + 1
|
||||
|
||||
dict1[sno] = dict2
|
||||
l = l + 1
|
||||
|
||||
out_file = open(outfile, 'w', encoding='utf-8')
|
||||
json.dump(dict1, out_file, indent='\t')
|
||||
out_file.close()
|
Loading…
Reference in New Issue
Block a user