Uploads to the website but uses "Unknown Prompt" for now.

This commit is contained in:
phixxy 2024-01-18 00:13:46 -08:00
parent 399a979826
commit 16cd44bb41

View file

@ -75,17 +75,21 @@ async def handle_error(error):
return error return error
async def upload_ftp_ai_images(filename, prompt): async def upload_ftp_ai_images(folder):
for filename in os.listdir(folder):
if filename[-4:] == '.png':
filepath = folder + filename
prompt = "Unknown Prompt" # Will have to update this later
html_file = "phixxy.com/ai-images/index.html" html_file = "phixxy.com/ai-images/index.html"
html_insert = '''<!--REPLACE THIS COMMENT--> html_insert = '''<!--REPLACE THIS COMMENT-->
<div> <div>
<img src="<!--filename-->" loading="lazy"> <img src="<!--filename-->" loading="lazy">
<p class="image-description"><!--description--></p> <p class="image-description"><!--description--></p>
</div>''' </div>'''
img_list = []
server_folder = (os.getenv('ftp_public_html') + 'ai-images/') server_folder = (os.getenv('ftp_public_html') + 'ai-images/')
new_filename = str(time.time_ns()) + ".png" new_filename = str(time.time_ns()) + ".png"
await upload_sftp(filename, server_folder, new_filename) await upload_sftp(filepath, server_folder, new_filename)
print("Uploaded", new_filename) print("Uploaded", new_filename)
with open(html_file, 'r') as f: with open(html_file, 'r') as f:
html_data = f.read() html_data = f.read()
@ -95,6 +99,7 @@ async def upload_ftp_ai_images(filename, prompt):
with open(html_file, "w") as f: with open(html_file, "w") as f:
f.writelines(html_data) f.writelines(html_data)
await upload_sftp(html_file, server_folder, "index.html") await upload_sftp(html_file, server_folder, "index.html")
os.rename(filepath, f"tmp/{new_filename}")
def create_channel_config(filepath): def create_channel_config(filepath):
config_dict = { config_dict = {
@ -275,6 +280,7 @@ async def task_loop():
#Run every minute #Run every minute
if current_time.tm_sec == 0: if current_time.tm_sec == 0:
await meme_handler('tmp/meme/') await meme_handler('tmp/meme/')
await upload_ftp_ai_images('tmp/sfw')