Compare commits

...

54 Commits

Author SHA1 Message Date
gitea 82273df13c This is seriously last fix
description update

last fix ?

Small fix

Kolejny fix

Final fix

FX2

fx
2024-04-10 15:26:29 +02:00
gitea ae0d807714 Pornol dl2 2024-04-10 15:26:28 +02:00
gitea edc0a4a502 Pornol dl 1 2024-04-10 15:26:28 +02:00
gitea 39ecb82395 Coroutine fix 2024-04-10 15:26:18 +02:00
gitea d8f5bd1805 Plan for next release 2024-04-10 15:26:18 +02:00
gitea 3f68c6aaed Test
aaa

aa

Bugfixing et masse

bbb

asas

aas

asas

aa

as

qq

as

as

as

as

as

aaa

asa

nn

aa

sda

88

asa

sasa

adsa

a

as

asdas

Final version before tests

Fix1

aa

aa

fx

dx

:)

aa

Hopefully last fix

aaa

aaa

bbb

bb

dd

aa

sdae

aa

bb

aa

kk

a

Fix

fx

aa

deploy

fx

asas

bb

as

fx

fx

aa

aa

mess

kk

A

fix

aa

aa

Viwe fix

a

test

a

aa

FX
2024-04-10 15:26:18 +02:00
gitea aee53de258 Installer
`12`

sa

asda

123

AA

Test
2024-04-10 15:26:12 +02:00
gitea 20caa5600a name change and othre bugfixes
fix

fax

fx

121

as

aa

fx

f5

fx4

fix

fx1
2024-04-10 15:26:06 +02:00
gitea 4a4f8df06e Work on deployment 2024-04-10 15:26:06 +02:00
gitea 6c9f01971a Bugfixes
asdasdasd

:)

asa

asdasda

aa

:)

asa

aa

:)

:)

sa

as

aa

aa

aa

aaa

as

11

aa

11

xxx

dd

ds

aa

a1

aa

Test

Suppress

Move

Installer

aaa

Serwis

`12`

aa

xd

asasa

xd

aa

asa

aaa

:)

Hejka

a

xd

aa

aaas

555

aaa

asa

aa

11

aaa

aaa

as

sa

async

asda

00

123

123

aa

as

ss

as

a

sa

aa

1

RES

T

Hejko

aa

11

AA

test

Test
2024-04-10 15:26:05 +02:00
gitea 211c45891e Work on deployment
fix

fax

fx

Fin part

fx

121

Temp fix

as

aa

fx

f5

fx4

fix

fx1

Work on deployment
2024-04-10 15:26:00 +02:00
gitea de3d6a8f42 Install options 2024-04-10 15:25:59 +02:00
gitea 9c027fd636 Waitress 2024-04-10 15:25:59 +02:00
gitea 9af6b8e187 Bugfixing
add

Test 1

Test 2

Test3

Test phase 2

FIx 1

Fix 2

Fix 10

Fix 11

Fix 13

Fix 14

Fix 15

Test 1

Test 2

Test 3

Fix 15

Test 7

Fix 18

Test 20

Done

Minor 1
2024-04-10 15:25:59 +02:00
gitea d00ede6c62 Service
FIx
2024-04-10 15:25:59 +02:00
gitea 5b7d7b31b2 Linux conf files 2024-04-10 15:25:59 +02:00
gitea 00172920a9 Waitress
Deploy.shgit
2024-04-10 15:25:59 +02:00
gitea 5e3ffdacb5 Minor fix 2
Minor 1

Done

Test 20

Fix 18

Test 7

Fix 15

Test 3

Test 2

Test 1

Fix 15

Fix 14

Fix 13

Fix 12

Fix 11

Fix 10

Fix 9

Fix 2

FIx 1

Test phase 2

Test 8

Final test

Test 5

Test 4

Test3

Test 2

Test 1

