Skip to content

Commit

Permalink
多线程和tinksp支持
Browse files Browse the repository at this point in the history
  • Loading branch information
lilingfengdev committed Jun 12, 2024
1 parent 6dd0cac commit 55dbc77
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 33 deletions.
30 changes: 12 additions & 18 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from plugin.engine.minebbs import Minebbs
from plugin.engine.klpbbs import Klpbbs
from plugin.engine.spigotmc import Spigot
from plugin.utils.translate import translate, EN
from plugin.engine.tinksp import Tinksp
from concurrent.futures import ThreadPoolExecutor, wait


def print_result(result):
Expand All @@ -18,20 +19,13 @@ def print_result(result):
if keyword == "exit":
break

engine = Spigot()

for result in engine.search(keyword):
print_result(result)

engine = Minebbs()

for result in engine.search(keyword):
print_result(result)

engine = Klpbbs()

for result in engine.search(keyword):
print_result(result)



engine = [Spigot, Tinksp, Minebbs, Klpbbs, ]
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():
print_result(result)
20 changes: 11 additions & 9 deletions plugin/engine/bing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@
from plugin.utils.translate import translate, EN


class Bing(SearchEngine):
def search(self, keywords) -> typing.List[SearchResult]:
pass
class Bing:

def get_bing_url(self, keywords):
keywords = keywords.strip('\n')
bing_url = re.sub(r'^', 'https://cn.bing.com/search?q=', keywords)
bing_url = re.sub(r'\s', '+', bing_url)
return bing_url

def _search(self, keywords, site="minebbs.com") -> typing.List[SearchResult]:
keywords = f'"{translate(keywords)}" ”插件“ site:{site}'
def search(self, keywords, site) -> typing.List[SearchResult]:
keywords = f'"{translate(keywords)}" 插件 site:{site}'
url = self.get_bing_url(keywords)
result: typing.List[SearchResult] = []
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0',
Expand All @@ -37,13 +35,17 @@ def _search(self, keywords, site="minebbs.com") -> typing.List[SearchResult]:
li_list = tree.xpath('//ol[@id="b_results"]//li[@class="b_algo"]')
for li in li_list:
try:
h3: str = li.xpath('./h2/a')[0].xpath('string(.)')
h3 = li.xpath('./h2/a')[0]
p = li.xpath('.//p')[0].xpath('string(.)')
url = li.xpath('./div[1]/a/div[2]/div[2]/div/cite')[0].xpath('string(.)')
try:
url = li.xpath('./div[1]/a/div[2]/div[2]/div/cite')[0].xpath('string(.)')
except IndexError:
url = h3.get('href')
h3 = h3.xpath('string(.)')
if h3.find("模组") != -1 or h3.find("地图") != -1 or h3.find("插件") == -1:
continue
result.append(SearchResult(url=url, title=h3, summary=p))
except Exception as pri:
print(pri)
except IndexError:
pass

return result
6 changes: 3 additions & 3 deletions plugin/engine/klpbbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from plugin.engine.bing import Bing


class Klpbbs(Bing):
class Klpbbs:

def search(self, keywords) -> typing.List[SearchResult]:
return super()._search(keywords, site="klpbbs.com")[:3] # 一般来将,前五个才有价值 # 更加fw,3个
def search(self, keywords,engine=Bing()) -> typing.List[SearchResult]:
return engine.search(keywords, site="klpbbs.com")[:3] # 一般来将,前五个才有价值 # 更加fw,3个
6 changes: 3 additions & 3 deletions plugin/engine/minebbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from plugin.engine.bing import Bing


class Minebbs(Bing):
class Minebbs():

def search(self, keywords) -> typing.List[SearchResult]:
return super()._search(keywords, site="minebbs.com")[:4] # 一般来将,前五个才有价值 # 四个吧
def search(self, keywords, engine=Bing()) -> typing.List[SearchResult]:
return engine.search(keywords, site="minebbs.com")[:4] # 一般来将,前五个才有价值 # 四个吧
10 changes: 10 additions & 0 deletions plugin/engine/tinksp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import typing

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


class Tinksp:

def search(self, keywords, engine=Bing()) -> typing.List[SearchResult]:
return engine.search(keywords, site="tinksp.com")[:5]

0 comments on commit 55dbc77

Please sign in to comment.