Skip to content

Commit

Permalink
重构
Browse files Browse the repository at this point in the history
显然需要修改构建脚本
  • Loading branch information
lilingfengdev committed Jun 23, 2024
1 parent c2e687d commit deee44a
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 116 deletions.
File renamed without changes.
26 changes: 26 additions & 0 deletions cli/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from core.search import search
import random
import colorama

colorama.init(autoreset=True)


def print_result(result):
print("\033[1;33m====================\033[0m")
print(f"\033[1;32m标题: \033[0m{result.title}")
print(f"\033[1;34m简介: \033[0m{result.summary}")
print(f"\033[1;36mURL: \033[0m{result.url}")
print("\033[1;33m====================\033[0m")
print()


print("欢迎使用插件搜索工具")
while True:
keyword = input("请输入关键字(exit退出):")
if keyword == "exit":
break

results = search(keyword)
random.shuffle(results)
for result in results:
print_result(result)
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion plugin/engine/bing.py → core/engine/bing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import typing

from plugin.engine.base import SearchResult
from core.engine.base import SearchResult
import re
import requests
from lxml.html import etree
Expand Down
4 changes: 2 additions & 2 deletions plugin/engine/klpbbs.py → core/engine/klpbbs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typing

from plugin.engine.base import SearchResult
from plugin.engine.bing import Bing
from core.engine.base import SearchResult
from core.engine.bing import Bing


class Klpbbs:
Expand Down
4 changes: 2 additions & 2 deletions plugin/engine/minebbs.py → core/engine/minebbs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typing

from plugin.engine.base import SearchResult
from plugin.engine.bing import Bing
from core.engine.base import SearchResult
from core.engine.bing import Bing


class Minebbs():
Expand Down
4 changes: 2 additions & 2 deletions plugin/engine/spigotmc.py → core/engine/spigotmc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typing

from plugin.engine.base import SearchEngine, SearchResult
from plugin.utils.translate import translate, EN
from core.engine.base import SearchEngine, SearchResult
from core.utils.translate import translate, EN
import requests
import json

Expand Down
4 changes: 2 additions & 2 deletions plugin/engine/tinksp.py → core/engine/tinksp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typing

from plugin.engine.base import SearchResult
from plugin.engine.bing import Bing
from core.engine.base import SearchResult
from core.engine.bing import Bing


class Tinksp:
Expand Down
23 changes: 23 additions & 0 deletions core/search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import List

from core.engine.minebbs import Minebbs
from core.engine.klpbbs import Klpbbs
from core.engine.spigotmc import Spigot
from core.engine.tinksp import Tinksp
from core.engine.base import SearchResult
from concurrent.futures import ThreadPoolExecutor, wait


def search(keyword: str) -> List[SearchResult]:
engine = [Spigot, Tinksp, Minebbs, Klpbbs]
results = []
with ThreadPoolExecutor(max_workers=6) as executor:
future_list = []
for e in engine:
future = executor.submit(e().search, keyword)
future_list.append(future)
wait(future_list)
for future in future_list:
for result in future.result():
results.append(result)
return result
Empty file added core/utils/__init__.py
Empty file.
File renamed without changes.
Empty file added gui/__init__.py
Empty file.
26 changes: 7 additions & 19 deletions pse.py → gui/main.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
from plugin.engine.minebbs import Minebbs
from plugin.engine.klpbbs import Klpbbs
from plugin.engine.spigotmc import Spigot
from plugin.engine.tinksp import Tinksp
from concurrent.futures import ThreadPoolExecutor, wait
from core.search import search
from PySide6.QtWidgets import QMainWindow, QApplication, QMessageBox, QTreeWidgetItem
from PySide6.QtCore import QObject, QThread, Signal, Slot
# from PySide6 import QtCore
import sys
from ui import Ui_MainWindow
import pyperclip


class Worker(QObject):
_signal = Signal(list)

def __init__(self):
super().__init__()
print("000")

def work(self, keyword):
print(111)
engine = [Spigot, Tinksp, Minebbs, Klpbbs]
results = []
with ThreadPoolExecutor(max_workers=6) as executor:
future_list = []
for e in engine:
future = executor.submit(e().search, keyword)
print(10)
future_list.append(future)
wait(future_list)
for future in future_list:
for result in future.result():
results.append(result)
print(1)
results = search(keyword)
self._signal.emit(results)


class MainWindow(QMainWindow):
a = Signal(str)

Expand All @@ -58,12 +45,13 @@ def shower(self, results):
for result in results:
num = results.index(result)
title = QTreeWidgetItem(self.ui.outputTreeWidget, [result.title, result.url, result.summary])

def copyUrl(self, item):
# copy a text to the clipboard.
pyperclip.copy(item.text(1))
QMessageBox.information(self, "Copied!", "已将该插件链接复制到剪贴板。")


if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
Expand Down
File renamed without changes.
File renamed without changes.
41 changes: 0 additions & 41 deletions main.py

This file was deleted.

45 changes: 0 additions & 45 deletions main.spec

This file was deleted.

6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
cn_bing_translator
pyperclip
colorama
pyperclip~=1.9.0
colorama~=0.4.6
requests~=2.32.3
lxml~=5.2.2

0 comments on commit deee44a

Please sign in to comment.