mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 01:49:42 +02:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5af9e79ecc |
@@ -28,54 +28,45 @@ async def init_uztracker():
|
|||||||
|
|
||||||
asyncio.run(init_uztracker())
|
asyncio.run(init_uztracker())
|
||||||
|
|
||||||
async def scrape_uztracker(search, max_results=450):
|
def scrape_uztracker(search):
|
||||||
if up:
|
if up:
|
||||||
|
search_url = url_uztracker + search
|
||||||
|
if state.debug:
|
||||||
|
print(search_url)
|
||||||
result = False
|
result = False
|
||||||
global results
|
global results
|
||||||
global resulttitles
|
global resulttitles
|
||||||
results = []
|
results = []
|
||||||
resulttitles = []
|
resulttitles = []
|
||||||
|
|
||||||
per_page = 50
|
try:
|
||||||
|
resultCount = 0
|
||||||
|
response = requests.get(search_url)
|
||||||
|
response.raise_for_status()
|
||||||
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
|
links = soup.find_all('a', class_="genmed tLink", href=lambda x: x and x.startswith('./viewtopic'))
|
||||||
|
for link in links:
|
||||||
|
if link.b:
|
||||||
|
resultCount += 1
|
||||||
|
results.append(link['href'])
|
||||||
|
resulttitles.append(link.b.text)
|
||||||
|
result = True
|
||||||
|
|
||||||
for start in range(0, max_results, per_page):
|
if result:
|
||||||
search_url = url_uztracker + search + f"&start={start}"
|
return resulttitles, results
|
||||||
if state.debug:
|
|
||||||
print(search_url)
|
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
if not result:
|
||||||
try:
|
# add popup in gui for no result
|
||||||
async with session.get(search_url) as response:
|
return None
|
||||||
response.raise_for_status()
|
|
||||||
text = await response.text()
|
|
||||||
soup = BeautifulSoup(text, 'html.parser')
|
|
||||||
links = soup.find_all('a', class_="genmed tLink", href=lambda x: x and x.startswith('./viewtopic'))
|
|
||||||
resultCount = 0
|
|
||||||
for link in links:
|
|
||||||
if link.b:
|
|
||||||
resultCount += 1
|
|
||||||
results.append(link['href'])
|
|
||||||
resulttitles.append(link.b.text)
|
|
||||||
result = True
|
|
||||||
|
|
||||||
if resultCount == 0:
|
|
||||||
# add popup in gui for no result
|
|
||||||
break
|
|
||||||
|
|
||||||
except aiohttp.ClientError as e:
|
|
||||||
if result and state.debug:
|
|
||||||
print(f"Failed to fetch {search_url}: {e}")
|
|
||||||
return None
|
|
||||||
|
|
||||||
else:
|
except requests.RequestException as e:
|
||||||
if state.debug:
|
if result and state.debug:
|
||||||
print("Error: Uztracker down")
|
print(f"Failed to fetch {search_url}: {e}")
|
||||||
return None, None
|
return None
|
||||||
|
else:
|
||||||
if not results:
|
if state.debug:
|
||||||
return None, None
|
print("Error: Uztracker down")
|
||||||
|
return None, None
|
||||||
return resulttitles, results
|
|
||||||
|
|
||||||
def get_post_title(post_url):
|
def get_post_title(post_url):
|
||||||
if up:
|
if up:
|
||||||
|
|||||||
@@ -5,29 +5,41 @@ from core.utils.network.jsonhandler import split_data, format_data
|
|||||||
from core.utils.data.state import state
|
from core.utils.data.state import state
|
||||||
|
|
||||||
def return_pressed(self):
|
def return_pressed(self):
|
||||||
search_text = self.searchbar.text()
|
search_text = self.searchbar.text()
|
||||||
if search_text == "":
|
if search_text == "":
|
||||||
if state.debug:
|
|
||||||
print("Error: Can't search for nothing")
|
|
||||||
return
|
|
||||||
if state.debug:
|
if state.debug:
|
||||||
print("User searched for:", search_text)
|
print("Error: Can't search for nothing")
|
||||||
if state.tracker == "uztracker":
|
return
|
||||||
response = asyncio.run(scrape_uztracker(search_text))
|
if state.debug:
|
||||||
if state.tracker == "rutracker":
|
print("User searched for:", search_text)
|
||||||
response = scrape_rutracker(search_text)
|
|
||||||
|
if state.tracker == "uztracker":
|
||||||
|
response = scrape_uztracker(search_text)
|
||||||
if response:
|
if response:
|
||||||
if state.tracker == "uztracker":
|
state.post_titles, state.post_urls = response
|
||||||
state.post_titles, state.post_urls, = response
|
self.softwareList.clear()
|
||||||
|
if state.post_titles and len(state.post_titles) > 0:
|
||||||
|
self.softwareList.addItems(state.post_titles)
|
||||||
|
self.show_empty_results(False)
|
||||||
|
self.post_author_list.clear()
|
||||||
|
else:
|
||||||
|
if state.debug:
|
||||||
|
print(f"No Results for {search_text}")
|
||||||
self.softwareList.clear()
|
self.softwareList.clear()
|
||||||
if state.post_titles:
|
self.show_empty_results(True)
|
||||||
self.softwareList.addItems(state.post_titles)
|
else:
|
||||||
self.post_author_list.addItems(state.post_author)
|
if state.debug:
|
||||||
if state.tracker == "rutracker":
|
print(f"No response from uztracker")
|
||||||
_, state.posts, _, _, cached = split_data(response)
|
self.softwareList.clear()
|
||||||
|
self.show_empty_results(True)
|
||||||
|
|
||||||
|
elif state.tracker == "rutracker":
|
||||||
|
response = scrape_rutracker(search_text)
|
||||||
|
if response:
|
||||||
|
_, state.posts, _, _, cached = split_data(response)
|
||||||
if state.posts == []:
|
if state.posts == []:
|
||||||
if state.debug:
|
if state.debug:
|
||||||
print(f"No Results found for \"{search_text}\"")
|
print(f"No Results for {search_text}")
|
||||||
self.softwareList.clear()
|
self.softwareList.clear()
|
||||||
self.show_empty_results(True)
|
self.show_empty_results(True)
|
||||||
else:
|
else:
|
||||||
@@ -39,4 +51,8 @@ def return_pressed(self):
|
|||||||
self.softwareList.addItems(state.post_titles)
|
self.softwareList.addItems(state.post_titles)
|
||||||
if state.debug == True:
|
if state.debug == True:
|
||||||
print(f"Response Cached: {cached}")
|
print(f"Response Cached: {cached}")
|
||||||
|
else:
|
||||||
|
if state.debug:
|
||||||
|
print(f"No response from rutracker")
|
||||||
|
self.softwareList.clear()
|
||||||
|
self.show_empty_results(True)
|
||||||
Reference in New Issue
Block a user