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

@ -73,28 +73,33 @@ async def handle_error(error):
with open("databases/error_log.txt", 'a') as f: with open("databases/error_log.txt", 'a') as f:
f.write(log_line) f.write(log_line)
return error return error
async def upload_ftp_ai_images(filename, prompt):
html_file = "phixxy.com/ai-images/index.html" async def upload_ftp_ai_images(folder):
html_insert = '''<!--REPLACE THIS COMMENT--> for filename in os.listdir(folder):
<div> if filename[-4:] == '.png':
<img src="<!--filename-->" loading="lazy"> filepath = folder + filename
<p class="image-description"><!--description--></p> prompt = "Unknown Prompt" # Will have to update this later
</div>'''
img_list = [] html_file = "phixxy.com/ai-images/index.html"
server_folder = (os.getenv('ftp_public_html') + 'ai-images/') html_insert = '''<!--REPLACE THIS COMMENT-->
new_filename = str(time.time_ns()) + ".png" <div>
await upload_sftp(filename, server_folder, new_filename) <img src="<!--filename-->" loading="lazy">
print("Uploaded", new_filename) <p class="image-description"><!--description--></p>
with open(html_file, 'r') as f: </div>'''
html_data = f.read() server_folder = (os.getenv('ftp_public_html') + 'ai-images/')
html_insert = html_insert.replace("<!--filename-->", new_filename) new_filename = str(time.time_ns()) + ".png"
html_insert = html_insert.replace("<!--description-->", prompt) await upload_sftp(filepath, server_folder, new_filename)
html_data = html_data.replace("<!--REPLACE THIS COMMENT-->", html_insert) print("Uploaded", new_filename)
with open(html_file, "w") as f: with open(html_file, 'r') as f:
f.writelines(html_data) html_data = f.read()
await upload_sftp(html_file, server_folder, "index.html") html_insert = html_insert.replace("<!--filename-->", new_filename)
html_insert = html_insert.replace("<!--description-->", prompt)
html_data = html_data.replace("<!--REPLACE THIS COMMENT-->", html_insert)
with open(html_file, "w") as f:
f.writelines(html_data)
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')