Reverted a function change for now to avoid bug
This commit is contained in:
parent
ab626999bf
commit
a8d20d4f3b
1 changed files with 18 additions and 27 deletions
|
|
@ -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:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue