-
Notifications
You must be signed in to change notification settings - Fork 1
/
converter.py
35 lines (26 loc) · 989 Bytes
/
converter.py
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
from pathlib import Path
import sys
import csv
if len(sys.argv) < 3 :
print("arguments length is under 1. input string to argument for convert.")
sys.exit()
if len(sys.argv) > 3 :
print("arguments length is over 3. input two string to argument for convert.")
sys.exit()
print('file name : '+str(sys.argv[1]))
pathString ='./csv/'+str(sys.argv[1])
argvSplit = str(sys.argv[1]).split('.')
writePath = './csv/'+argvSplit[0]+'2.'+argvSplit[1]
path = Path(pathString)
if path.exists() == False:
print(path+" is doesn't exist file")
sys.exit()
with open(pathString, newline='') as csvfile:
spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
for row in spamreader:
split = ' '.join(row).split(',,,,NNP,지명')
split2 = split[1].split(',*,*,*,')
convertedPart = split2[0].replace(split[0],str(sys.argv[2]))+',*,*,*,'+split2[1]
converted = split[0]+',,,,NNP,지명'+convertedPart
with open(writePath, 'a', newline='') as file:
file.write(converted+'\n')