update .gitignore & add some .py

This commit is contained in:
askazin 2022-03-24 15:30:30 +03:00
parent 6a5d7c7d73
commit 31193157a5
3 changed files with 59 additions and 3 deletions

4
.gitignore vendored
View File

@ -1,4 +1,2 @@
.idea/
src/
converter.py
txt-converter.py
src/

29
utils/converter.py Normal file
View 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
View 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()