This commit is contained in:
Paillat
2023-02-07 15:44:13 +01:00
parent df4d5fd998
commit 61eadd47c1

28
main.py
View File

@@ -133,27 +133,33 @@ class:
with open(f'./data/{uid}/{b64}{datenow}/{images}.png', 'wb') as handler: with open(f'./data/{uid}/{b64}{datenow}/{images}.png', 'wb') as handler:
handler.write(img_data) handler.write(img_data)
with open(f"./data/{uid}/{b64}{datenow}/{subject}.md", "w", encoding="utf8") as f: f.write(present) with open(f"./data/{uid}/{b64}{datenow}/{subject}.md", "w", encoding="utf8") as f: f.write(present)
#we execute the command to convert the markdown file to a pdf and html file and also generate the first slide image
current_dir = os.getcwd()
print(current_dir)
#cmd = f"./marp --pdf --allow-local-files data/{uid}/{b64}{datenow}/{subject}.md" #cmd = f"./marp --pdf --allow-local-files data/{uid}/{b64}{datenow}/{subject}.md"
cmd = f"./marp --pdf --allow-local-files {current_dir}/data/{uid}/{b64}{datenow}/{subject}.md" cmd = f"--pdf --allow-local-files ./data/{uid}/{b64}{datenow}/{subject}.md"
#we replace all the ' with \' #we replace all the ' with \'
#if the os is linux we replace the \ with /
try:
os.system(f"marp.exe {cmd}")
except:
cmd = cmd.replace("'", "\\'") cmd = cmd.replace("'", "\\'")
os.system(cmd) os.system(f"./marp {cmd}")
print(cmd) print(cmd)
#cmd = f"./marp --image png -o ./data/{uid}/{b64}{datenow}/{subject}.png --allow-local-files data/{uid}/{b64}{datenow}/{subject}.md" #cmd = f"./marp --image png -o ./data/{uid}/{b64}{datenow}/{subject}.png --allow-local-files data/{uid}/{b64}{datenow}/{subject}.md"
#the above command is not working in docker, so we use the following one #the above command is not working in docker, so we use the following one
cmd = f"./marp --image png -o {current_dir}/data/{uid}/{b64}{datenow}/{subject}.png --allow-local-files {current_dir}/data/{uid}/{b64}{datenow}/{subject}.md" cmd = f" --image png -o ./data/{uid}/{b64}{datenow}/{subject}.png --allow-local-files ./data/{uid}/{b64}{datenow}/{subject}.md"
cmd = cmd.replace("'", "\\'")
#hopefully this will work in docker #hopefully this will work in docker
os.system(cmd) try: os.system(f"marp.exe {cmd}")
except:
cmd = cmd.replace("'", "\\'")
os.system(f"./marp {cmd}")
print(cmd) print(cmd)
#cmd = f"./marp --html --allow-local-files data/{uid}/{b64}{datenow}/{subject}.md" #cmd = f"./marp --html --allow-local-files data/{uid}/{b64}{datenow}/{subject}.md"
cmd = f"./marp --html --allow-local-files {current_dir}/data/{uid}/{b64}{datenow}/{subject}.md" cmd = f" --html --allow-local-files ./data/{uid}/{b64}{datenow}/{subject}.md"
try : os.system(f"marp.exe {cmd}")
except:
cmd = cmd.replace("'", "\\'") cmd = cmd.replace("'", "\\'")
os.system(cmd) os.system(f"./marp {cmd}")
print(cmd) print(cmd)
#we create an embed with the first slide imageand send it with the pdf file and the markdown file #we create an embed with the first slide imageand send it with the pdf file and the markdown file
embed = discord.Embed(title=subject2, description="Thanks for using presentator bot. You can download the presentation in different formats (pdf, markdown, html). The images are generated by an ai. If you want to modify your presentation you can use the markdown file. More information about how to modify the file [HERE](https://marp.app).", color=0xaaaaaa) embed = discord.Embed(title=subject2, description="Thanks for using presentator bot. You can download the presentation in different formats (pdf, markdown, html). The images are generated by an ai. If you want to modify your presentation you can use the markdown file. More information about how to modify the file [HERE](https://marp.app).", color=0xaaaaaa)
@@ -197,6 +203,8 @@ async def get(ctx: discord.ApplicationContext, pid: str):
@bot.event @bot.event
async def on_ready(): async def on_ready():
print("Bot is ready") print("Bot is ready")
#print the name of the os (linux or windows)
print(str(os.name))
#if the data directory doesn't exist we create it #if the data directory doesn't exist we create it
if not os.path.exists("data"): if not os.path.exists("data"):
os.mkdir("data") os.mkdir("data")