Compare commits

...

7 Commits

Author SHA1 Message Date
gitea a68745713b Change in weights 2024-07-20 13:27:40 +02:00
gitea bbe1b89007 Fix logging0 2024-07-20 11:13:36 +02:00
gitea 27fefdccb5 Added more logging 2024-07-20 09:55:32 +02:00
gitea 64849f728f Fixed :) 2024-07-20 09:50:24 +02:00
gitea 9b09c2c13f Fix 2024-07-20 09:41:42 +02:00
gitea f2fb2232ee Audition 2024-07-20 09:09:14 +02:00
gitea 7e4dfbf8cd NEw util 2024-07-20 09:00:51 +02:00
5 changed files with 99 additions and 19 deletions
+52 -12
View File
@@ -143,6 +143,8 @@ GET_MP3 = "/mp3"
SEND_MP3 = "/update_mp3"
GET_PLAYLIST = "/get_music"
ADD_TO_PRIO_PLAYLIST = "/add_to_priority"
CREATE_PRIO_PLAYLIST = "/create_priority_playlist"
REQUEST_MUSIC = "/request_radio_file"
CLEAR_PRIO = "/clear_pr_pls"
LIBRARIAN_SERVICE_ADDRESS = "http://192.168.1.192:5001"
@@ -1368,7 +1370,9 @@ async def skip_track(ctx):
f"{RADIO_HARBOR_ADDRESS}{SKIP_TRACK}",
timeout=360,
)
_ = await coroutine
result = await coroutine
logger.info("Done %s", result)
await ctx.send("Zrobione szefie!")
@client.hybrid_command(
@@ -1837,7 +1841,9 @@ async def dodaj_do_ulubionych(ctx):
json=jrequest,
timeout=360,
)
_ = await coroutine
result = await coroutine
logger.info("Done %s", result)
await ctx.send("Zrobione szefie!")
@client.hybrid_command(
name="ja_chciol",
description="Dodaje do listy ulubionych w radiu",
@@ -1867,7 +1873,46 @@ async def request_radio(ctx):
json=jrequest,
timeout=360,
)
_ = await coroutine
result = await coroutine
logger.info("Done %s", result)
await ctx.send("Zrobione szefie!")
@client.hybrid_command(
name="stworz_audycje",
description="Dodaje do listy ulubionych w radiu",
guild=discord.Object(id=664789470779932693),
)
async def stworz_audycje(ctx):
"""
Generate a playlist in queue. First word in this command shall be int defining length of the playlist.
Rest of the line are search terms.
: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. This parameter is required in all
Discord.py commands
"""
async with ctx.typing():
logger.info("Zaczynam szukać timestamp %s", datetime.now())
dlugosc_playlisty = ctx.message.content.split()[1]
word_list = ctx.message.content.split()
jrequest = {
"lista_slow": word_list,
"dlugosc_plejlisty": dlugosc_playlisty,
"UUID": str(uuid.uuid4()),
}
coroutine = asyncio.to_thread(
requests.post,
f"{FILE_SERVICE_ADDRESS}{CREATE_PRIO_PLAYLIST}",
json=jrequest,
timeout=360,
)
result = await coroutine
logger.info("Done %s", result)
await ctx.send("Zrobione szefie!")
@client.hybrid_command(
name="wyczysc_ulubione",
description="Czysci liste ulubionych w radiu",
@@ -1889,7 +1934,9 @@ async def wyczysc_ulubione(ctx):
f"{FILE_SERVICE_ADDRESS}{CLEAR_PRIO}",
timeout=360,
)
_ = await coroutine
result = await coroutine
logger.info("Done %s", result)
await ctx.send("Zrobione szefie!")
@client.hybrid_command(
@@ -2416,7 +2463,7 @@ async def krecimy_pornola(ctx):
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})")
ctx.send(f"Jest w tajnym archiwum pod adresem{sciezka})")
else:
ctx.reply("Jak ładnie szefa poprosisz.")
@@ -2441,10 +2488,3 @@ if __name__ == "__main__":
WRK_CNT+=1
logger.info("Starting discord bot: Joining thread %s", WRK_CNT)
worker.join()
# widok - generuje się 5 stron po 4 linki
# odśwież - zamienić na "dalej" - zaciąga kolejne 20 rezultatów
# po wyslaniu czekamy na odbior i dodajemy UUID oraz nick poszukiwacza do queue ktora jest sprawdzana
# flask sobie chodzi i jak dostaje posta z wynikami to wyciaga z queue UUID i odpowiada że znalazła
# po samym wyszukaniu dajemy info że "Zaczynam szukać ale pare godzin to potrwa."
# OPCJONALNIE: Dosyłamy znalezione wyniki na bieżąco - wtedy wkładamy do queue dla UUID wyniki
+8
View File
@@ -0,0 +1,8 @@
FILEPTH = r"C:\Database\chunks\4_chunk.txt"
with open(FILEPTH, "r", encoding="utf-8") as file:
tab = file.readlines()
print(len(tab))
#1842295
+1
View File
@@ -23,6 +23,7 @@ from queue import Empty, Queue
from threading import Thread
import time
q = Queue()
#TODO: Count number of lines in files and print to approximate on which part of the file search is
# DATA FOR TEST ONLY
# MAXTHREADS = 5
+32
View File
@@ -206,6 +206,7 @@ def wyszukaj(word_list, how_many, _logger=None, return_to_bot=True):
fun_logger.info("Wiele plików do zagrania")
search_weight.sort(key=lambda x: x[0], reverse=True)
return_list.extend(search_weight[: int(how_many)])
fun_logger.info("Done: %s", return_list)
return return_list
@@ -369,6 +370,37 @@ def add_request():
)
return return_data
@app.route("/create_priority_playlist", methods=["POST"])
def create_priority_playlist():
"""
The function `create_priority_playlist` 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: 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)
app.logger.info(record["lista_slow"])
app.logger.info(record["UUID"])
app.logger.info(record["dlugosc_plejlisty"])
return_data = wyszukaj(
record["lista_slow"], record["dlugosc_plejlisty"], app.logger, False
)
with open(
"/home/pi/Conjurer/request.playlist", "a", encoding="utf-8"
) as s_file:
for item in return_data:
s_file.write(item[1] + "\n")
return_data = (
jsonify(isError=False, message="Success", statusCode=200, data={"status": "OK"}),
200,
)
return return_data
@app.route("/add_to_priority", methods=["POST"])
+6 -7
View File
@@ -34,10 +34,9 @@ requests_queue = request.queue()
# Function to process the request queue and add new requests
def queue_processing()
f1=file.read("/home/pi/Conjurer/request.playlist")
text = f1()
if text != "" then
requests_queue.push.uri(text)
text=file.lines("/home/pi/Conjurer/request.playlist")
if text != [] then
list.iter(fun(item) -> requests_queue.push.uri(item), text)
file.remove("/home/pi/Conjurer/request.playlist")
f = file.open("/home/pi/Conjurer/request.playlist", create=true)
f.close()
@@ -45,7 +44,7 @@ def queue_processing()
end
# Randomly select a playlist with weights
s4 = random(id="randomizer", weights=[1, 3, 5], [s1, s2, s3])
s4 = random(id="randomizer", weights=[2, 3, 5], [s1, s2, s3])
# Load jingles playlist
jingles = (playlist(reload_mode="watch", "/home/pi/Conjurer/jingles.playlist"))
@@ -74,7 +73,7 @@ s = amplify(a, s)
mic = buffer(input.pulseaudio()) # Microphone
mic = gate(threshold=-30., range=-80., mic)
mic = blank.strip(max_blank=2., min_noise=.1, threshold=-20., mic)
mic = blank.strip(max_blank=10., min_noise=.1, threshold=-20., mic)
s = add([s, mic])
#w = interactive.float("wetness", min=0., max=1., 1.)
@@ -82,7 +81,7 @@ s = add([s, mic])
# Skip blank sections in the stream
s = blank.skip(max_blank=2., s)
s = blank.skip(max_blank=10., s)
# Configure logging settings
log_to_stdout = true