From 85035e4ec3b54f5008b30c97ef0fa4d15d529cf1 Mon Sep 17 00:00:00 2001
From: phixxy
Date: Sat, 20 Apr 2024 21:03:41 -0700
Subject: [PATCH] made blog format use damn small blog for better organization
---
cogs/phixxycom.py | 40 +++++++++++-----------------------------
1 file changed, 11 insertions(+), 29 deletions(-)
diff --git a/cogs/phixxycom.py b/cogs/phixxycom.py
index 000322e..5c1cec9 100644
--- a/cogs/phixxycom.py
+++ b/cogs/phixxycom.py
@@ -239,17 +239,16 @@ class PhixxyCom(commands.Cog):
last_5_messages += lines[-i]
return last_5_messages
- async def generate_blog(self):
+ async def generate_blog(self, force=False):
start_time = time.time()
topic = ''
- filename = f"{self.data_dir}ai-blog/index.html"
- with open(filename, 'r', encoding="utf-8") as f:
- html_data = f.read()
- current_time = time.time()
- current_struct_time = time.localtime(current_time)
- date = time.strftime("%B %d, %Y", current_struct_time)
- if date in html_data:
+ #filename = f"{self.data_dir}ai-blog/index.html"
+ #filename format year-month-day ie: 2021-01-01.md
+ filename = f"{self.data_dir}ai-blog/{time.strftime('%Y-%m-%d')}.md"
+ if os.path.exists(filename) and not force:
return
+ current_struct_time = time.time()
+ date = time.strftime("%B %d, %Y", current_struct_time)
blogpost_file = f"{self.data_dir}blog_topics.txt"
if os.path.isfile(blogpost_file):
with open(blogpost_file, 'r') as f:
@@ -265,32 +264,15 @@ class PhixxyCom(commands.Cog):
self.logger.info("No topic given for blogpost, generating one.")
topic = await self.answer_question(question)
self.logger.info("Writing blogpost")
- post_div = '''
- '''
title_prompt = 'generate an absurd essay title about ' + topic
title = await self.answer_question(title_prompt, model="gpt-3.5-turbo")
prompt = 'Write a satirical essay with a serious tone titled: "' + title + '". Do not label parts of the essay.'
content = await self.answer_question(prompt, model="gpt-4-turbo-preview")
if title in content[:len(title)]:
content = content.replace(title, '', 1)
- content = f"{content}
"
- content = content.replace('\n\n', "
")
- content = content.replace("
", '')
-
- post_div = post_div.replace("", title)
- post_div = post_div.replace("", date)
- post_div = post_div.replace("", content)
-
- html_data = html_data.replace("", post_div)
- with open(filename, 'w', encoding="utf-8") as f:
- f.write(html_data)
- await self.upload_sftp(filename, (os.getenv('ftp_public_html') + 'ai-blog/'), "index.html")
+ with open(filename, 'w') as f:
+ f.write(f"# {title}\n\n*{date}*\n\n{content}")
+ await self.upload_sftp(filename, (os.getenv('ftp_public_html') + 'ai-blog/'), filename)
run_time = time.time() - start_time
self.logger.debug("It took " + str(run_time) + " seconds to generate the blog post!")
output = f"Blog Updated! ({run_time} seconds) {title} https://ai.phixxy.com/ai-blog"
@@ -299,7 +281,7 @@ class PhixxyCom(commands.Cog):
@commands.command()
async def force_blog(self, ctx):
await ctx.send("Forcing blog generation")
- await self.generate_blog()
+ await self.generate_blog(force=True)
@commands.command(
description="Website",