Skip to content

Commit bbf03c5

Browse files
committed
글 검색시 제목이 ... 으로 나오던 것 수정
1 parent f230ab9 commit bbf03c5

File tree

5 files changed

+105
-80
lines changed

5 files changed

+105
-80
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ venv/
33
.idea/
44
.vscode/
55
output/
6-
__pycache__
6+
__pycache__/
7+
*.pyc
8+
module/__pycache__/
79
*.pyc
8-
module/__pycache__

async/new_asyncio_engine/main.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DCAsyncParser:
2323
}
2424
requests_limit = 50
2525

26-
# 어짜피 싱글톤으로 설계할거라 객체 간의 변수 공유 문제는 생각하지 않아도 됨.
26+
2727

2828
# 생성자에는 async를 붙일 수 없으므로, static 메서드를 이용하여 생성자를 대체한다.
2929
# https://stackoverflow.com/questions/36363278/can-async-await-be-used-in-constructors
@@ -146,7 +146,7 @@ async def search(self, search_type : Search, keyword : str, repeat_cnt : int) ->
146146
self.keyword = keyword
147147

148148
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(limit=DCAsyncParser.requests_limit), headers=DCAsyncParser.headers) as session:
149-
async with limiter:
149+
# async with limiter:
150150
# 제일 처음 검색 페이지에 요청을 던져서 글 갯수 (검색 위치) 를 파악한다.
151151
url = f'https://gall.dcinside.com/{self.gallary_type}board/lists/?id={self.id}&s_type={self.search_type}&s_keyword={self.keyword}'
152152
res = await self.fetch(session, url)
@@ -238,8 +238,11 @@ async def search(self, search_type : Search, keyword : str, repeat_cnt : int) ->
238238

239239
return article_list
240240

241-
limiter = AsyncLimiter(1, 0.125)
241+
# limiter = AsyncLimiter(1, 0.125)
242242
if __name__ == '__main__':
243243
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
244-
parser = asyncio.run(DCAsyncParser.create(id='taiko'))
245-
asyncio.run(parser.search(search_type=Search.TITLE_PLUS_CONTENT, keyword='타타콘', repeat_cnt=9999))
244+
# parser = asyncio.run(DCAsyncParser.create(id='taiko'))
245+
# asyncio.run(parser.search(search_type=Search.TITLE_PLUS_CONTENT, keyword='타타콘', repeat_cnt=9999))
246+
parser = asyncio.run(DCAsyncParser.create(id='baseball_new11'))
247+
asyncio.run(parser.search(search_type=Search.TITLE_PLUS_CONTENT, keyword='야붕이', repeat_cnt=9999))
248+

main.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ class Worker(QThread):
4343
# 메인폼에서 상속받기
4444

4545
# parent는 WindowClass에서 전달하는 self이다.(WidnowClass의 인스턴스)
46-
def __init__(self, parent : Main) -> None:
46+
def __init__(self, parent: Main) -> None:
4747
super().__init__(parent) # 부모 Class의 생성자 호출 - 코드 중복 방지
4848
# 클래스 변수 self.parent로 WindowClass 인스턴스를 접근할 수 있다.
49-
self.parent : Main = parent
49+
self.parent: Main = parent
5050

5151
def run(self) -> None:
5252
global running, parser
@@ -110,7 +110,7 @@ def run(self) -> None:
110110
# 모듈화에 문제가 생겨서 우선 하드 코딩
111111

112112

113-
def resource_path(relative_path : str) -> str:
113+
def resource_path(relative_path: str) -> str:
114114
base_path = getattr(sys, '_MEIPASS', os.path.dirname(
115115
os.path.abspath(__file__)))
116116
return os.path.join(base_path, relative_path)
@@ -199,7 +199,7 @@ def __init__(self) -> None:
199199
# arrow_path 경로를 슬래시로 변경 (윈도우 역슬래시 경로 문자열을 슬래쉬로 바꿔줘야함. 아니면 인식을 못하네용.. ㅠ)
200200
arrow_path = arrow_path.replace('\\', '/')
201201

202-
style = f"QComboBox::down-arrow {{image: url(%s);}}" % (arrow_path)
202+
style = f"QComboBox::down-arrow {{image: url(%s);}}" % arrow_path
203203
self.comboBox.setStyleSheet(style)
204204
# print(style)
205205

@@ -266,16 +266,19 @@ def set_table_widget(self) -> None:
266266
self.articleView.setColumnWidth(5, 40) # 조회
267267
self.articleView.setColumnWidth(6, 40) # 추천
268268