add
2024-04-10 15:25:59 +02:00
gitea 471d4e923b Service
FIx
2024-04-10 15:25:53 +02:00
gitea d11f5d8d24 New files for flask services 2024-04-10 15:25:53 +02:00
gitea cfb26d95a4 Nowy lepszy trunk 2024-04-10 15:25:53 +02:00
gitea 5e14299fef Additional lines of code 2024-04-10 15:25:40 +02:00
gitea 126de9a4a4 Fix 2024-04-10 15:16:22 +02:00
gitea 0d132983fc Fix 2.0 2024-04-10 15:05:43 +02:00
gitea 67cae0e68e Fix 2024-04-10 15:05:43 +02:00
gitea eabd0e8e1e Nope 2024-04-10 15:05:43 +02:00
gitea f7c91e3874 Test chat gpt4 2024-04-10 15:05:43 +02:00
gitea c224b2ccc8 Hejo 2024-04-10 15:05:43 +02:00
gitea 3ca9f2c6f3 -1 2024-04-10 15:04:41 +02:00
gitea c52d55e0a2 +1 2024-04-10 15:04:41 +02:00
gitea e1fa15abb3 Async 2024-04-10 15:04:41 +02:00
gitea 74c76e639d Async fix 2024-04-10 15:04:41 +02:00
gitea 35a65e48e9 And even more async 2024-04-10 15:04:41 +02:00
gitea 5d5c136b41 More async 2024-04-10 15:04:40 +02:00
gitea b9fbc0f910 Async wyszukaj 2024-04-10 15:04:40 +02:00
gitea fd742c8f1c Parametryzacja "muzyki mojego ludu" 2024-04-10 15:04:40 +02:00
gitea 1c240342c5 Logging 2024-04-10 15:04:37 +02:00
gitea 7bd0c0aca4 Fix 2.6 2024-04-10 15:04:37 +02:00
gitea 7c8ad99743 Fix 2 2024-04-10 15:04:37 +02:00
gitea 90896fa9be Fix 1 2024-04-10 15:04:37 +02:00
gitea e3bec6bc11 Playlist based on chat history 2024-04-10 15:04:37 +02:00
gitea aa00045dec Trunk + mod 2024-04-10 15:04:32 +02:00
gitea 06e3671ec2 Linting is done 2024-04-10 15:04:22 +02:00
gitea 0879796cc6 Linting 2024-04-10 15:04:13 +02:00
gitea 9f756b3092 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
2024-04-10 15:04:09 +02:00
gitea 579a3f2a52 Reakcje ladacznicy, poprawka na mention w reset the clock 2024-04-10 15:04:09 +02:00
gitea 5505022dbb Funkcjonalnosc logowania incydentow w Absinth Eldritch Horror
Hammertimespace Continuum
2024-04-10 15:04:05 +02:00
gitea d2e5a34b87 Mala poprawka na rozmiar plikow pamieci 2024-04-10 15:03:55 +02:00
gitea c7696fafdc Fixed playlist gen 2024-04-10 15:03:43 +02:00
gitea 7f3de2ea13 Kurwa bugfix pod windowsa 2024-04-10 15:03:42 +02:00
gitea ec505f050f modified 2024-04-10 14:22:01 +02:00
gitea f55c4ce1a7 Nowy lepszy trunk
Additional lines of code

1

AAA
2024-04-10 14:22:00 +02:00
gitea 432abc73b9 Upgrade gpt model 2024-04-10 14:22:00 +02:00
gitea cdaf2589b3 Library update
fix

1111

