-
Notifications
You must be signed in to change notification settings - Fork 0
/
open file.py
60 lines (52 loc) · 2.17 KB
/
open file.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import csv
with open('/parsing/all_data_general_3.csv', 'r') as csvfile:
spamreader = csv.reader(csvfile, delimiter=';')
changed_str = ''
for page, string in enumerate(spamreader):
print(page, '...')
changed_attr = []
try:
group = string[8].split(',')
# print(group)
# print('\n')
for i, attr in enumerate(group):
count = 0
param = attr.split(':')
changed_param = []
changed = 0
# print(group)
for j in range(len(group)):
if param[0] == group[j].split(':')[0]:
count += 1
if count >= 1:
status = 1
if param[0] != ' ' or param[0] != '':
result = param[0] + str(count) + ':' + ':'.join(k for k in param[1:])
else:
continue
try:
changed_attr.index(result)
except:
for b in changed_attr:
if b.split(':')[1:] == param[1:] or b.split(':')[0] == param[0] + str(count):
status = 0
if status != 0:
changed_attr.append(result)
final = []
for k in changed_attr:
number = k.split(':')[0]
if number[-1] == '1':
result = number[:-1] + ':' + ':'.join(n for n in k.split(':')[1:])
else:
result = k
if result != ':':
final.append(result)
# print('result: ', final)
string.pop(8)
string.insert(8, ', '.join(v for v in final))
# print(string)
with open('/parsing/all_data_general_3(edit).csv', 'a', newline='') as f:
writer = csv.writer(f, delimiter=';')
writer.writerow(string)
except BaseException as e:
print(e)