269-
def set_table_autosize(self, isAutoResize : bool) -> None:
269+
270+
def set_table_autosize(self, isAutoResize: bool) -> None:
270271
# 성능을 위해 사이즈 정책은 검색 완료후 변경하도록 한다.
271272
# 해당 함수는 검색 완료후 2번 호출된다. (정책만 바꿔서 오토 리사이징 시키고 다시 정책을 원래대로 돌려놓기 위함)
272273
# isAutoResize : True - 자동 사이즈 조절, False - 고정 사이즈
273274
column_cnt = self.articleView.columnCount()
274275
header = self.articleView.horizontalHeader()
275276
if (isAutoResize):
276-
[header.setSectionResizeMode(i, QHeaderView.ResizeToContents) for i in range(column_cnt)]
277+
[header.setSectionResizeMode(
278+
i, QHeaderView.ResizeToContents) for i in range(column_cnt)]
277279
else:
278-
[header.setSectionResizeMode(i, QHeaderView.Fixed) for i in range(column_cnt)]
280+
[header.setSectionResizeMode(i, QHeaderView.Fixed)
281+
for i in range(column_cnt)]
279282

280283
# GUI----------------------------------------------
281284

@@ -353,15 +356,16 @@ def item_dbl_click(self) -> None:
353356

354357
# Slot Event
355358
@ pyqtSlot(str)
356-
def ThreadMessageEvent(self, n : str) -> None:
359+
def ThreadMessageEvent(self, n: str) -> None:
357360
QMessageBox.information(self, '알림', n, QMessageBox.Yes)
358361

359362
@ pyqtSlot(bool)
360-
def QTableWidgetSetSort(self, bool : bool) -> None:
363+
def QTableWidgetSetSort(self, bool: bool) -> None:
361364
self.articleView.setSortingEnabled(bool)
362365

363366
@ pyqtSlot(list)
364367
def QTableWidgetUpdate(self, article: list[Article]) -> None:
368+
365369
for data in article:
366370
row_position = self.articleView.rowCount()
367371
self.articleView.insertRow(row_position)
@@ -433,11 +437,12 @@ def filtering(self, keyword) -> None:
433437

434438
# print(keyword)
435439

436-
def keyPressEvent(self, event : PyQt5.QtGui.QKeyEvent) -> None:
440+
def keyPressEvent(self, event: PyQt5.QtGui.QKeyEvent) -> None:
437441
# Ctrl + C 누른 경우 Table의 내용 복사
438442
# https://stackoverflow.com/questions/60715462/how-to-copy-and-paste-multiple-cells-in-qtablewidget-in-pyqt5
439-
if event.key() == Qt.Key.Key_C and (event.modifiers() & Qt.KeyboardModifier.ControlModifier): # type: ignore
440-
copied_cells = sorted(self.articleView.selectedIndexes()) # type: ignore
443+
if event.key() == Qt.Key.Key_C and (event.modifiers() & Qt.KeyboardModifier.ControlModifier): # type: ignore
444+
copied_cells = sorted(
445+
self.articleView.selectedIndexes()) # type: ignore
441446

442447
copy_text = ''
443448
max_column = copied_cells[-1].column()
@@ -451,7 +456,7 @@ def keyPressEvent(self, event : PyQt5.QtGui.QKeyEvent) -> None:
451456
QApplication.clipboard().setText(copy_text)
452457

453458
# Ctrl + F 누른 경우 검색 창 (필터링 창) 열기
454-
elif event.key() == Qt.Key.Key_F and (event.modifiers() & Qt.KeyboardModifier.ControlModifier): # type: ignore
459+
elif event.key() == Qt.Key.Key_F and (event.modifiers() & Qt.KeyboardModifier.ControlModifier): # type: ignore
455460
if hasattr(self, 'searchWindow'):
456461
# 이미 열려있으면 포커스만 이동 (창 활성화)
457462
if self.searchWindow.isVisible():

module/article_parser.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ def article_parse(self, keyword: str, s_type: str, page: int = 1, search_pos='')
6161
else:
6262
img = False
6363

64-
title = element.select(".ub-word > a")[0].text
64+
# 이유는 모르겠으나 디시 사이트가 바뀐건지 .text 로 가져오면
65+
# 아래와 같이
66+
# Article(num='번호', title='\n데이터', reply='1', nickname='ㅇㅇ(118.235)', timestamp='03.30', refresh='208', recommend='0')
67+
# 데이터 앞에 \n 이 붙어서 strip() 으로 썰어줬다.
68+
# strip()은 문자열의 시작과 끝에 있는 줄바꿈과 공백을 제거합니다.
69+
# 원래 strip 은 공백 제거 기능만 있는줄 알았더니 줄바꿈 기능도 있었다!
70+
# https://codechacha.com/ko/python-remove-newline-in-string/ 참고
71+
title = element.select(".ub-word > a")[0].text.strip()
72+
6573
reply = element.select(
6674
".ub-word > a.reply_numbox > .reply_num")
6775
if reply:

