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