Intermediate commits (oldest → newest):
- Library update
- Upgrade gpt model
- Nowy lepszy trunk
- modified
- Kurwa bugfix pod windowsa
- Fixed playlist gen
- Mala poprawka na rozmiar plikow pamieci
- Funkcjonalnosc logowania incydentow w Absinth Eldritch Horror Hammertimespace Continuum
- Reakcje ladacznicy, poprawka na mention w reset the clock
- Dodana procedura asynchronicznej generacji iteratora oraz komentarz w jaki sposob inaczej przerobic fora na asynchroniczny. Przydatne ze wzgledu na to ze szukajka nadal blokuje heartbeat bota - co skutkuje warningnami i wyjatkami
- Linting
- Linting is done
This commit is contained in:
2025-10-30 16:58:53 +01:00
parent 3a843abccf
commit e6ccb5e48f
13 changed files with 1920 additions and 316 deletions
+1
View File
@@ -6,3 +6,4 @@
plugins
user_trunk.yaml
user.yaml
tmp
+2
View File
@@ -0,0 +1,2 @@
[settings]
profile=black
-3
View File
@@ -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
+5
View File
@@ -0,0 +1,5 @@
# Generic, formatter-friendly config.
select = ["B", "D3", "E", "F"]
# Never enforce `E501` (line length violations). This should be handled by formatters.
ignore = ["E501"]
+23 -30
View File
@@ -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.5
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.8
- black@24.3.0
- codespell
- checkov@3.2.48
- git-diff-check
- isort@5.13.2
- pylint
- markdownlint@0.39.0
- prettier@3.2.5
- ruff@0.3.4
- trivy@0.50.1
- trufflehog@3.71.0
- yamllint@1.35.1
actions:
disabled:
- trunk-announce
-2
View File
@@ -1,6 +1,4 @@
{
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"trunk.inlineDecorators": true,
"trunk.inlineDecoratorsForAllExtensions": true,
"trunk.showPreexistingIssues": true,
+29 -280
View File
@@ -35,13 +35,12 @@ import pdf2image
import PyPDF2
import requests
import spotipy
import tiktoken
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",
@@ -69,10 +68,6 @@ MEMORY_FIVE_MUZYKA = ""
SETTINGS_FILE = ""
ENCODING = ""
GRAPHICS_PATH = ""
MUZYKA_MOJEGO_LUDU_HISTORIA = 1500
MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE = 15
MUZYKA_MOJEGO_LUDU_PLAJLISTA = 30
# *=========================================== Platform Specific Predefines
if platform in ("linux", "linux2"):
@@ -80,7 +75,6 @@ if platform in ("linux", "linux2"):
if "microsoft-standard" in uname().release:
LOGFILE = "/home/mtuszowski/conjurer/discord.log"
MEMORY_FIVE_SIARA = "/home/mtuszowski/conjurer/pamiec.json"
SYSTEM_GPT_SETTINGS = "/home/mtuszowski/conjurer/system_gpt_settings.json"
MEMORY_FIVE_MUZYKA = "/home/mtuszowski/conjurer/pamiec_muzyki.json"
MUSIC_FOLDER = "/mnt/g/Muzyka/"
SETTINGS_FILE = "/home/mtuszowski/conjurer/settings.json"
@@ -94,7 +88,6 @@ if platform in ("linux", "linux2"):
else:
LOGFILE = "/home/pi/Conjurer/discord.log"
MEMORY_FIVE_SIARA = "/home/pi/Conjurer/pamiec.json"
SYSTEM_GPT_SETTINGS = "/home/pi/Conjurer/system_gpt_settings.json"
MEMORY_FIVE_MUZYKA = "/home/pi/Conjurer/pamiec_muzyki.json"
MUSIC_FOLDER = "/home/pi/RetroPie/mp3/"
SETTINGS_FILE = "/home/pi/Conjurer/settings.json"
@@ -109,7 +102,6 @@ if platform in ("linux", "linux2"):
elif platform == "win32":
LOGFILE = "discord.log"
MEMORY_FIVE_SIARA = "pamiec.json"
SYSTEM_GPT_SETTINGS = "system_gpt_settings.json"
MEMORY_FIVE_MUZYKA = "pamiec_muzyki.json"
MUSIC_FOLDER = "G:\\Muzyka\\"
SETTINGS_FILE = "settings.json"
@@ -170,10 +162,6 @@ for mp3_item in Path.glob(Path(MUSIC_FOLDER), "**/*.mp3"):
if platform == "win32":
temp_music_file = temp_music_file.replace("/", "\\")
music_file_list.append(temp_music_file)
with open(SYSTEM_GPT_SETTINGS, "r+", encoding=ENCODING) as temp_settings_file:
# First we load existing data into a dict.
GPT_SETTINGS = json.load(temp_settings_file)
with open(MEMORY_FIVE_SIARA, "r+", encoding=ENCODING) as temp_memory_file:
# First we load existing data into a dict.
MESSAGE_TABLE = json.load(temp_memory_file)
@@ -183,7 +171,6 @@ with open(MEMORY_FIVE_MUZYKA, "r+", encoding=ENCODING) as temp_music_memory_file
with open(SETTINGS_FILE, "r", encoding=ENCODING) as f_settings_file:
data = json.load(f_settings_file)
word_reactions = data["word_reactions"]
cyclic_words = data["cyclic_words"]
historia_fabryczki = data["fabryczka"]
for key in word_reactions:
word_reactions[key][2] = datetime.now()
@@ -200,6 +187,7 @@ async def on_ready():
logger.debug("%s has connected to Discord!", client.user)
await client.change_presence(activity=discord.Game(name="Axe Throwing Darts"))
await client.tree.sync()
# await tree.sync(guild=discord.Object(id=Your guild id))
await check()
@@ -278,33 +266,26 @@ async def on_message(message):
word_reactions[word][2] = datetime.now()
# TODO: drobne literówki, mentiony, spacja przed dwukropkiem. napraw.
kondziu_mentioned = False
for mention in message.mentions:
if mention == client.user:
kondziu_mentioned = True
if kondziu_mentioned or "conjurer:" in message.content:
if "conjurer:" in message.content:
async with channel.typing():
logger.debug("Procedura chatu")
message.content = message.content.replace("conjurer: ", "")
prompt = message.content
if message.author.nick:
username = message.author.nick
else:
username = message.author.name
vykidailo = False
bartender = False
if kondziu_mentioned:
prompt = message.clean_content
else:
prompt = message.content
for role in message.author.roles:
if role.name == "Vykidailo":
vykidailo = True
if role.name == "Bartender":
bartender = True
global MESSAGE_TABLE # pylint: disable=global-statement
result, MESSAGE_TABLE = await handle_response(
prompt, vykidailo, bartender, MESSAGE_TABLE, username, False
)
@@ -335,29 +316,6 @@ 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
message according to the given model.
:param message: A string containing the message or text from which you want to count the number of
tokens
:param model: The model parameter refers to a language model or tokenizer that can be used to
tokenize the input string. It could be a pre-trained model or a custom tokenizer
"""
tokens_per_message = 3
tokens_per_name = 1
chat_gpt_encoding = tiktoken.encoding_for_model(model)
num_tokens = 0
num_tokens += tokens_per_message
for keys, values in message.items():
num_tokens += len(chat_gpt_encoding.encode(values))
if keys == "role":
num_tokens += tokens_per_name
num_tokens += 3 # every reply is primed with <|start|>assistant<|message|>
return num_tokens
async def connect(ctx, arg=None):
"""
@@ -490,16 +448,8 @@ async def play(ctx, zamawial=None, arg=None):
async def check():
"""Funkcja sprawdzająca czy grać następny kawałek."""
last_spontaneous_call = datetime.now()
while True:
tdelta = datetime.now() - last_spontaneous_call
tdelta = tdelta.total_seconds()
if tdelta > 34000:
channel = client.get_channel(1062047571557744721)
last_spontaneous_call = datetime.now()
with channel.typing():
message = get_random_cyclic_message()
await channel.send(message)
# TODO: Tu dołożyć skanowanie rozmiaru pliku logowania oraz plików pamięci i przenoszenie ich na większy dysk.
# trunk-ignore(codespell/misspelled)
# TODO: dlaczego sie tu wypierdala
if client.voice_clients:
@@ -567,19 +517,7 @@ async def check():
await asyncio.sleep(60)
async def get_random_cyclic_message():
"""
The function `get_random_cyclic_message` returns a random cyclic message from a list of cyclic
words.
:return: a random cyclic message from the list `cyclic_words`.
"""
messnum = random.randint(0, len(cyclic_words)-1)
return cyclic_words[messnum][0]
# trunk-ignore(pylint/R0914)
# trunk-ignore(pylint/R0913)
# trunk-ignore(pylint/R0915)
async def handle_response(prompt, vykidailo, bartender, history, username, music):
"""
Handle responses by appending them to a history, use OpenAI to
@@ -622,49 +560,22 @@ async def handle_response(prompt, vykidailo, bartender, history, username, music
# convert back to json.
json.dump(file_data, file_memory, indent=4)
history = []
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():
if not reakcja[3]:
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)
# * append bo pierwszy index
# * extend bo 20 ostatnich
if music:
algorithm = "gpt-3.5-turbo-16k"
table = message_table_muzyka
token_amount = 10700
history.append(message_table_muzyka[0])
history.extend(message_table_muzyka[-20:])
else:
table = MESSAGE_TABLE
algorithm = "gpt-4"
token_amount = 7000
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:
temptable.insert(1, i)
chat_gpt_config_request_size += temp_token
history.extend(temptable)
temp = {"role": "user", "content": final_prompt}
history.append(temp)
logger.info("Rozmiar zapytania po wyslaniu %s", chat_gpt_config_request_size)
response = await openai.ChatCompletion.acreate(
model=algorithm, messages=history
)
history.append(MESSAGE_TABLE[0])
history.extend(MESSAGE_TABLE[-20:])
logger.info("Historia wysłana:")
logger.info(history)
await asyncio.sleep(15)
logger.debug(history)
response = await openai.ChatCompletion.acreate(
model="gpt-3.5-turbo", messages=history
)
await asyncio.sleep(10)
result = ""
logger.debug("Odpowiedzi")
logger.info(response)
logger.debug(response.choices)
for choice in response.choices:
result += choice.message.content
@@ -845,42 +756,10 @@ async def async_iterator_generator(range_of_iterable):
"""
async def get_stats(ctx, history_limit):
"""
The `get_stats` function retrieves the message history of a specific channel and counts the
frequency of each word in the messages.
:param ctx: The `ctx` parameter is an object that represents the context of the command being
executed. It contains information such as the message, the author, the server, and other relevant
details
:param history_limit: The `history_limit` parameter is the maximum number of messages to retrieve
from the channel history. It determines how far back in time the statistics will be calculated
:return: The function `get_stats` returns a dictionary `stats` that contains the frequency count of
words found in the messages from the specified channel.
"""
channel_id = 1062047367337095268
async with ctx.typing():
stats = {}
channel = client.get_channel(channel_id)
messages = [message async for message in channel.history(limit=history_limit)]
# traverse the iterable of awaitables
for message in messages:
# await and get the result from the awaitable
result = message.content
words = result.split()
for word in words:
if word in stats:
stats[word] += 1
else:
stats[word] = 1
for name, how_many in stats.items():
yield name, how_many
# trunk-ignore(pylint/R0914)
# trunk-ignore(pylint/R0915)
# trunk-ignore(pylint/R0912)
async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
async def wyszukaj(ctx, how_many=0):
"""
Take in a context object and an optional integer parameter "how_many" and perform search
operation on music library.
@@ -894,10 +773,7 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
"""
# TODO: Potem dorobić wyszukiwania po kawałkach słów
# i sieć neuronową z możliwością wyrażenia opinii o dopasowaniu.
if slowa_kluczowe:
word_list = slowa_kluczowe
else:
word_list = ctx.message.content.split()
word_list = ctx.message.content.split()
logger.info("Wyszukuje")
search_weight = []
for _ in range(len(music_file_list)):
@@ -908,11 +784,11 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
skip_start = 2
else:
skip_start = 1
async for word in async_iterator_generator(word_list[skip_start:]):
for word in word_list[skip_start:]:
token_weight = len(word)
logger.info("Słowo kluczowe: %s", word)
itr = 0
async for file in async_iterator_generator(music_file_list):
for file in music_file_list:
file = file.split(SEPARATOR_FILE_PATH)
char_remove = [
@@ -938,9 +814,9 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
"mp3",
]
all_words = []
async for f_iter in async_iterator_generator(file):
async for char in async_iterator_generator(char_remove):
f_iter = await remove_characters(f_iter, char)
for f_iter in file:
for char in char_remove:
f_iter = f_iter.replace(char, "")
tmp = f_iter.split()
all_words.extend(tmp)
pingu = 1
@@ -950,7 +826,7 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
else:
skip = 4
matched_times = 1
async for itm in async_iterator_generator(all_words[skip:]):
for itm in all_words[skip:]:
pingu += 1
pattern = ".*" + word + ".*"
if re.match(pattern, itm, re.IGNORECASE):
@@ -986,18 +862,6 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
return return_list
async def remove_characters(string, character):
"""
The `remove_characters` function removes all occurrences of a specified character from a given
string.
:param string: The string parameter is the input string from which characters will be removed
:param character: The character parameter is the character that you want to remove from the string
:return: a new string where all occurrences of the specified character have been removed.
"""
return string.replace(character, "")
async def max_weight(lista):
"""
Take a list of weights and return the maximum weight.
@@ -1455,7 +1319,7 @@ async def zrob_mi_plejliste(ctx):
if metadata.tag.title:
reply += " z prywatnej kolekcji Hammera i na Twoją specjalną rpośbę.\n"
else:
reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera.\n"
reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera."
index += 1
if len(reply) > 1800:
@@ -1625,14 +1489,7 @@ 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",
guild=discord.Object(id=664789470779932693),
)
# trunk-ignore(pylint/R0912)
# trunk-ignore(pylint/R0915)
# @client.hybrid_command()
async def zagraj_muzyke_mego_ludu(ctx):
"""
Play completeley random playlist based on messaging history.
@@ -1642,117 +1499,9 @@ async def zagraj_muzyke_mego_ludu(ctx):
channel, the author, and other relevant details. In this case, it is being passed as a parameter to
the `get_image
"""
stats = {}
if ctx:
logger.info("Zagraj muzyke mego ludu: wywolane")
stat_iter = get_stats(ctx, MUZYKA_MOJEGO_LUDU_HISTORIA)
async for name, how_many in stat_iter:
if len(name) > 3:
stats[name] = how_many
sorted_stats = sorted(stats.items(), key=lambda x: x[1])
logger.info("Zagraj muzyke mego ludu:zebrano statystyki")
key_words = []
for stat in sorted_stats:
key_words.append(stat[0])
logger.info(sorted_stats[:MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE])
logger.info(key_words[:MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE])
logger.info(sorted_stats[-MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE:])
logger.info(key_words[-MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE:])
final_key_words = key_words[:MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE]
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())
search_time_glob = datetime.now()
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(
"Koniec szukania(timestamp %s zajęło %s",
datetime.now(),
datetime.now() - search_time_glob,
)
index = 1
if file:
for plik in file:
global MUZYKA # pylint: disable=global-variable-not-assigned
MUZYKA["queue"].insert(0, plik[1])
MUZYKA["requestor"].insert(0, ctx.author)
metadata = eyed3.load(plik[1])
if metadata and metadata.tag:
if metadata.tag.title:
reply += f"{index} {metadata.tag.title}"
else:
reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera."
if metadata.tag.artist:
reply += f" wykonawcy {metadata.tag.artist}"
if metadata.tag.album:
reply += f" z albumu {metadata.tag.album}"
if metadata.tag.title:
reply += " z prywatnej kolekcji Hammera i na Twoją specjalną rpośbę.\n"
else:
reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera.\n"
index += 1
if len(reply) > 1800:
await ctx.send(reply)
reply = ""
else:
await ctx.send(
"Obawiam się że nie mogę nic znaleźć u siebie. Spróbuj komendy '$dej_co_ze_spotifaja' jeśli masz link"
)
await ctx.send(reply)
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):
"""
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.
:param ctx: The `ctx` parameter is typically used in Discord.py, a Python library for creating
Discord bots. It represents the context of the command being executed, including information about
the message, the server, and the user who invoked the command
:param ile_historii: The parameter "ile_historii" represents the number of history items for the
music playlist, defaults to 1500 (optional)
:param ile_slow_kluczowych: The parameter "ile_slow_kluczowych" represents the number of keywords or
key phrases related to music that you want to include in your analysis or search, defaults to 30
(optional)
:param jak_dluga_plejlista: The parameter "jak_dluga_plejlista" determines the length of the
playlist. It specifies how many songs should be included in the playlist, defaults to 30 (optional)
"""
if ctx:
async with ctx.typing():
# if ':' in ile_historii:
# _, _, ile_historii = ile_historii.partition(':')
# if ':' in ile_slow_kluczowych:
# _, _, ile_slow_kluczowych = ile_slow_kluczowych.partition(':')
# if ':' in jak_dluga_plejlista:
# _, _, jak_dluga_plejlista = jak_dluga_plejlista.partition(':')
try:
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}")
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}")
except discord.ext.commands.errors.BadArgument as exce:
ctx.send("Spierdalaj")
logger.info(exce)
pass
# *================================== Run
+1707
View File
File diff suppressed because it is too large Load Diff
+58
View File
@@ -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)
+33
View 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)
+35
View File
@@ -0,0 +1,35 @@
from pathlib import Path, PurePath
from platform import uname
from sys import platform
MUSIC_FOLDER = ""
if platform in ("linux", "linux2"):
SEPARATOR_FILE_PATH = "/"
if "microsoft-standard" in uname().release:
LOGFILE = "/home/mtuszowski/conjurer/discord_mus_service.log"
MUSIC_FOLDER = "/mnt/g/Muzyka/"
NETRC_FILE = "/home/mtuszowski/.netrc"
LOGSTORE = "/home/mtuszowski/conjurer/logs/"
ENCODING = "utf-8"
GRAPHICS_PATH = "/home/mtuszowski/conjurer/Conjurer_graphics/"
else:
LOGFILE = "/home/pi/Conjurer/discord_mus_service.log"
MEMORY_FIVE_SIARA = "/home/pi/Conjurer/pamiec.json"
SYSTEM_GPT_SETTINGS = "/home/pi/Conjurer/system_gpt_settings.json"
MEMORY_FIVE_MUZYKA = "/home/pi/Conjurer/pamiec_muzyki.json"
MUSIC_FOLDER = "/home/pi/RetroPie/mp3/"
SETTINGS_FILE = "/home/pi/Conjurer/settings.json"
NETRC_FILE = "/home/pi/.netrc"
LOGSTORE = "/home/pi/RetroPie/logs/"
ACCIDENT_LOG = "/home/pi/Conjurer/accident_log.json"
ENCODING = "utf-8"
GRAPHICS_PATH = "/home/pi/RetroPie/Conjurer_graphics/"
DIR_PATH_SADOX = "/home/pi/RetroPie/Fansadox/"
music_file_list = []
for mp3_item in Path.glob(Path(MUSIC_FOLDER), "**/*.mp3"):
temp_music_file = mp3_item.as_posix()
if platform == "win32":
temp_music_file = temp_music_file.replace("/", "\\")
music_file_list.append(temp_music_file)
+1 -1
View File
@@ -211,7 +211,7 @@
false,
false
],
"burdel": [
"burdel\\b": [
"Oooo... Hammer nadal nie zmienił firanek - ale całkiem nieźle sprząta, jebaniutki.",
15.0,
0,
+26
View File
@@ -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)