tezz
2024-04-10 14:22:00 +02:00
26 changed files with 5156 additions and 166 deletions
+5
View File
@@ -6,3 +6,8 @@
plugins plugins
user_trunk.yaml user_trunk.yaml
user.yaml user.yaml
<<<<<<< HEAD
tmp
=======
tools
>>>>>>> c7dc465 (Parametryzacja "muzyki mojego ludu")
+2
View File
@@ -0,0 +1,2 @@
[settings]
profile=black
-3
View File
@@ -2,9 +2,6 @@ rules:
quoted-strings: quoted-strings:
required: only-when-needed required: only-when-needed
extra-allowed: ["{|}"] extra-allowed: ["{|}"]
empty-values:
forbid-in-block-mappings: true
forbid-in-flow-mappings: true
key-duplicates: {} key-duplicates: {}
octal-values: octal-values:
forbid-implicit-octal: true 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"]
+37 -7
View File
@@ -1,19 +1,29 @@
# 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 version: 0.1
cli: cli:
version: 1.14.2 <<<<<<< HEAD
version: 1.20.1
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
plugins: plugins:
sources: sources:
- id: trunk - id: trunk
ref: v1.2.1 ref: v1.4.5
uri: https://github.com/trunk-io/plugins
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
=======
version: 1.12.1
plugins:
sources:
- id: trunk
ref: v0.0.22
uri: https://github.com/trunk-io/plugins uri: https://github.com/trunk-io/plugins
lint: lint:
enabled: enabled:
- checkov@2.4.9
- yamllint@1.32.0
- actionlint@1.6.25 - actionlint@1.6.25
- markdownlint@0.35.0 - markdownlint@0.35.0
- trivy@0.44.1 - trivy@0.43.1
- trufflehog@3.54.0 - trufflehog@3.44.0
- pylint - pylint
- codespell - codespell
- cspell - cspell
@@ -33,11 +43,31 @@ lint:
- yapf - yapf
- gitleaks - gitleaks
>>>>>>> c7dc465 (Parametryzacja "muzyki mojego ludu")
runtimes: runtimes:
enabled: enabled:
- go@1.19.5
- node@18.12.1 - node@18.12.1
- python@3.10.8 - python@3.10.8
<<<<<<< HEAD
# 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
=======
>>>>>>> c7dc465 (Parametryzacja "muzyki mojego ludu")
actions: actions:
disabled: disabled:
- trunk-announce - trunk-announce
-2
View File
@@ -1,6 +1,4 @@
{ {
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"trunk.inlineDecorators": true, "trunk.inlineDecorators": true,
"trunk.inlineDecoratorsForAllExtensions": true, "trunk.inlineDecoratorsForAllExtensions": true,
"trunk.showPreexistingIssues": true, "trunk.showPreexistingIssues": true,
+113 -148
View File
@@ -35,12 +35,11 @@ import pdf2image
import PyPDF2 import PyPDF2
import requests import requests
import spotipy import spotipy
import tiktoken
from discord.ext import commands from discord.ext import commands
from spotipy.oauth2 import SpotifyClientCredentials from spotipy.oauth2 import SpotifyClientCredentials
import yt_dlp
from spotify_dl import youtube as youtube_download from spotify_dl import youtube as youtube_download
from spotify_dl import spotify from spotify_dl import spotify
Music_Config = TypedDict( Music_Config = TypedDict(
@@ -70,9 +69,10 @@ SETTINGS_FILE = ""
ENCODING = "" ENCODING = ""
GRAPHICS_PATH = "" GRAPHICS_PATH = ""
MUZYKA_MOJEGO_LUDU_HISTORIA = 1500 MUZYKA_MOJEGO_LUDU_HISTORIA = 1500
MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE = 15 MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE = 30
MUZYKA_MOJEGO_LUDU_PLAJLISTA = 30 MUZYKA_MOJEGO_LUDU_PLAJLISTA = 30
# *=========================================== Platform Specific Predefines # *=========================================== Platform Specific Predefines
if platform in ("linux", "linux2"): if platform in ("linux", "linux2"):
@@ -80,7 +80,6 @@ if platform in ("linux", "linux2"):
if "microsoft-standard" in uname().release: if "microsoft-standard" in uname().release:
LOGFILE = "/home/mtuszowski/conjurer/discord.log" LOGFILE = "/home/mtuszowski/conjurer/discord.log"
MEMORY_FIVE_SIARA = "/home/mtuszowski/conjurer/pamiec.json" 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" MEMORY_FIVE_MUZYKA = "/home/mtuszowski/conjurer/pamiec_muzyki.json"
MUSIC_FOLDER = "/mnt/g/Muzyka/" MUSIC_FOLDER = "/mnt/g/Muzyka/"
SETTINGS_FILE = "/home/mtuszowski/conjurer/settings.json" SETTINGS_FILE = "/home/mtuszowski/conjurer/settings.json"
@@ -94,7 +93,6 @@ if platform in ("linux", "linux2"):
else: else:
LOGFILE = "/home/pi/Conjurer/discord.log" LOGFILE = "/home/pi/Conjurer/discord.log"
MEMORY_FIVE_SIARA = "/home/pi/Conjurer/pamiec.json" 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" MEMORY_FIVE_MUZYKA = "/home/pi/Conjurer/pamiec_muzyki.json"
MUSIC_FOLDER = "/home/pi/RetroPie/mp3/" MUSIC_FOLDER = "/home/pi/RetroPie/mp3/"
SETTINGS_FILE = "/home/pi/Conjurer/settings.json" SETTINGS_FILE = "/home/pi/Conjurer/settings.json"
@@ -109,7 +107,6 @@ if platform in ("linux", "linux2"):
elif platform == "win32": elif platform == "win32":
LOGFILE = "discord.log" LOGFILE = "discord.log"
MEMORY_FIVE_SIARA = "pamiec.json" MEMORY_FIVE_SIARA = "pamiec.json"
SYSTEM_GPT_SETTINGS = "system_gpt_settings.json"
MEMORY_FIVE_MUZYKA = "pamiec_muzyki.json" MEMORY_FIVE_MUZYKA = "pamiec_muzyki.json"
MUSIC_FOLDER = "G:\\Muzyka\\" MUSIC_FOLDER = "G:\\Muzyka\\"
SETTINGS_FILE = "settings.json" SETTINGS_FILE = "settings.json"
@@ -170,10 +167,6 @@ for mp3_item in Path.glob(Path(MUSIC_FOLDER), "**/*.mp3"):
if platform == "win32": if platform == "win32":
temp_music_file = temp_music_file.replace("/", "\\") temp_music_file = temp_music_file.replace("/", "\\")
music_file_list.append(temp_music_file) 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: with open(MEMORY_FIVE_SIARA, "r+", encoding=ENCODING) as temp_memory_file:
# First we load existing data into a dict. # First we load existing data into a dict.
MESSAGE_TABLE = json.load(temp_memory_file) MESSAGE_TABLE = json.load(temp_memory_file)
@@ -183,7 +176,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: with open(SETTINGS_FILE, "r", encoding=ENCODING) as f_settings_file:
data = json.load(f_settings_file) data = json.load(f_settings_file)
word_reactions = data["word_reactions"] word_reactions = data["word_reactions"]
cyclic_words = data["cyclic_words"]
historia_fabryczki = data["fabryczka"] historia_fabryczki = data["fabryczka"]
for key in word_reactions: for key in word_reactions:
word_reactions[key][2] = datetime.now() word_reactions[key][2] = datetime.now()
@@ -278,12 +270,8 @@ async def on_message(message):
word_reactions[word][2] = datetime.now() word_reactions[word][2] = datetime.now()
# TODO: drobne literówki, mentiony, spacja przed dwukropkiem. napraw. # 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(): async with channel.typing():
logger.debug("Procedura chatu") logger.debug("Procedura chatu")
@@ -335,29 +323,6 @@ async def on_message(message):
# *=========================================== Define Functions # *=========================================== 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): async def connect(ctx, arg=None):
""" """
@@ -488,18 +453,24 @@ async def play(ctx, zamawial=None, arg=None):
await ctx.send(result) await ctx.send(result)
async def archive_channel(channel_no):
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(): async def check():
"""Funkcja sprawdzająca czy grać następny kawałek.""" """Funkcja sprawdzająca czy grać następny kawałek."""
last_spontaneous_call = datetime.now()
while True: while True:
tdelta = datetime.now() - last_spontaneous_call # TODO: Tu dołożyć skanowanie rozmiaru pliku logowania oraz plików pamięci i przenoszenie ich na większy dysk.
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)
# trunk-ignore(codespell/misspelled) # trunk-ignore(codespell/misspelled)
# TODO: dlaczego sie tu wypierdala # TODO: dlaczego sie tu wypierdala
if client.voice_clients: if client.voice_clients:
@@ -567,19 +538,7 @@ async def check():
await asyncio.sleep(60) 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/R0913)
# trunk-ignore(pylint/R0915)
async def handle_response(prompt, vykidailo, bartender, history, username, music): async def handle_response(prompt, vykidailo, bartender, history, username, music):
""" """
Handle responses by appending them to a history, use OpenAI to Handle responses by appending them to a history, use OpenAI to
@@ -622,49 +581,22 @@ async def handle_response(prompt, vykidailo, bartender, history, username, music
# convert back to json. # convert back to json.
json.dump(file_data, file_memory, indent=4) json.dump(file_data, file_memory, indent=4)
history = [] history = []
history.append(GPT_SETTINGS[0]) # * append bo pierwszy index
chat_gpt_config_request_size = num_tokens_from_string(GPT_SETTINGS[0], "gpt-4") # * extend bo 20 ostatnich
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)
if music: if music:
algorithm = "gpt-3.5-turbo-16k" history.append(message_table_muzyka[0])
table = message_table_muzyka history.extend(message_table_muzyka[-15:])
token_amount = 10700
else: else:
table = MESSAGE_TABLE history.append(MESSAGE_TABLE[0])
algorithm = "gpt-4" history.extend(MESSAGE_TABLE[-15:])
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
)
logger.info("Historia wysłana:") logger.info("Historia wysłana:")
logger.info(history) logger.debug(history)
await asyncio.sleep(15) response = await openai.ChatCompletion.acreate(
model="gpt-4", messages=history
)
await asyncio.sleep(10)
result = "" result = ""
logger.debug("Odpowiedzi") logger.debug("Odpowiedzi")
logger.info(response)
logger.debug(response.choices) logger.debug(response.choices)
for choice in response.choices: for choice in response.choices:
result += choice.message.content result += choice.message.content
@@ -731,7 +663,7 @@ async def get_file(ctx, source, link):
url_dict["songs"] = file_list url_dict["songs"] = file_list
url_data["urls"].append(url_dict.copy()) url_data["urls"].append(url_dict.copy())
file_name_f = youtube_download.default_filename file_name_f = youtube_download.default_filename
youtube_download.download_songs( coro = asyncio.to_thread(youtube_download.download_songs,
songs=url_data, songs=url_data,
output_dir=MUSIC_FOLDER, output_dir=MUSIC_FOLDER,
format_str="bestaudio/best", format_str="bestaudio/best",
@@ -744,6 +676,7 @@ async def get_file(ctx, source, link):
multi_core=0, multi_core=0,
proxy="", proxy="",
) )
_ = await coro
dir_path = (url_dict["save_path"].resolve()).as_posix() dir_path = (url_dict["save_path"].resolve()).as_posix()
if platform == "win32": if platform == "win32":
dir_path = dir_path.replace("/", "\\") dir_path = dir_path.replace("/", "\\")
@@ -774,6 +707,8 @@ async def get_file(ctx, source, link):
"force_keyframes": True, "force_keyframes": True,
}, },
] ]
#TODO: Make sponsorblock work
sponsorblock_postprocessor = []
if platform == "win32": if platform == "win32":
dir_path = "G:\\Muzyka\\Youtube" dir_path = "G:\\Muzyka\\Youtube"
else: else:
@@ -782,7 +717,6 @@ async def get_file(ctx, source, link):
"proxy": "", "proxy": "",
"default_search": "ytsearch", "default_search": "ytsearch",
"format": "bestaudio/best", "format": "bestaudio/best",
"postprocessors": sponsorblock_postprocessor,
"noplaylist": True, "noplaylist": True,
"no_color": False, "no_color": False,
"paths": {"home": dir_path}, "paths": {"home": dir_path},
@@ -795,7 +729,8 @@ async def get_file(ctx, source, link):
ydl_opts["postprocessors"].append(mp3_postprocess_opts.copy()) ydl_opts["postprocessors"].append(mp3_postprocess_opts.copy())
with yt_dlp.YoutubeDL(ydl_opts) as ydl: with yt_dlp.YoutubeDL(ydl_opts) as ydl:
try: try:
ydl.download([query]) coro = asyncio.to_thread(ydl.download, [query])
_ = await coro
except Exception as exce: # pylint: disable=broad-exception-caught except Exception as exce: # pylint: disable=broad-exception-caught
logger.error(exce) logger.error(exce)
logger.info( logger.info(
@@ -815,7 +750,40 @@ async def get_file(ctx, source, link):
) )
logger.error("Wrong link provided youtube: %s", link) logger.error("Wrong link provided youtube: %s", link)
return "", None return "", None
elif source == "Pornol":
dir_path = ""
file_list = []
query = link
sponsorblock_postprocessor = [
{
"key": "SponsorBlock",
"categories": ["skip_non_music_sections"],
},
{
"key": "ModifyChapters",
"remove_sponsor_segments": ["music_offtopic"],
"force_keyframes": True,
},
]
# TODO: Make sponsorblock work
sponsorblock_postprocessor = []
dir_path = "/home/pi/RetroPie/movies/porn"
ydl_opts = {
"postprocessors": sponsorblock_postprocessor,
"paths": {"home": dir_path},
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
try:
coro = asyncio.to_thread(ydl.download, [query])
_ = await coro
except Exception as exce: # pylint: disable=broad-exception-caught
logger.error(exce)
logger.info(
"Failed to download %s, make sure yt_dlp is up to date", link
)
file_list.append("wiadomo co wiadomo gdzie")
return dir_path, file_list
# define an asynchronous generator # define an asynchronous generator
async def async_iterator_generator(range_of_iterable): async def async_iterator_generator(range_of_iterable):
@@ -892,7 +860,7 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
It is an optional parameter with a default value of 0, which means that if no value is provided for It is an optional parameter with a default value of 0, which means that if no value is provided for
how_many, the function will return all search results, defaults to 0 (optional) how_many, the function will return all search results, defaults to 0 (optional)
""" """
# TODO: Potem dorobić wyszukiwania po kawałkach słów #TODO: Przerobić na webservice
# i sieć neuronową z możliwością wyrażenia opinii o dopasowaniu. # i sieć neuronową z możliwością wyrażenia opinii o dopasowaniu.
if slowa_kluczowe: if slowa_kluczowe:
word_list = slowa_kluczowe word_list = slowa_kluczowe
@@ -940,7 +908,7 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
all_words = [] all_words = []
async for f_iter in async_iterator_generator(file): async for f_iter in async_iterator_generator(file):
async for char in async_iterator_generator(char_remove): async for char in async_iterator_generator(char_remove):
f_iter = await remove_characters(f_iter, char) f_iter = f_iter.replace(char, "")
tmp = f_iter.split() tmp = f_iter.split()
all_words.extend(tmp) all_words.extend(tmp)
pingu = 1 pingu = 1
@@ -986,18 +954,6 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
return return_list 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): async def max_weight(lista):
""" """
Take a list of weights and return the maximum weight. Take a list of weights and return the maximum weight.
@@ -1455,7 +1411,7 @@ async def zrob_mi_plejliste(ctx):
if metadata.tag.title: if metadata.tag.title:
reply += " z prywatnej kolekcji Hammera i na Twoją specjalną rpośbę.\n" reply += " z prywatnej kolekcji Hammera i na Twoją specjalną rpośbę.\n"
else: else:
reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera.\n" reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera."
index += 1 index += 1
if len(reply) > 1800: if len(reply) > 1800:
@@ -1632,7 +1588,6 @@ async def get_image_stable_diffusion(ctx):
guild=discord.Object(id=664789470779932693), guild=discord.Object(id=664789470779932693),
) )
# trunk-ignore(pylint/R0912) # trunk-ignore(pylint/R0912)
# trunk-ignore(pylint/R0915)
async def zagraj_muzyke_mego_ludu(ctx): async def zagraj_muzyke_mego_ludu(ctx):
""" """
Play completeley random playlist based on messaging history. Play completeley random playlist based on messaging history.
@@ -1644,31 +1599,22 @@ async def zagraj_muzyke_mego_ludu(ctx):
""" """
stats = {} stats = {}
if ctx: if ctx:
logger.info("Zagraj muzyke mego ludu: wywolane")
stat_iter = get_stats(ctx, MUZYKA_MOJEGO_LUDU_HISTORIA) stat_iter = get_stats(ctx, MUZYKA_MOJEGO_LUDU_HISTORIA)
async for name, how_many in stat_iter: async for name, how_many in stat_iter:
if len(name) > 3: if len(name) > 3:
stats[name] = how_many stats[name] = how_many
sorted_stats = sorted(stats.items(), key=lambda x: x[1]) sorted_stats = sorted(stats.items(), key=lambda x: x[1])
logger.info("Zagraj muzyke mego ludu:zebrano statystyki")
key_words = [] key_words = []
for stat in sorted_stats: for stat in sorted_stats:
key_words.append(stat[0]) key_words.append(stat[0])
logger.info(sorted_stats[:MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE]) logger.info(sorted_stats[:30])
logger.info(key_words[:MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE]) logger.info(key_words[:30])
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" reply = "Wygenerowana plejlista:\n"
async with ctx.typing(): async with ctx.typing():
logger.info("Zaczynam szukać timestamp %s", datetime.now()) logger.info("Zaczynam szukać timestamp %s", datetime.now())
search_time_glob = 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=key_words[:MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE])
logger.info("Zagraj muzyke mego ludu:wygenerowano plejliste")
logger.info(file)
logger.info( logger.info(
"Koniec szukania(timestamp %s zajęło %s", "Koniec szukania(timestamp %s zajęło %s",
datetime.now(), datetime.now(),
@@ -1694,7 +1640,7 @@ async def zagraj_muzyke_mego_ludu(ctx):
if metadata.tag.title: if metadata.tag.title:
reply += " z prywatnej kolekcji Hammera i na Twoją specjalną rpośbę.\n" reply += " z prywatnej kolekcji Hammera i na Twoją specjalną rpośbę.\n"
else: else:
reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera.\n" reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera."
index += 1 index += 1
if len(reply) > 1800: if len(reply) > 1800:
@@ -1714,7 +1660,7 @@ async def zagraj_muzyke_mego_ludu(ctx):
description="Konfiguruje komende zagraj muzyke mojego ludu", description="Konfiguruje komende zagraj muzyke mojego ludu",
guild=discord.Object(id=664789470779932693), 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=30, jak_dluga_plejlista=30):
""" """
The function `parametry_muzyki_mego_ludu` sets global variables for the number of history entries, 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. number of keywords, and length of playlist for a music application.
@@ -1732,27 +1678,46 @@ async def parametry_muzyki_mego_ludu(ctx, ile_historii=1500, ile_slow_kluczowych
""" """
if ctx: 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_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_HISTORIA = ile_historii
global MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE # pylint: disable=global-statement
MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE = ile_slow_kluczowych MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE = ile_slow_kluczowych
global MUZYKA_MOJEGO_LUDU_PLAJLISTA # pylint: disable=global-statement
MUZYKA_MOJEGO_LUDU_PLAJLISTA = jak_dluga_plejlista 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}") @client.hybrid_command(
except discord.ext.commands.errors.BadArgument as exce: name="krecimy_pornola",
ctx.send("Spierdalaj") description="Wiadomo co, dla kogo i po co",
logger.info(exce) guild=discord.Object(id=664789470779932693),
)
async def krecimy_pornola(ctx):
"""
Download a music number from youtube.
:param ctx: ctx stands for "context" and is a parameter commonly used in Discord.py commands. It
represents the context in which the command was invoked, including information such as the message,
the channel, the server, and the user who invoked the command. It allows the command to interact
with the Discord API and
"""
await ctx.send("Dej mnie chwilkę")
allowed = False
for role in ctx.author.roles:
if role.name == "Bartender":
allowed = True
if allowed:
logger.info("Pornol")
async with ctx.typing():
# wyciagnij linka z kontekstu
content = ctx.message.content.split()
for item_yt in content:
if re.match("http.*", item_yt):
sciezka, files = await get_file(ctx, "Pornol", item_yt)
if files:
logger.info("Pornol udany")
ctx.reply(f"Jest w tajnym archiwum pod adresem{sciezka})")
else:
ctx.reply("Jak ładnie szefa poprosisz.")
# *================================== Run # *================================== Run
+1707
View File
File diff suppressed because it is too large Load Diff
+11
View File
@@ -0,0 +1,11 @@
[Unit]
Description=Conjurer
After=multi-user.target
[Service]
Type=simple
ExecStart=/home/pi/Conjurer/env/bin/python3 /home/pi/Conjurer/bot.py
Restart=on-abort
[Install]
WantedBy=multi-user.target
+190
View File
@@ -0,0 +1,190 @@
import re
import logging
import threading
import time
from flask import Flask, jsonify, request
import netrc
import json
from json.decoder import JSONDecodeError
from platform import uname
from sys import platform
from urllib.request import urlopen
from habanero import Crossref
from waitress import serve
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"
#HOST_ADDRESS = "192.168.1.191"
HOST_ADDRESS = "0.0.0.0"
PORT_ADDRESS = 5001
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.limit = 1000
self.fetched = 0
self.hit = 0
self.total = 0
def search_crossref(self, query, uuid):
search_result_from_cr = self.cr.works(query = query, limit = self.limit)
self.total = search_result_from_cr['message']['total-results']
self.fetched = len(search_result_from_cr['message']['items'])
#add to sql with UUID
#sql row - title, doi, author, uuid, last retrieved, is_available
with open("results.json", "r+", encoding="UTF-8") as data_file:
# First we load existing data into a dict.
try:
file_data = json.load(data_file)
except JSONDecodeError:
file_data = []
# Join new_data with file_data inside emp_details
summarized_results = []
for item in search_result_from_cr['message']['items']:
container = "NO"
if "container-title" in item:
container = "YES"
summarized_results.append({"DOI" : item['DOI'], "title": item['title'] if 'title' in item else None,"type": item['type'] if 'type' in item else None, "container": container})
result = {"UUID": uuid, "total_results": search_result_from_cr['message']['total-results'], "on_page" : 1, "summary":summarized_results, "results":search_result_from_cr['message']['items'], }
file_data.append(result)
print("Saving")
data_file.seek(0)
# convert back to json.
json.dump(file_data, data_file, indent=4)
return result
def check_if_exists(self,page_url):
#TODO: Spowolnic
#TODO: Sprawdzac po mirrorach
#TODO: sprawdzac w tym jebanym pliku
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:
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
def refine_query(self, unrefined_reqult):
print("Refine result")
refined_result = []
for item in unrefined_reqult["summary"]:
if item["container"] == "NO" and item["title"]:
item_link = "https://sci-hub.se/" + str(item['DOI'])
if self.check_if_exists(item_link):
refined_result.append(item)
print ("HIT")
print(item["title"])
time.sleep(0.01)
print("Existing hits")
self.hit = len(refined_result)
return refined_result
def answer_query(self, query, uuid):
#Search sql for UUID
#SQL SELECT * FROM RESULTS WHERE UUID = uuid
print("Answer result")
uuid_found = False
database = None
with open("results.json", "r", encoding="UTF-8") as new_file:
#tu logika komunikacji z SQL i cała logika związana z wyszukaniem
#ale tymczasowo plik
try:
database = json.load(new_file)
except JSONDecodeError:
pass
if database:
for item in database:
if item["UUID"] == uuid:
print (item["UUID"])
uuid_found = True
return self.refine_query(item)
if not uuid_found:
answer = self.search_crossref(query=query, uuid=uuid)
return self.refine_query(answer)
#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")
app = Flask(__name__)
def flask_debug():
"""
The `flask_debug` function starts a Flask application in debug mode without using the reloader.
Do not use for production for fucks sake.
"""
# trunk-ignore(bandit/B201)
app.run(debug=True, use_reloader=False, host=HOST_ADDRESS, port=PORT_ADDRESS)
def waitress_run():
"""
The `waitress_run` function serves the `app` on host "0.0.0.0"
and port 5000 using the Waitress WSGI server.
"""
serve(app, host=HOST_ADDRESS, port=PORT_ADDRESS)
@app.route("/query", methods=["POST"])
def query_database():
record = json.loads(request.data)
app.logger.info(record)
app.logger.info(record["query"])
app.logger.info(record["UUID"])
cl = Librarian()
answer_data = cl.answer_query(record["query"], record["UUID"])
app.logger.info(answer_data)
summary = (cl.hit,cl.fetched, cl.total, record["UUID"])
answer_data = (summary,answer_data)
return_data = (
jsonify(isError=False, message="Success", statusCode=200, data=answer_data),
200,
)
return return_data
if __name__ == "__main__":
logger = logging.getLogger('conjurer_musician')
logger.setLevel(logging.DEBUG)
threads = []
#threads.append(threading.Thread(target=waitress_run))
threads.append(threading.Thread(target=flask_debug))
for worker in threads:
worker.start()
for worker in threads:
worker.join()
#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
@@ -0,0 +1,11 @@
#!/bin/bash
python3 -m venv /home/pi/Conjurer_librarian/env
cp /home/pi/conjurer/conjurer_librarian/conjurer_librarian.py ./Conjurer_librarian/
cp /home/pi/conjurer/conjurer_librarian/requirements_librarian.txt ./Conjurer_librarian/
cd /home/pi/Conjurer_librarian
source /home/pi/Conjurer_librarian/env/bin/activate
./env/bin/python3 -m pip install --upgrade pip
./env/bin/python3 -m pip install -r requirements_librarian.txt
deactivate
cp /home/pi/conjurer/conjurer_librarian/conjurer_librarian.py ./Conjurer_librarian/
@@ -0,0 +1,3 @@
habanero
waitress
flask
Executable
+9
View File
@@ -0,0 +1,9 @@
#!/bin/bash
git pull
cd ..
cp ./conjurer/bot.py ./Conjurer/
cp ./conjurer/settings.json ./Conjurer/
cp ./conjurer/system_gpt_settings.json ./Conjurer/
cp ./conjurer/install.sh ./Conjurer/
cp ./conjurer/requirements.txt ./Conjurer/requirements.txt
sudo systemctl restart conjurer.service
+134
View File
@@ -0,0 +1,134 @@
"""
The provided Python script sets up a Flask web server to manage a list of music files, with
functions for rescanning the music folder, updating the music list, and serving the music list via
API endpoints.
"""
import json
from pathlib import Path
from platform import uname
import threading
import time
from sys import platform
import logging
from flask import Flask, jsonify, request
from waitress import serve
HOST_ADDRESS = "192.168.1.15"
PORT_ADDRESS = 5000
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 = []
def rescan():
"""
The `rescan` function logs a message, scans for mp3 files in a specified folder,
and adds them to a list of music files.
"""
logging.info("Rescan triggered")
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)
def thread_rescan():
"""
The `thread_rescan` function periodically triggers a rescan operation after a specified time
interval.
"""
logging.info("Starting filesystemupdater")
while True:
time.sleep(60*60*24)
logging.info("Rescan triggered")
rescan()
app = Flask(__name__)
@app.route("/mp3", methods=["GET"])
def get_music_list():
"""
The function `get_music_list` returns a JSON object containing a list of music files.
:return: A JSON response containing a key "music_file_list" with the value of the variable
`music_file_list`.
"""
return jsonify({"music_file_list": music_file_list})
@app.route("/update_mp3", methods=["POST"])
def update_music_list():
"""
The function `update_music_list` receives a POST request with a JSON payload, logs the received
item, adds it to a music file list, and returns a success message along with the updated record.
:return: The function `update_music_list` is returning a tuple containing a JSON response and a
status code. The JSON response includes keys `isError`, `message`, `statusCode`, and `data`,
with values indicating the success of the operation and the data that was
received and added to the `music_file_list`.
The status code returned is 200, indicating a successful response.
"""
record = json.loads(request.data)
app.logger.info(record["item"])
music_file_list.append(record["item"])
return_data = (
jsonify(isError=False, message="Success", statusCode=200, data=record),
200,
)
return return_data
def flask_debug():
"""
The `flask_debug` function starts a Flask application in debug mode without using the reloader.
Do not use for production for fucks sake.
"""
# trunk-ignore(bandit/B201)
app.run(debug=True, use_reloader=False, host=HOST_ADDRESS, port=PORT_ADDRESS)
def waitress_run():
"""
The `waitress_run` function serves the `app` on host "0.0.0.0"
and port 5000 using the Waitress WSGI server.
"""
serve(app, host=HOST_ADDRESS, port=PORT_ADDRESS)
def waitress_run():
serve(app, host="0.0.0.0", port=5000)
if __name__ == "__main__":
logger = logging.getLogger('conjurer_musician')
logger.setLevel(logging.DEBUG)
rescan()
threads = []
threads.append(threading.Thread(target=waitress_run))
threads.append(threading.Thread(target=thread_rescan))
#threads.append(threading.Thread(target=flask_debug))
for worker in threads:
worker.start()
for worker in threads:
worker.join()
#TODO: wrzucić wyszukanie i robienie playlist
#TODO: Inne pliki - sadox, dokumenty naukowe itp.
+11
View File
@@ -0,0 +1,11 @@
[Unit]
Description=Conjurer_musician
After=multi-user.target
[Service]
Type=simple
ExecStart=/home/pi/Conjurer-service/conjurer/file_webservice/bin/python3 /home/pi/Conjurer-service/conjurer/file_webservice/conjurer_musician.py
Restart=on-abort
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,11 @@
#!/bin/bash
python3 -m venv /home/pi/Conjurer-service/conjurer/file_webservice
source ./bin/activate
./bin/python3 -m pip install --upgrade pip
./bin/python3 -m pip install -r requirements_musician.txt
deactivate
sudo cp ./conjurer_musician.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl start conjurer_musician.service
sudo systemctl enable conjurer_musician.service
@@ -0,0 +1,2 @@
flask
waitress
+12
View File
@@ -0,0 +1,12 @@
#!/bin/bash
python3 -m venv /home/pi/Conjurer/env
source ./env/bin/activate
./env/bin/python3 -m pip install --upgrade pip
./env/bin/python3 -m pip install -r requirements_bot.txt
sed -i -e 's/os.rename/shutil.copy/g' ./env/lib/python3.11/site-packages/spotify_dl/youtube.py
sed -i '1i\import shutil' ./env/lib/python3.11/site-packages/spotify_dl/youtube.py
deactivate
sudo cp ./conjurer.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl start conjurer_musician.service
sudo systemctl enable conjurer_musician.service
+13
View File
@@ -0,0 +1,13 @@
discord
yt_dlp
spotify_dl
spotipy
openai
eyed3
numpy
pdf2image
PyPDF2
requests
spotipy
tiktoken
PyNaCl
+2742
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -211,7 +211,7 @@
false, false,
false false
], ],
"burdel": [ "burdel\\b": [
"Oooo... Hammer nadal nie zmienił firanek - ale całkiem nieźle sprząta, jebaniutki.", "Oooo... Hammer nadal nie zmienił firanek - ale całkiem nieźle sprząta, jebaniutki.",
15.0, 15.0,
0, 0,
+2 -2
View File
@@ -97,8 +97,8 @@ def write_tracks(tracks_file, song_dict):
def set_tags(temp, filename, kwargs): def set_tags(temp, filename, kwargs):
""" """
sets song tags after they are downloaded sets song tags after they are downloaded
:param temp: contains index used to obtain more info about song being editted :param temp: contains index used to obtain more info about song being edited
:param filename: location of song whose tags are to be editted :param filename: location of song whose tags are to be edited
:param kwargs: a dictionary of extra arguments to be used in tag editing :param kwargs: a dictionary of extra arguments to be used in tag editing
""" """
song = kwargs["track_db"][int(temp[-1])] song = kwargs["track_db"][int(temp[-1])]
+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)
+73
View File
@@ -0,0 +1,73 @@
# trunk-ignore-all(pylint/C0301)
"""
The function `cut_my_life_into_pieces` reads a source file, splits its content based on a file size
limit, and writes the parts to separate output files in a specified folder.
: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. It represents the actual content that will be written to
the file
:param file: The code you provided defines two functions: `smart_write` and
`cut_my_life_into_pieces`. The `smart_write` function encodes input lines to UTF-8, writes them to a
file, and returns the size of the encoded bytes. The `cut_my_life_into_pieces` function reads
:return: The functions provided in the code snippet do not explicitly return any values. However,
the `smart_write` function returns the size of the encoded bytes of the input `lines` in bytes. The
`cut_my_life_into_pieces` function does not have a return statement, so it does not explicitly
return any value.
"""
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)