From ab37cc2e5a9845c039a5bef23930f359cdfbdd42 Mon Sep 17 00:00:00 2001 From: phixxy Date: Sun, 9 Jul 2023 13:07:09 -0700 Subject: [PATCH] made website command asynchronous, removed website archive ability for now. --- sparkytron3000.py | 205 ++++++++++------------------------------------ 1 file changed, 43 insertions(+), 162 deletions(-) diff --git a/sparkytron3000.py b/sparkytron3000.py index 04a8df6..f4482af 100644 --- a/sparkytron3000.py +++ b/sparkytron3000.py @@ -21,6 +21,7 @@ from ftplib import FTP import threading import matplotlib.pyplot as plt import aiohttp +import aioftp #config STABLE_DIFFUSION_URL = "http://127.0.0.1:7861" @@ -728,24 +729,6 @@ async def question_gpt4(ctx): for chunk in chunks: await ctx.send(chunk) - -@bot.command() -async def save_website(ctx): - try: - folder_name = ctx.message.content.split(" ", maxsplit=1)[1] - try: - os.makedirs("websites/" + folder_name) - except FileExistsError: - await ctx.send(folder_name + " already exists. Choose a new name.") - return 0 - for filename in os.listdir("webpage/"): - if ".png" in filename or ".html" in filename: - shutil.copyfile("webpage/" + filename, "websites/"+folder_name+"/"+filename) - await ctx.send("Website Archived!") - except Exception as error: - print(error) - await ctx.send("Usage !save_website (filename)") - @bot.command() async def highscores(ctx, limit=0): filename = str(ctx.channel.id) + ".log" @@ -881,15 +864,16 @@ async def website(ctx): os.remove(local_folder + filename) async def delete_ftp_pngs(server_folder): - with FTP(ftp_server) as ftp: - ftp.login(ftp_username, ftp_password) - ftp.cwd(server_folder) - file_list = ftp.nlst() - for filename in file_list: - if ".png" in filename: - print("Deleting", filename) - ftp.delete(filename) - + client = aioftp.Client() + await client.connect(ftp_server) + await client.login(ftp_username, ftp_password) + await client.change_directory(server_folder) + for path, info in (await client.list()): + if ".png" in path.name: + print("Deleting", path.name) + await client.remove(path.name) + await client.quit() + async def extract_image_tags(code): count = code.count(" - - - - webpage-archive - - - - -

webpage-archive

-

This is a list of saved websites that AI generated.

- - - -''' - with FTP(ftp_server) as ftp: - ftp.login(ftp_username, ftp_password) - ftp.cwd(server_archive_folder) - file_list = ftp.nlst() - dir_list = "" - for folder in file_list: - if folder != "index.html": - dir_list += "
  • " + folder + "
  • \n" - html = html1 + dir_list + html2 - with open("index.html","w") as f: - f.write(html) - f.close() - ftp.storbinary("STOR " + "index.html", open("index.html", "rb")) - - server_folder = os.getenv('ftp_ai_webpage') server_archive_folder = "/media/sdq1/bottlecap/www/phixxy.com/public_html/webpage-archive/" @@ -1080,11 +965,7 @@ async def website(ctx): f.write(code) f.close() - await upload_html_and_imgs(local_folder, server_folder) - await upload_archived_website(server_archive_folder, local_archive_folder) - await generate_website_archive_html(server_archive_folder) - - + await upload_html_and_imgs(local_folder, server_folder) await ctx.send("Finished https://phixxy.com/ai-webpage/") except openai.error.APIConnectionError as error: