@@ -81,7 +81,7 @@ def article_parse(self, dc_id, keyword, search_type, page=1, search_pos=''):
81
81
global all_link , g_type
82
82
try :
83
83
url = f"https://gall.dcinside.com/{ g_type } /lists/?id={ dc_id } &page={ page } &search_pos={ search_pos } &s_type={ search_type } &s_keyword={ keyword } "
84
- print (url );
84
+ # print(url);
85
85
res = requests .get (url , headers = headers )
86
86
soup = BeautifulSoup (res .text , "lxml" )
87
87
@@ -104,6 +104,9 @@ def article_parse(self, dc_id, keyword, search_type, page=1, search_pos=''):
104
104
else :
105
105
reply = "0"
106
106
107
+ if '/' in reply :
108
+ reply = reply .split ('/' )[0 ]
109
+
107
110
nickname = element .select (".ub-writer" )[0 ].text .strip ()
108
111
timestamp = element .select (".gall_date" )[0 ].text
109
112
refresh = element .select (".gall_count" )[0 ].text
@@ -116,14 +119,12 @@ def article_parse(self, dc_id, keyword, search_type, page=1, search_pos=''):
116
119
'refresh' : refresh , 'recommend' : recommend }
117
120
self .QTableWidgetUpdate .emit (article_data ) # 글 데이터 방출
118
121
119
-
120
122
except Exception as e :
121
123
# print(e)
122
124
self .ThreadMessageEvent .emit ('글을 가져오는 중 오류가 발생했습니다.' )
123
125
124
126
def run (self ):
125
127
self .mutex .lock ()
126
-
127
128
global running
128
129
129
130
search_pos = ''
@@ -133,23 +134,20 @@ def run(self):
133
134
search_type = search_dict [self .parent .comboBox .currentText ()]
134
135
135
136
idx = 0
136
- while (True ):
137
- if running == False :
138
- return
139
-
137
+ while running :
140
138
if idx > loop_count or search_pos == 'last' :
141
139
self .QLabelWidgetUpdate .emit ('상태 : 검색 완료' )
142
140
self .ThreadMessageEvent .emit ('작업이 완료되었습니다.' )
143
141
running = False
144
142
break
145
143
146
144
page = self .parent .page_explorer (id , keyword , search_pos )
147
- print (page )
145
+ # print(page)
148
146
149
147
if not page ['start' ] == 0 : # 글이 있으면
150
148
151
149
for i in range (page ['start' ], page ['end' ] + 1 ):
152
- if running == False :
150
+ if not running :
153
151
return
154
152
155
153
self .QLabelWidgetUpdate .emit (f'상태 : { idx } /{ loop_count } 탐색중...' )
@@ -160,20 +158,24 @@ def run(self):
160
158
if idx > loop_count or search_pos == 'last' :
161
159
break
162
160
163
- time .sleep (0.1 ) # 디시 서버를 위한 딜레이
161
+ # time.sleep(0.1) # 디시 서버를 위한 딜레이
162
+ self .msleep (100 ) # ※주의 QThread에서 제공하는 sleep을 사용
164
163
165
164
self .QLabelWidgetUpdate .emit (f'상태 : { idx } /{ loop_count } 탐색중...' )
166
165
idx += 1 # 글을 못찾고 넘어가도 + 1
167
166
168
167
search_pos = page ['next_pos' ]
169
-
170
168
self .mutex .unlock ()
169
+ running = False
171
170
172
171
def stop (self ):
172
+ global running
173
+ running = False
173
174
self .working = False
174
- self . mutex . unlock ()
175
+
175
176
self .quit ()
176
- self .wait (5000 ) # 5000ms = 5s
177
+ self .msleep (5000 ) #wait로 하면 안되고 msleep으로 해야 제대로 mutex lock이 작동하는듯 하다.
178
+ #self.wait(5000) # 5000ms = 5s
177
179
178
180
179
181
class SlotEvent :
@@ -183,6 +185,10 @@ def ThreadMessageEvent(self, n):
183
185
184
186
@pyqtSlot (dict )
185
187
def QTableWidgetUpdate (self , data ):
188
+ #업데이트를 너무 자주하면 GUI에 제대로 반영이 안되는 것이 있음.
189
+ #IO 성능을 포기하더라도 delay보단 print로 출력해서 주는게 더 낫다는 생각..
190
+ print (data )
191
+
186
192
rowPosition = self .articleView .rowCount ()
187
193
self .articleView .insertRow (rowPosition )
188
194
@@ -352,8 +358,8 @@ def page_explorer(self, dc_id, keyword, search_pos=''):
352
358
def search (self ): # 글검색
353
359
global all_link , g_type , running
354
360
355
- if running == True : # 이미 실행중이면
356
- dialog = QMessageBox .question (self , 'Message' , '검색이 진행중입니다. 새로 검색을 시작하시겠습니까?' ,
361
+ if running : # 이미 실행중이면
362
+ dialog = QMessageBox .question (self , 'Message' , '검색이 진행중입니다. 새로 검색을 시작하시겠습니까? (이전 검색을 중단하기 위해 프로그램이 잠시 멈출 수 있습니다.) ' ,
357
363
QMessageBox .Yes | QMessageBox .No , QMessageBox .No )
358
364
if dialog == QMessageBox .Yes :
359
365
running = False
0 commit comments