This commit is contained in:
2024-04-01 13:11:33 +02:00
parent 22d2c8ab39
commit ba5be99bce
4 changed files with 161393 additions and 4 deletions
+16 -4
View File
@@ -317,7 +317,6 @@ async def on_message(message):
channel = message.channel
await client.process_commands(message)
# TODO: wpiac jego reakcje we framework chatu GPT
message.content = message.content.lower()
tdelta = datetime.now() - MASTER_TIMEOUT
@@ -611,7 +610,6 @@ async def check_data():
in a Discord channel.
"""
# trunk-ignore(codespell/misspelled)
# TODO: dlaczego sie tu wypierdala
logger.info("Heartbeat of cleanup proc")
channel = client.get_channel(1062047367337095268)
messages = [message async for message in channel.history(limit=1)]
@@ -1854,7 +1852,7 @@ async def zagraj_muzyke_mego_ludu(ctx):
final_key_words.extend(key_words[-MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE:])
reply = "Wygenerowana plejlista:\n"
async with ctx.typing():
logger.info("Zaczynam szukać timestamp %s", datetime.now())
logger.info("Zagraj muzyke mego ludu:Zaczynam szukać timestamp %s", datetime.now())
search_time_glob = datetime.now()
file = await wyszukaj(
ctx=ctx,
@@ -1864,7 +1862,7 @@ async def zagraj_muzyke_mego_ludu(ctx):
logger.info("Zagraj muzyke mego ludu:wygenerowano plejliste")
logger.info(file)
logger.info(
"Koniec szukania(timestamp %s zajęło %s",
"Zagraj muzyke mego ludu: Koniec szukania(timestamp %s zajęło %s",
datetime.now(),
datetime.now() - search_time_glob,
)
@@ -1963,6 +1961,20 @@ async def parametry_muzyki_mego_ludu(
ctx.send("Spierdalaj")
logger.info(exce)
class DoSearchView(discord.ui.View):
@discord.ui.button(label="Test", style=discord.ButtonStyle.danger, emoji=":)")
async def button_callback(self, button, interaction):
await interaction.response.send_message("You clicked the button!") # Send a message when the button is clicked
@client.hybrid_command(
name="znajdz_linki_do_dokumentow",
description="Szuka linkow doi w bazie crossref i podaje linki do scihuba",
guild=discord.Object(id=664789470779932693),
)
async def parametry_muzyki_mego_ludu(
ctx, ile_historii=1500, ile_slow_kluczowych=15, jak_dluga_plejlista=30
):
# *================================== Run
logger.info("Starting discord bot")
+89
View File
@@ -0,0 +1,89 @@
import re
import netrc
import json
from platform import uname
from sys import platform
from urllib.request import urlopen
from habanero import Crossref
if platform in ("linux", "linux2"):
SEPARATOR_FILE_PATH = "/"
if "microsoft-standard" in uname().release:
NETRC_FILE = "/home/mtuszowski/.netrc"
else:
NETRC_FILE = "/home/pi/.netrc"
elif platform == "win32":
NETRC_FILE = "C:\\Users\\mtusz\\.netrc"
class Librarian(object):
def __init__(self) -> None:
netrc_mod = netrc.netrc(NETRC_FILE)
authTokens = netrc_mod.authenticators("crossref")
self.cr = Crossref(mailto=authTokens[0])
self.last_search = ""
self.limit = 1000
def search_crossref(self, query):
self.last_search = self.cr.works(query = query, limit = self.limit)
for item in self.last_search['message']['items']:
print("=====")
#print (item)
print(item['DOI'])
print(item['title'])
print(item['type'])
print("=====")
if "container-title" in item:
print("This a part of larger release")
print(item['container-title'])
print (self.last_search['message']['total-results'])
with open("results.json", "x", encoding="UTF-8") as new_file:
new_file.seek(0)
json.dump(self.last_search['message']['items'], new_file, indent=4)
def check_if_exists(self,page_url):
in_scihub_db = True
if not page_url.startswith(("http:", "https:")):
raise ValueError("URL must start with 'http:' or 'https:'")
# trunk-ignore(bandit/B310)
with urlopen(page_url) as response:
info = response.info()
print(info.get_content_type())
data = response.read()
text = data.decode("utf-8")
for line in text.splitlines():
if re.match(r".*Unfortunately, Sci-Hub doesn't have the requested document.*", line):
return None
if in_scihub_db:
return text
return None
def download(self, page_url):
if response := self.check_if_exists(page_url):
for line in response.splitlines():
if m := re.match(r".*<embed type=\"application.pdf\"\s*src=\"(.*\.pdf)",line):
return "https:" + str(m.group(1))
return None
def provide_sci_hub_link(self, page_url):
if self.check_if_exists(page_url):
return page_url
return None
cl = Librarian()
#example not exists
#sample_non_existing_page_url = "https://sci-hub.se/10.4324/9781003006237"
#sample usage to download
#sample_existing_page_url = "https://sci-hub.se/10.1057/9781137435026"
#print(cl.download(sample_existing_page_url))
cl.search_crossref("BDSM")
#1. robi liste wyników i ją wyświetla - ale tylko tytuły niezależnych dzieł - jeśli jest coś w containerze to trza pogrupować
#2. Tworzy przyciski pozwalające sprawdzić czy jest dostępne - i jeśli jest zwraca link
#3. Jest też przycisk "more" - wyszukujemy po 100, wyświetlamy po 20. Po 100 jak jeszcze to dopiero odpytujemy crossref przyciski strzałek przesuwają po obecnej porcji danych
+1
View File
@@ -0,0 +1 @@
habanero
+161287
View File
File diff suppressed because one or more lines are too long