ui.py

Lines changed: 67 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -16,58 +16,60 @@ def setupUi(self, MainWindow):
1616
MainWindow.setObjectName("MainWindow")
1717
MainWindow.resize(812, 802)
1818
icon = QtGui.QIcon()
19-
icon.addPixmap(QtGui.QPixmap("main.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
19+
icon.addPixmap(QtGui.QPixmap("main.ico"),
20+
QtGui.QIcon.Normal, QtGui.QIcon.Off)
2021
MainWindow.setWindowIcon(icon)
2122
MainWindow.setStyleSheet("QLineEdit {\n"
22-
" border: 4px solid #3B4890;\n"
23-
" padding: 4px;\n"
24-
"}\n"
25-
"\n"
26-
"QLineEdit:focus{\n"
27-
" border: 4px solid rgb(0, 170, 255);\n"
28-
"}\n"
29-
"\n"
30-
"QPushButton {\n"
31-
" background-color: #3b4890;\n"
32-
" min-width: 5em;\n"
33-
" padding: 8px;\n"
34-
" color:white;\n"
35-
"\n"
36-
" border-style: outset;\n"
37-
" border-width: 2px;\n"
38-
" border-radius : 5px;\n"
39-
"\n"
40-
" border-color: beige;\n"
41-
"}\n"
42-
"\n"
43-
"QPushButton:pressed {\n"
44-
" background-color: #29367C;\n"
45-
" border-style: inset;\n"
46-
"}\n"
47-
"\n"
48-
"QComboBox {\n"
49-
" border: 4px solid #3B4890;\n"
50-
" padding: 4px;\n"
51-
"}\n"
52-
"\n"
53-
"QComboBox::drop-down \n"
54-
"{\n"
55-
" border: 0px;\n"
56-
"}\n"
57-
"\n"
58-
"QComboBox::down-arrow {\n"
59-
" image: url(git.png);\n"
60-
" width: 28px;\n"
61-
" height: 28px;\n"
62-
"}")
23+
" border: 4px solid #3B4890;\n"
24+
" padding: 4px;\n"
25+
"}\n"
26+
"\n"
27+
"QLineEdit:focus{\n"
28+
" border: 4px solid rgb(0, 170, 255);\n"
29+
"}\n"
30+
"\n"
31+
"QPushButton {\n"
32+
" background-color: #3b4890;\n"
33+
" min-width: 5em;\n"
34+
" padding: 8px;\n"
35+
" color:white;\n"
36+
"\n"
37+
" border-style: outset;\n"
38+
" border-width: 2px;\n"
39+
" border-radius : 5px;\n"
40+
"\n"
41+
" border-color: beige;\n"
42+
"}\n"
43+
"\n"
44+
"QPushButton:pressed {\n"
45+
" background-color: #29367C;\n"
46+
" border-style: inset;\n"
47+
"}\n"
48+
"\n"
49+
"QComboBox {\n"
50+
" border: 4px solid #3B4890;\n"
51+
" padding: 4px;\n"
52+
"}\n"
53+
"\n"
54+
"QComboBox::drop-down \n"
55+
"{\n"
56+
" border: 0px;\n"
57+
"}\n"
58+
"\n"
59+
"QComboBox::down-arrow {\n"
60+
" image: url(git.png);\n"
61+
" width: 28px;\n"
62+
" height: 28px;\n"
63+
"}")
6364
self.centralwidget = QtWidgets.QWidget(MainWindow)
6465
self.centralwidget.setObjectName("centralwidget")
6566
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
6667
self.gridLayout.setObjectName("gridLayout")
6768
self.verticalLayout = QtWidgets.QVBoxLayout()
6869
self.verticalLayout.setObjectName("verticalLayout")
6970
self.horizontalLayout = QtWidgets.QHBoxLayout()
70-
self.horizontalLayout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
71+
self.horizontalLayout.setSizeConstraint(
72+
QtWidgets.QLayout.SetDefaultConstraint)
7173
self.horizontalLayout.setSpacing(2)
7274
self.horizontalLayout.setObjectName("horizontalLayout")
7375
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
@@ -89,8 +91,8 @@ def setupUi(self, MainWindow):
8991
self.txt_repeat.setFont(font)
9092
self.txt_repeat.setToolTip("")
9193
self.txt_repeat.setStyleSheet("#searchBox {\n"
92-
" border: 4px solid #3b4890;\n"
93-
"}")
94+
" border: 4px solid #3b4890;\n"
95+
"}")
9496
self.txt_repeat.setObjectName("txt_repeat")
9597
self.horizontalLayout.addWidget(self.txt_repeat)
9698
self.txt_id = QtWidgets.QLineEdit(self.centralwidget)
@@ -100,8 +102,8 @@ def setupUi(self, MainWindow):
100102
self.txt_id.setFont(font)
101103
self.txt_id.setToolTip("")
102104
self.txt_id.setStyleSheet("#searchBox {\n"
103-
" border: 4px solid #3b4890;\n"
104-
"}")
105+
" border: 4px solid #3b4890;\n"
106+
"}")
105107
self.txt_id.setObjectName("txt_id")
106108
self.horizontalLayout.addWidget(self.txt_id)
107109
self.txt_keyword = QtWidgets.QLineEdit(self.centralwidget)
@@ -127,8 +129,8 @@ def setupUi(self, MainWindow):
127129
self.verticalLayout.addLayout(self.horizontalLayout)
128130
self.articleView = QtWidgets.QTableWidget(self.centralwidget)
129131
self.articleView.setStyleSheet("QLabel#label{\n"
130-
"color : rgb(85, 85, 255)\n"
131-
"}")
132+
"color : rgb(85, 85, 255)\n"
133+
"}")
132134
self.articleView.setShowGrid(True)
133135
self.articleView.setGridStyle(QtCore.Qt.SolidLine)
134136
self.articleView.setObjectName("articleView")
@@ -159,16 +161,17 @@ def setupUi(self, MainWindow):
159161
font.setWeight(75)
160162
self.label.setFont(font)
161163
self.label.setStyleSheet("QLabel#label{\n"
162-
"color : rgb(85, 85, 255)\n"
163-
"}")
164+
"color : rgb(85, 85, 255)\n"
165+
"}")
164166
self.label.setObjectName("label")
165167
self.horizontalLayout_2.addWidget(self.label)
166168
self.txt_status = QtWidgets.QLabel(self.centralwidget)
167169
font = QtGui.QFont()
168170
font.setFamily("나눔고딕")
169171
font.setPointSize(10)
170172
self.txt_status.setFont(font)
171-
self.txt_status.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
173+
self.txt_status.setAlignment(
174+
QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
172175
self.txt_status.setObjectName("txt_status")
173176
self.horizontalLayout_2.addWidget(self.txt_status)
174177
self.verticalLayout.addLayout(self.horizontalLayout_2)
@@ -179,16 +182,20 @@ def setupUi(self, MainWindow):
179182
MainWindow.setStatusBar(self.statusbar)
180183

181184
self.retranslateUi(MainWindow)
182-
self.btn_Search.clicked.connect(MainWindow.search) # type: ignore
183-
self.articleView.itemDoubleClicked['QTableWidgetItem*'].connect(MainWindow.item_dbl_click) # type: ignore
184-
self.txt_keyword.returnPressed.connect(MainWindow.search) # type: ignore
185-
self.txt_id.returnPressed.connect(MainWindow.search) # type: ignore
186-
self.txt_repeat.returnPressed.connect(MainWindow.search) # type: ignore
185+
self.btn_Search.clicked.connect(MainWindow.search) # type: ignore
186+
self.articleView.itemDoubleClicked['QTableWidgetItem*'].connect(
187+
MainWindow.item_dbl_click) # type: ignore
188+
self.txt_keyword.returnPressed.connect(
189+
MainWindow.search) # type: ignore
190+
self.txt_id.returnPressed.connect(MainWindow.search) # type: ignore
191+
self.txt_repeat.returnPressed.connect(
192+
MainWindow.search) # type: ignore
187193
QtCore.QMetaObject.connectSlotsByName(MainWindow)
188194

189195
def retranslateUi(self, MainWindow):
190196
_translate = QtCore.QCoreApplication.translate
191-
MainWindow.setWindowTitle(_translate("MainWindow", "DCINSIDE ARTICLE FINDER v0.152 Beta"))
197+
MainWindow.setWindowTitle(_translate(
198+
"MainWindow", "DCINSIDE ARTICLE FINDER v0.152 Beta"))
192199
self.comboBox.setItemText(0, _translate("MainWindow", "제목+내용"))
193200
self.comboBox.setItemText(1, _translate("MainWindow", "제목"))
194201
self.comboBox.setItemText(2, _translate("MainWindow", "내용"))
@@ -213,7 +220,8 @@ def retranslateUi(self, MainWindow):
213220
item.setText(_translate("MainWindow", "조회"))
214221
item = self.articleView.horizontalHeaderItem(6)
215222
item.setText(_translate("MainWindow", "추천"))
216-
self.label.setText(_translate("MainWindow", "Copyright 2022. File(pgh268400@naver.com) all rights reserved."))
223+
self.label.setText(_translate(
224+
"MainWindow", "Copyright 2022. File(pgh268400@naver.com) all rights reserved."))
217225
self.txt_status.setText(_translate("MainWindow", "상태 : IDLE"))
218226

219227

0 commit comments

Comments
 (0)