프로젝트

일반

사용자정보

통계
| 개정판:

hytos / minorTools / xmlTextSearcher.py @ 26ffe3d3

이력 | 보기 | 이력해설 | 다운로드 (3.43 KB)

1
import os
2

    
3
def finder():
4
    print("finder start")
5
    
6
    targetText = ['t strainer<']
7
    path = 'W:\ID2_Project\POSCO\Temp'
8

    
9
    print("target : " + str(len(targetText)))
10
    print("path : " + path)
11

    
12
    start = input("start enter 1 : ")
13
    if start != '1':
14
        return
15

    
16
    xmlList = os.listdir(path)
17
    nonXmlList = []
18

    
19
    for index in range(len(xmlList)):
20
        if xmlList[index][-3:] != 'xml':
21
            nonXmlList.append(index)
22

    
23
    nonXmlList.sort(reverse=True)
24
    for index in nonXmlList:
25
        xmlList.pop(index)
26

    
27
    for xml in xmlList:
28
        xmlPath = os.path.join(path, xml)
29
        fw = open(xmlPath, 'r', encoding='utf8')
30
        xmlCon = fw.read()
31
        fw.close()
32

    
33
        number = 0
34
        for target in targetText:
35
            while xmlCon.find(target) != -1:
36
                xmlCon = xmlCon.replace(target, '', 1)
37
                number += 1
38

    
39
        if number > 0:
40
            print("drawing : " + xml)
41
            print("count : " + str(number))
42
            print("")
43

    
44

    
45
def changer():
46
    print("changer start")
47
    
48
    originText = 'kg/cm&#178;g'
49
    newText = ''
50
    path = 'W:\ID2_Project\POSCO\Temp'
51
    
52
    print("origin : " + originText)
53
    print("new : " + newText)
54
    print("path : " + path)
55

    
56
    start = input("start enter 1 : ")
57
    if start != '1':
58
        return
59

    
60
    xmlList = os.listdir(path)
61
    nonXmlList = []
62

    
63
    for index in range(len(xmlList)):
64
        if xmlList[index][-3:] != 'xml':
65
            nonXmlList.append(index)
66

    
67
    nonXmlList.sort(reverse=True)
68
    for index in nonXmlList:
69
        xmlList.pop(index)
70

    
71
    for xml in xmlList:
72
        xmlPath = os.path.join(path, xml)
73
        fw = open(xmlPath, 'r', encoding='utf8')
74
        xmlCon = fw.read()
75
        fw.close()
76

    
77
        xmlCon = xmlCon.replace(originText, newText)
78

    
79
        fw = open(xmlPath, 'w', encoding='utf8')
80
        fw.write(xmlCon)
81
        fw.close()
82

    
83

    
84
def adder():
85
    import re
86
    print("changer_2 start")
87
    
88
    findingText = 'Freeze="True" Length="" UID="81400489-ef7f-40f3-855f-256c2ffc7329">'
89
    distance = 0
90
    addingText = 'SP-'
91
    aboid = 'SP'
92
    path = 'W:\ID2_Project\REB\Temp'
93
    
94
    print("finding : " + findingText)
95
    print("distance : " + str(distance))
96
    print("adding : " + addingText)
97
    print("path : " + path)
98

    
99
    start = input("start enter 1 : ")
100
    if start != '1':
101
        return
102

    
103
    xmlList = os.listdir(path)
104
    nonXmlList = []
105

    
106
    for index in range(len(xmlList)):
107
        if xmlList[index][-3:] != 'xml':
108
            nonXmlList.append(index)
109

    
110
    nonXmlList.sort(reverse=True)
111
    for index in nonXmlList:
112
        xmlList.pop(index)
113

    
114
    for xml in xmlList:
115
        xmlPath = os.path.join(path, xml)
116
        fw = open(xmlPath, 'r', encoding='utf8')
117
        xmlCon = fw.read()
118
        fw.close()
119

    
120
        index = []
121

    
122
        for position in re.finditer(findingText, xmlCon):
123
            pos = position.end()
124
            index.append(pos)
125
            
126
        index.reverse()
127

    
128
        for position in index:
129
            if aboid not in xmlCon[position - 1 + distance: position + 10 + distance]:
130
                xmlCon = xmlCon[:position + distance] + addingText + xmlCon[position + distance:]        
131

    
132
        fw = open(xmlPath, 'w', encoding='utf8')
133
        fw.write(xmlCon)
134
        fw.close()
135

    
136

    
137
if __name__ == '__main__':
138
    selection = input("select fuction(changer = 1, finder = 2, adder = 3) : ")
139
    if selection == '1':
140
        changer()
141
    elif selection == '2':
142
        finder()
143
    elif selection == '3':
144
        adder()
클립보드 이미지 추가 (최대 크기: 500 MB)