-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhdn.py
More file actions
61 lines (55 loc) · 1.68 KB
/
Copy pathhdn.py
File metadata and controls
61 lines (55 loc) · 1.68 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class Parser:
def __init__(self, file):
self.file = file
def parse(self):
file = open(self.file, 'r').read()
items = []
lines = []
word = ''
gather_item = False
index = 0
for x in file:
if x == '"' and gather_item is False:
gather_item = True
elif x == '"' and gather_item is True:
if file[index + 1] == ',':
gather_item = False
items.append(word)
word = ''
else:
word += x
elif gather_item:
word += x
elif x == ';':
lines.append(items)
items = []
index += 1
return lines
def write_in_hdn(self, lines):
file_str = ''
for line in lines:
for word in line:
hdn_word = f'"{word}"'
file_str += hdn_word + ','
file_str += ';'
return file_str
def dump(self, hdn, file):
hdn_file = open(file, 'w')
hdn_file.write(hdn)
hdn_file.close()
def replace_value(self, original, final):
lines = self.parse()
for line in lines:
index = 0
for item in line:
if item == original:
line[index] = final
index += 1
print(lines)
hdn_str = self.write_in_hdn(lines)
self.dump(hdn_str, self.file)
def append(self, lines):
lines_hdn_str = self.write_in_hdn(lines)
hdn_file = open(self.file, 'a')
hdn_file.write(lines_hdn_str + '\n')
hdn_file.close()