Merge pull request #11 from phixxy/meme

Reverted a function change for now to avoid bug
This commit is contained in:
phixxy 2023-07-17 16:59:34 -07:00 committed by GitHub
commit 5255c4c976
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -592,36 +592,27 @@ async def meme(ctx):
async def update_meme_webpage(filename): async def update_meme_webpage(filename):
server_folder = os.getenv('ftp_ai_memes') server_folder = os.getenv('ftp_ai_memes')
client = aioftp.Client() 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: try:
await client.connect(ftp_server) file_count = len(server_files)
await client.login(ftp_username, ftp_password) except:
await client.change_directory(server_folder) file_count = 0
new_file_name = str(file_count) + ".png"
async with client: await client.upload(filename, new_file_name, write_into=True)
server_files = await client.list() print("Uploaded", new_file_name)
with open("phixxy.com/ai-memes/index.html", 'r') as f:
file_count = len(server_files) if server_files else 0 html_data = f.read()
new_file_name = str(file_count) + ".png" html_insert = '<!--ADD IMG HERE-->\n <img src="' + new_file_name + '" loading="lazy">'
await client.upload(filename, new_file_name, write_into=True) html_data = html_data.replace('<!--ADD IMG HERE-->',html_insert)
print("Uploaded", new_file_name) with open("phixxy.com/ai-memes/index.html", "w") as f:
f.writelines(html_data)
async with aiofiles.open("phixxy.com/ai-memes/index.html", 'r') as f: await client.upload("phixxy.com/ai-memes/index.html", "index.html", write_into=True)
html_data = await f.read()
html_insert = '<!--ADD IMG HERE-->\n <img src="' + new_file_name + '" loading="lazy">'
html_data = html_data.replace('<!--ADD IMG HERE-->', html_insert)
async with aiofiles.open("phixxy.com/ai-memes/index.html", "w") as f:
await f.write(html_data)
await client.upload("phixxy.com/ai-memes/index.html", "index.html", write_into=True)
except Exception as error:
print("An error occurred:", error)
await handle_error(error)
await client.quit() await client.quit()
async def generate_random_meme(topic): async def generate_random_meme(topic):
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get('https://api.imgflip.com/get_memes') as resp: async with session.get('https://api.imgflip.com/get_memes') as resp: