mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
Nowy lepszy trunk
Additional lines of code 1 AAA
This commit is contained in:
@@ -6,3 +6,4 @@
|
||||
plugins
|
||||
user_trunk.yaml
|
||||
user.yaml
|
||||
tmp
|
||||
|
||||
@@ -2,9 +2,6 @@ rules:
|
||||
quoted-strings:
|
||||
required: only-when-needed
|
||||
extra-allowed: ["{|}"]
|
||||
empty-values:
|
||||
forbid-in-block-mappings: true
|
||||
forbid-in-flow-mappings: true
|
||||
key-duplicates: {}
|
||||
octal-values:
|
||||
forbid-implicit-octal: true
|
||||
|
||||
+23
-30
@@ -1,43 +1,36 @@
|
||||
# This file controls the behavior of Trunk: https://docs.trunk.io/cli
|
||||
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
|
||||
version: 0.1
|
||||
cli:
|
||||
version: 1.14.2
|
||||
version: 1.20.1
|
||||
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
|
||||
plugins:
|
||||
sources:
|
||||
- id: trunk
|
||||
ref: v1.2.1
|
||||
ref: v1.4.4
|
||||
uri: https://github.com/trunk-io/plugins
|
||||
lint:
|
||||
enabled:
|
||||
- checkov@2.4.9
|
||||
- yamllint@1.32.0
|
||||
- actionlint@1.6.25
|
||||
- markdownlint@0.35.0
|
||||
- trivy@0.44.1
|
||||
- trufflehog@3.54.0
|
||||
- pylint
|
||||
- codespell
|
||||
- cspell
|
||||
- git-diff-check
|
||||
- eslint
|
||||
- prettier
|
||||
- semgrep
|
||||
- autopep8
|
||||
- bandit
|
||||
- black
|
||||
- flake8
|
||||
- isort
|
||||
- mypy
|
||||
- pylint
|
||||
- ruff
|
||||
- semgrep
|
||||
- yapf
|
||||
- gitleaks
|
||||
|
||||
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
|
||||
runtimes:
|
||||
enabled:
|
||||
- go@1.19.5
|
||||
- node@18.12.1
|
||||
- python@3.10.8
|
||||
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
|
||||
lint:
|
||||
enabled:
|
||||
- actionlint@1.6.27
|
||||
- bandit@1.7.7
|
||||
- black@24.2.0
|
||||
- codespell
|
||||
- checkov@3.2.32
|
||||
- git-diff-check
|
||||
- isort@5.13.2
|
||||
- pylint
|
||||
- markdownlint@0.39.0
|
||||
- prettier@3.2.5
|
||||
- ruff@0.3.1
|
||||
- trivy@0.49.1
|
||||
- trufflehog@3.68.5
|
||||
- yamllint@1.35.1
|
||||
actions:
|
||||
disabled:
|
||||
- trunk-announce
|
||||
|
||||
Vendored
-2
@@ -1,6 +1,4 @@
|
||||
{
|
||||
"python.linting.enabled": true,
|
||||
"python.linting.pylintEnabled": true,
|
||||
"trunk.inlineDecorators": true,
|
||||
"trunk.inlineDecoratorsForAllExtensions": true,
|
||||
"trunk.showPreexistingIssues": true,
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
# trunk-ignore-all(bandit/B311)
|
||||
# pylint: disable=line-too-long
|
||||
# pylint: disable=too-many-lines
|
||||
"""
|
||||
Module of a python bot named Conjurer - used to work on BDSM discord servers.
|
||||
"""
|
||||
# This Python file uses the following encoding: utf-8
|
||||
# trunk-ignore-all(flake8/E501)
|
||||
# trunk-ignore-all(bandit/B311)
|
||||
# trunk-ignore-all(mypy/index)
|
||||
# pylint: disable=line-too-long
|
||||
# pylint: disable=too-many-lines
|
||||
import asyncio
|
||||
import io
|
||||
import json
|
||||
@@ -40,8 +38,8 @@ from discord.ext import commands
|
||||
from spotipy.oauth2 import SpotifyClientCredentials
|
||||
|
||||
import yt_dlp
|
||||
from spotify_dl import youtube as youtube_download
|
||||
from spotify_dl import spotify
|
||||
from spotify_dl import youtube as youtube_download
|
||||
|
||||
Music_Config = TypedDict(
|
||||
"Music_Config",
|
||||
@@ -54,12 +52,10 @@ Music_Config = TypedDict(
|
||||
)
|
||||
|
||||
# *=========================================== Predefines
|
||||
formatter = logging.Formatter(
|
||||
"%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||
MASTER_TIMEOUT = datetime.now()
|
||||
INITIAL_TIME_WAIT = 5
|
||||
MUZYKA: Music_Config = {"playing": False,
|
||||
"ctx": None, "queue": [], "requester": []}
|
||||
MUZYKA: Music_Config = {"playing": False, "ctx": None, "queue": [], "requester": []}
|
||||
|
||||
LOGFILE = ""
|
||||
NETRC_FILE = ""
|
||||
@@ -209,7 +205,6 @@ async def on_ready():
|
||||
# trunk-ignore(pylint/R0914)
|
||||
# trunk-ignore(pylint/R0912)
|
||||
async def on_message(message):
|
||||
|
||||
"""
|
||||
Handle incoming messages in a Discord server, perform various
|
||||
checks and actions based on the content and context of the message, and respond accordingly.
|
||||
@@ -315,14 +310,16 @@ async def on_message(message):
|
||||
logger.info("Poczatek procedury obrazkowej")
|
||||
message.content = message.content.replace("imaginuje sobie: ", "")
|
||||
logger.debug("Wywolanie obrazka: %s", message.content)
|
||||
response = openAIClient.images.generate(
|
||||
response = await openAIClient.images.generate(
|
||||
model="dall-e-3",
|
||||
prompt=message.content,
|
||||
size="1024x1024",
|
||||
quality="standard",
|
||||
n=1,
|
||||
)
|
||||
image_url = response["data"][0]["url"]
|
||||
|
||||
logger.info(response)
|
||||
image_url = response.data[0].url
|
||||
logger.debug("Wynikowy obrazek pod url: %s", image_url)
|
||||
response = requests.get(image_url, timeout=360)
|
||||
|
||||
@@ -340,6 +337,7 @@ async def on_message(message):
|
||||
|
||||
# *=========================================== Define Functions
|
||||
|
||||
|
||||
def num_tokens_from_string(message, model):
|
||||
"""
|
||||
The function takes a string message and a model as input and returns the number of tokens in the
|
||||
@@ -493,6 +491,25 @@ async def play(ctx, zamawial=None, arg=None):
|
||||
await ctx.send(result)
|
||||
|
||||
|
||||
async def archive_channel(channel_no):
|
||||
"""
|
||||
The function `archive_channel` retrieves messages from a specified channel, processes them, and
|
||||
saves the data in a JSON file with a timestamp in the filename.
|
||||
|
||||
:param channel_no: The `archive_channel` function you provided seems to be incomplete. It looks like
|
||||
you are trying to archive messages from a Discord channel into a JSON file
|
||||
"""
|
||||
channel = client.get_channel(channel_no)
|
||||
messages = [message async for message in channel.history(limit=None)]
|
||||
path_newfile = f"{LOGSTORE}channeldump_{channel_no}_{datetime.now()}.json"
|
||||
new_data = []
|
||||
for message in messages:
|
||||
pass
|
||||
with open(path_newfile, "x", encoding=ENCODING) as new_file:
|
||||
new_file.seek(0)
|
||||
json.dump(new_data, new_file, indent=4)
|
||||
|
||||
|
||||
async def check():
|
||||
"""Funkcja sprawdzająca czy grać następny kawałek."""
|
||||
last_spontaneous_call = datetime.now()
|
||||
@@ -578,7 +595,7 @@ async def get_random_cyclic_message():
|
||||
words.
|
||||
:return: a random cyclic message from the list `cyclic_words`.
|
||||
"""
|
||||
messnum = random.randint(0, len(cyclic_words)-1)
|
||||
messnum = random.randint(0, len(cyclic_words) - 1)
|
||||
return cyclic_words[messnum][0]
|
||||
|
||||
|
||||
@@ -630,30 +647,47 @@ async def handle_response(prompt, vykidailo, bartender, history, username, music
|
||||
history.append(GPT_SETTINGS[0])
|
||||
chat_gpt_config_request_size = num_tokens_from_string(GPT_SETTINGS[0], "gpt-4")
|
||||
|
||||
for (slowo, reakcja) in word_reactions.items():
|
||||
for slowo, reakcja in word_reactions.items():
|
||||
if not reakcja[3]:
|
||||
content = "Kiedy słyszysz " + slowo + " to reagujesz lub dzieje się to " + reakcja[0]
|
||||
content = (
|
||||
"Kiedy słyszysz "
|
||||
+ slowo
|
||||
+ " to reagujesz lub dzieje się to "
|
||||
+ reakcja[0]
|
||||
)
|
||||
temp = {"role": "system", "content": content}
|
||||
chat_gpt_config_request_size += num_tokens_from_string(temp, "gpt-4")
|
||||
history.append(temp)
|
||||
|
||||
final_prompt = username + ":" + prompt
|
||||
logger.info("Rozmiar zapytania przed dodaniem historii %s", chat_gpt_config_request_size)
|
||||
logger.info(
|
||||
"Rozmiar zapytania przed dodaniem historii %s", chat_gpt_config_request_size
|
||||
)
|
||||
if music:
|
||||
algorithm = "gpt-3.5-turbo-0125"
|
||||
table = message_table_muzyka
|
||||
token_amount = 10700
|
||||
else:
|
||||
table = MESSAGE_TABLE
|
||||
algorithm = "gpt-4-turbo-preview"
|
||||
token_amount = 28000
|
||||
algorithm = "gpt-4"
|
||||
token_amount = 7000
|
||||
|
||||
prompt_gpt_request_size = num_tokens_from_string({"role": "user", "content": final_prompt}, "gpt-4")
|
||||
prompt_gpt_request_size = num_tokens_from_string(
|
||||
{"role": "user", "content": final_prompt}, "gpt-4"
|
||||
)
|
||||
temptable = []
|
||||
for i in reversed(table):
|
||||
temp_token = num_tokens_from_string(i, "gpt-4")
|
||||
logger.info("Rozmiar zapytania %s prompt %s temp %s", chat_gpt_config_request_size, prompt_gpt_request_size, temp_token)
|
||||
if chat_gpt_config_request_size < token_amount + prompt_gpt_request_size + temp_token:
|
||||
logger.info(
|
||||
"Rozmiar zapytania %s prompt %s temp %s",
|
||||
chat_gpt_config_request_size,
|
||||
prompt_gpt_request_size,
|
||||
temp_token,
|
||||
)
|
||||
if (
|
||||
chat_gpt_config_request_size
|
||||
< token_amount + prompt_gpt_request_size + temp_token
|
||||
):
|
||||
temptable.insert(1, i)
|
||||
chat_gpt_config_request_size += temp_token
|
||||
history.extend(temptable)
|
||||
@@ -661,8 +695,8 @@ async def handle_response(prompt, vykidailo, bartender, history, username, music
|
||||
history.append(temp)
|
||||
logger.info("Rozmiar zapytania po wyslaniu %s", chat_gpt_config_request_size)
|
||||
response = await openAIClient.chat.completions.create(
|
||||
model=algorithm,
|
||||
messages=history)
|
||||
model=algorithm, messages=history
|
||||
)
|
||||
|
||||
logger.info("Historia wysłana:")
|
||||
logger.info(history)
|
||||
@@ -725,8 +759,7 @@ async def get_file(ctx, source, link):
|
||||
item_type, item_id = spotify.parse_spotify_url(link)
|
||||
if item_id:
|
||||
file_list = spotify.fetch_tracks(spotify_ctrl, item_type, link)
|
||||
directory_name = spotify.get_item_name(
|
||||
spotify_ctrl, item_type, item_id)
|
||||
directory_name = spotify.get_item_name(spotify_ctrl, item_type, item_id)
|
||||
url_data = {"urls": []}
|
||||
url_dict = {}
|
||||
url_dict["save_path"] = Path(
|
||||
@@ -961,15 +994,13 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
|
||||
if re.match(pattern, itm, re.IGNORECASE):
|
||||
temp_weight = (
|
||||
search_weight[itr][0]
|
||||
+ (token_weight + (pingu**1.5) /
|
||||
pattern_len) / matched_times
|
||||
+ (token_weight + (pingu**1.5) / pattern_len) / matched_times
|
||||
)
|
||||
search_weight[itr] = temp_weight, music_file_list[itr]
|
||||
matched_times += 1
|
||||
itr += 1
|
||||
|
||||
logger.info("Stworzylem tablice wag zajęło mi to %s",
|
||||
datetime.now() - time_start)
|
||||
logger.info("Stworzylem tablice wag zajęło mi to %s", datetime.now() - time_start)
|
||||
time_start = datetime.now()
|
||||
item_to_search = await max_weight(search_weight)
|
||||
itr = 0
|
||||
@@ -1022,7 +1053,6 @@ async def max_weight(lista):
|
||||
# *=========================================== Define Commands
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="dej_co_ze_spotifaja",
|
||||
description="Podaj link do spotify - sciagnie i doda muzyke",
|
||||
@@ -1068,7 +1098,6 @@ async def dej_co_ze_spotifaja(ctx):
|
||||
logger.info("Spotifaj udany")
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="dej_co_z_jutuba",
|
||||
description="Podaj link do youtube - sciagnie i doda muzyke",
|
||||
@@ -1101,7 +1130,6 @@ async def dej_co_z_jutuba(ctx):
|
||||
logger.info("Jutub udany")
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="update_banlist",
|
||||
description="Jeśli nie wiesz jak użyć tej komendy to nawet nie próbuj",
|
||||
@@ -1141,7 +1169,7 @@ async def update_banlist(ctx):
|
||||
for line in lines:
|
||||
match = re.search(
|
||||
"\\d{18}",
|
||||
line
|
||||
line,
|
||||
# trunk-ignore(codespell/misspelled)
|
||||
) # poprawilem backslash na podwojny bo linter sie czepial
|
||||
if match:
|
||||
@@ -1192,7 +1220,6 @@ async def update_banlist(ctx):
|
||||
await ctx.send("Zrobione tak czy inaczej")
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
nsfw=True,
|
||||
name="get_image_sadox",
|
||||
@@ -1237,7 +1264,6 @@ async def get_image_sadox(ctx):
|
||||
logger.info("Get sadox completed")
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="graj_muzyko",
|
||||
description="Włącza muzykę na kanale #nocna-zmiana.",
|
||||
@@ -1263,7 +1289,6 @@ async def graj_muzyko(ctx):
|
||||
logger.info("Press play on tape completed")
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="cisza",
|
||||
description="Wyłącza muzykę i czyści plejliste.",
|
||||
@@ -1291,7 +1316,6 @@ async def cisza(ctx):
|
||||
logger.info("Stop completed")
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="dalej",
|
||||
description="Przerzuca na następny kawałek",
|
||||
@@ -1316,7 +1340,6 @@ async def dalej(ctx):
|
||||
logger.info("Next completed")
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="daj_mi_chwile",
|
||||
description="Pauzuje",
|
||||
@@ -1341,7 +1364,6 @@ async def daj_mi_chwile(ctx):
|
||||
logger.info("Pause completed")
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="graj_dalej",
|
||||
description="Odpauzowuje",
|
||||
@@ -1365,7 +1387,6 @@ async def graj_dalej(ctx):
|
||||
logger.info("Unpause completed")
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="zagraj_mi_kawalek",
|
||||
description="Wyszukuje w bibliotece muzycznej Hammera kawałek który ma zostać zagrany",
|
||||
@@ -1412,7 +1433,6 @@ async def zagraj_mi_kawalek(ctx):
|
||||
)
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="zrob_mi_plejliste",
|
||||
description="Generuje playliste - param1 - dlugosc, potem slowa wyszukiwania",
|
||||
@@ -1474,7 +1494,6 @@ async def zrob_mi_plejliste(ctx):
|
||||
logger.info("Plejlista zrobiona")
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="przytul", description="Przytul kogoś - daj mention po komendzie :)"
|
||||
)
|
||||
@@ -1511,7 +1530,6 @@ async def przytul(ctx, arg: Optional[discord.Member] = None):
|
||||
)
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(name="fabryczka", description="Historia fabryczki")
|
||||
async def fabryczka(ctx):
|
||||
"""
|
||||
@@ -1525,7 +1543,6 @@ async def fabryczka(ctx):
|
||||
await ctx.send(historia_fabryczki)
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="chata_hammera",
|
||||
description="Czas od ostatniego incydentu w AbsinthHammerTimeSpaceContinuum",
|
||||
@@ -1549,7 +1566,6 @@ async def chata_hammera(ctx):
|
||||
)
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="historia_incydentow_u_hammera",
|
||||
description="Wyswietla liste incydentów które miały miejsce w AbsinthHammerTimeSpaceContinuum.",
|
||||
@@ -1577,7 +1593,6 @@ async def historia_incydentow_u_hammera(ctx):
|
||||
await ctx.send(return_data)
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="reset_the_clock",
|
||||
description="Resetowanie zegara - dostępne wyłącznie dla Hammera",
|
||||
@@ -1630,7 +1645,6 @@ async def get_image_stable_diffusion(ctx):
|
||||
pass
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="zagraj_muzyke_mego_ludu",
|
||||
description="Gra muzyke wyszukana na bazie tematow konwersacji na kanale NZ",
|
||||
@@ -1671,7 +1685,11 @@ async def zagraj_muzyke_mego_ludu(ctx):
|
||||
async with ctx.typing():
|
||||
logger.info("Zaczynam szukać timestamp %s", datetime.now())
|
||||
search_time_glob = datetime.now()
|
||||
file = await wyszukaj(ctx=ctx, how_many=MUZYKA_MOJEGO_LUDU_PLAJLISTA, slowa_kluczowe=final_key_words)
|
||||
file = await wyszukaj(
|
||||
ctx=ctx,
|
||||
how_many=MUZYKA_MOJEGO_LUDU_PLAJLISTA,
|
||||
slowa_kluczowe=final_key_words,
|
||||
)
|
||||
logger.info("Zagraj muzyke mego ludu:wygenerowano plejliste")
|
||||
logger.info(file)
|
||||
logger.info(
|
||||
@@ -1713,13 +1731,14 @@ async def zagraj_muzyke_mego_ludu(ctx):
|
||||
logger.info("Plejlista zrobiona")
|
||||
|
||||
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
@client.hybrid_command(
|
||||
name="parametry_muzyki_mego_ludu",
|
||||
description="Konfiguruje komende zagraj muzyke mojego ludu",
|
||||
guild=discord.Object(id=664789470779932693),
|
||||
)
|
||||
async def parametry_muzyki_mego_ludu(ctx, ile_historii=1500, ile_slow_kluczowych=15, jak_dluga_plejlista=30):
|
||||
async def parametry_muzyki_mego_ludu(
|
||||
ctx, ile_historii=1500, ile_slow_kluczowych=15, jak_dluga_plejlista=30
|
||||
):
|
||||
"""
|
||||
The function `parametry_muzyki_mego_ludu` sets global variables for the number of history entries,
|
||||
number of keywords, and length of playlist for a music application.
|
||||
@@ -1748,18 +1767,31 @@ async def parametry_muzyki_mego_ludu(ctx, ile_historii=1500, ile_slow_kluczowych
|
||||
global MUZYKA_MOJEGO_LUDU_HISTORIA # pylint: disable=global-statement
|
||||
global MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE # pylint: disable=global-statement
|
||||
global MUZYKA_MOJEGO_LUDU_PLAJLISTA # pylint: disable=global-statement
|
||||
logger.info("Długość historii wyszukiwania: %s\n Ilość słów kluczowych: %s\n Długość plejlisty do wygenerowanie: %s", MUZYKA_MOJEGO_LUDU_HISTORIA, MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE, MUZYKA_MOJEGO_LUDU_PLAJLISTA)
|
||||
ctx.send(f"Dotychczasowe wartośći:\n Długość historii wyszukiwania: {MUZYKA_MOJEGO_LUDU_HISTORIA}\n Ilość słów kluczowych: {MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE}\n Długość plejlisty do wygenerowanie:{MUZYKA_MOJEGO_LUDU_PLAJLISTA}")
|
||||
logger.info(
|
||||
"Długość historii wyszukiwania: %s\n Ilość słów kluczowych: %s\n Długość plejlisty do wygenerowanie: %s",
|
||||
MUZYKA_MOJEGO_LUDU_HISTORIA,
|
||||
MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE,
|
||||
MUZYKA_MOJEGO_LUDU_PLAJLISTA,
|
||||
)
|
||||
ctx.send(
|
||||
f"Dotychczasowe wartośći:\n Długość historii wyszukiwania: {MUZYKA_MOJEGO_LUDU_HISTORIA}\n Ilość słów kluczowych: {MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE}\n Długość plejlisty do wygenerowanie:{MUZYKA_MOJEGO_LUDU_PLAJLISTA}"
|
||||
)
|
||||
MUZYKA_MOJEGO_LUDU_HISTORIA = ile_historii
|
||||
MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE = ile_slow_kluczowych
|
||||
MUZYKA_MOJEGO_LUDU_PLAJLISTA = jak_dluga_plejlista
|
||||
logger.info("Długość historii wyszukiwania: %s\n Ilość słów kluczowych: %s\n Długość plejlisty do wygenerowanie: %s", MUZYKA_MOJEGO_LUDU_HISTORIA, MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE, MUZYKA_MOJEGO_LUDU_PLAJLISTA)
|
||||
ctx.send(f"Zmienione wartośći:\n Długość historii wyszukiwania: {MUZYKA_MOJEGO_LUDU_HISTORIA}\n Ilość słów kluczowych: {MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE}\n Długość plejlisty do wygenerowanie:{MUZYKA_MOJEGO_LUDU_PLAJLISTA}")
|
||||
logger.info(
|
||||
"Długość historii wyszukiwania: %s\n Ilość słów kluczowych: %s\n Długość plejlisty do wygenerowanie: %s",
|
||||
MUZYKA_MOJEGO_LUDU_HISTORIA,
|
||||
MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE,
|
||||
MUZYKA_MOJEGO_LUDU_PLAJLISTA,
|
||||
)
|
||||
ctx.send(
|
||||
f"Zmienione wartośći:\n Długość historii wyszukiwania: {MUZYKA_MOJEGO_LUDU_HISTORIA}\n Ilość słów kluczowych: {MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE}\n Długość plejlisty do wygenerowanie:{MUZYKA_MOJEGO_LUDU_PLAJLISTA}"
|
||||
)
|
||||
except discord.ext.commands.errors.BadArgument as exce:
|
||||
ctx.send("Spierdalaj")
|
||||
logger.info(exce)
|
||||
|
||||
|
||||
# *================================== Run
|
||||
# trunk-ignore(mypy/arg-type)
|
||||
client.run(TOKEN)
|
||||
|
||||
+1707
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,58 @@
|
||||
# trunk-ignore-all(pylint/C0301)
|
||||
|
||||
FILE_SIZE_LIMIT = 100000 * 1024
|
||||
SOURCE = "/mnt/n/scimag_2020-05-30.sql/scimag_2020-05-30.sql"
|
||||
OUTPUT_FOLDER = "/mnt/n/scimag_2020-05-30.sql/"
|
||||
OUTPUT_FILE_SCHEMA = "_scimag_chunk.sql"
|
||||
|
||||
|
||||
def smart_write(lines, file):
|
||||
"""
|
||||
The function `smart_write` encodes the input lines to UTF-8, writes them to a file, and returns the
|
||||
size of the encoded bytes.
|
||||
|
||||
:param lines: The `lines` parameter in the `smart_write` function is a string that contains the text
|
||||
content that you want to write to a file
|
||||
:param file: The `file` parameter in the `smart_write` function is expected to be a file object that
|
||||
has been opened in write mode. This file object will be used to write the encoded `lines` to a file
|
||||
:return: The function `smart_write` returns the size of the encoded bytes of the input `lines` in
|
||||
bytes.
|
||||
"""
|
||||
encoded_bytes = lines.encode("utf-8")
|
||||
size_in_bytes = len(encoded_bytes)
|
||||
file.write(lines)
|
||||
|
||||
return size_in_bytes
|
||||
|
||||
|
||||
def cut_my_life_into_pieces(source, output_folder, output_file):
|
||||
"""
|
||||
The function `cut_my_life_into_pieces` reads a source file, splits its content into smaller parts
|
||||
based on a file size limit, and writes these parts to separate output files in a specified output
|
||||
folder.
|
||||
|
||||
:param source: The `source` parameter in the `cut_my_life_into_pieces` function is the file path of
|
||||
the source file that you want to process and split into smaller pieces
|
||||
:param output_folder: The `output_folder` parameter in the `cut_my_life_into_pieces` function
|
||||
represents the directory where the output files will be saved. It should be a string that specifies
|
||||
the path to the folder where you want to store the output files generated by the function. For
|
||||
example, it could be something like
|
||||
:param output_file: The `output_file` parameter in the `cut_my_life_into_pieces` function represents
|
||||
the name of the output file that will be created for each segment of the source file. It will be
|
||||
appended with a number to differentiate between different segments
|
||||
"""
|
||||
with open(source, encoding="utf-8") as infile:
|
||||
output_size = 0
|
||||
output_no = 0
|
||||
|
||||
for line in infile:
|
||||
if output_size > FILE_SIZE_LIMIT:
|
||||
output_no += 1
|
||||
output_size = 0
|
||||
op_file_name = str(output_no) + output_file
|
||||
with open(
|
||||
output_folder + op_file_name,
|
||||
"a",
|
||||
encoding="utf-8",
|
||||
) as op_file:
|
||||
output_size += smart_write(line, op_file)
|
||||
@@ -0,0 +1,33 @@
|
||||
"""
|
||||
Kluczowe jest zeby po każdej linijce pokazywał która to jest, oraz po pliku
|
||||
"""
|
||||
|
||||
import netrc
|
||||
|
||||
import mysql.connector
|
||||
|
||||
NETRC_FILE = "/home/mtuszowski/.netrc"
|
||||
|
||||
netrc_mod = netrc.netrc(NETRC_FILE)
|
||||
REMOTE_HOST_NAME = "sql_localhost"
|
||||
authTokens = netrc_mod.authenticators(REMOTE_HOST_NAME)
|
||||
|
||||
mydb = mysql.connector.connect(
|
||||
host="localhost", user="root", password="root", database="scihubdois"
|
||||
)
|
||||
mycursor = mydb.cursor()
|
||||
|
||||
mycursor.execute("SELECT * FROM scimag")
|
||||
for x in mycursor:
|
||||
print(x)
|
||||
|
||||
|
||||
file_list = ""
|
||||
for file in file_list:
|
||||
|
||||
with open(
|
||||
"/mnt/n/scimag_2020-05-30.sql/{}".format(file), encoding="utf-8"
|
||||
) as infile:
|
||||
pass
|
||||
result = mycursor.execute("SHOW databases")
|
||||
# trunk-ignore(mypy/union-attr)
|
||||
@@ -0,0 +1,26 @@
|
||||
"""
|
||||
This Python code snippet is connecting to a MySQL database
|
||||
using the `mysql.connector` library and fetching data from a table named `scimag`
|
||||
Here is a breakdown of what the code is doing:
|
||||
"""
|
||||
|
||||
import netrc
|
||||
|
||||
import mysql.connector
|
||||
|
||||
NETRC_FILE = "/home/mtuszowski/.netrc"
|
||||
netrc_mod = netrc.netrc(NETRC_FILE)
|
||||
REMOTE_HOST_NAME = "192.168.1.192"
|
||||
authTokens = netrc_mod.authenticators(REMOTE_HOST_NAME)
|
||||
|
||||
mydb = mysql.connector.connect(
|
||||
host=REMOTE_HOST_NAME,
|
||||
user=authTokens[0],
|
||||
password=authTokens[2],
|
||||
database="scihubdois",
|
||||
)
|
||||
mycursor = mydb.cursor()
|
||||
|
||||
mycursor.execute("SELECT * FROM scimag WHERE Title Like 'spider%'")
|
||||
for x in mycursor:
|
||||
print(x)
|
||||
Reference in New Issue
Block a user