diff --git a/sparkytron3000.py b/sparkytron3000.py index 84e4576..43d2069 100644 --- a/sparkytron3000.py +++ b/sparkytron3000.py @@ -17,7 +17,6 @@ import subprocess import math from PIL import Image, PngImagePlugin from dotenv import load_dotenv -from ftplib import FTP import threading import matplotlib.pyplot as plt import aiohttp @@ -50,13 +49,15 @@ intents.message_content = True bot = commands.Bot(command_prefix='!', intents=intents) #discord stuff END + async def upload_ftp(local_filename, server_folder, server_filename): - with FTP(ftp_server) as ftp: - ftp.login(ftp_username, ftp_password) - ftp.cwd(ftp_public_html) - ftp.cwd(server_folder) - server_filename = server_filename - ftp.storbinary("STOR " + server_filename, open(local_filename, "rb")) + client = aioftp.Client() + await client.connect(ftp_server) + await client.login(ftp_username, ftp_password) + await client.change_directory(server_folder) + await client.upload(local_filename, server_folder+server_filename, write_into=True) + await client.quit() + async def upload_ftp_ai_images(filename, prompt): html_file = "phixxy.com/ai-images/index.html" @@ -66,26 +67,28 @@ async def upload_ftp_ai_images(filename, prompt):
''' img_list = [] - with FTP(ftp_server) as ftp: - ftp.login(ftp_username, ftp_password) - ftp.cwd(ftp_ai_images) - server_files = ftp.nlst(ftp_ai_images) - server_files.sort() - try: - file_count = int(len(server_files)) - except: - file_count = 0 - new_file_name = str(file_count) + ".png" - ftp.storbinary("STOR " + new_file_name, open(filename, "rb")) - print("Uploaded", new_file_name) - with open(html_file, 'r') as f: - html_data = f.read() - html_insert = html_insert.replace("", new_file_name) - html_insert = html_insert.replace("", prompt) - html_data = html_data.replace("", html_insert) - with open(html_file, "w") as f: - f.writelines(html_data) - ftp.storbinary("STOR " + "index.html", open(html_file, "rb")) + server_folder = os.getenv('ftp_ai_images') + client = aioftp.Client() + await client.connect(ftp_server) + await client.login(ftp_username, ftp_password) + await client.change_directory(server_folder) + server_files = await client.list() + try: + file_count = int(len(server_files)) + except: + file_count = 0 + new_file_name = str(file_count) + ".png" + await client.upload(filename, new_file_name, write_into=True) + print("Uploaded", new_file_name) + with open(html_file, 'r') as f: + html_data = f.read() + html_insert = html_insert.replace("", new_file_name) + html_insert = html_insert.replace("", prompt) + html_data = html_data.replace("", html_insert) + with open(html_file, "w") as f: + f.writelines(html_data) + await client.upload(html_file, "index.html", write_into=True) + await client.quit() def create_channel_config(filepath): config_dict = { @@ -510,70 +513,28 @@ async def currency(ctx, arg1=None, arg2=None, arg3=None, arg4=None): @bot.command() async def meme(ctx): async def update_meme_webpage(filename): - output_file = "index.html" - html = ''' - - -AI generated memes using chatgpt and imgflip
-