From 61eadd47c18a64e31d9e3a6612ff6e5903618d57 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 7 Feb 2023 15:44:13 +0100 Subject: [PATCH] . --- main.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 20f433c..66e6f82 100644 --- a/main.py +++ b/main.py @@ -133,27 +133,33 @@ class: with open(f'./data/{uid}/{b64}{datenow}/{images}.png', 'wb') as handler: handler.write(img_data) 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 {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 \' - cmd = cmd.replace("'", "\\'") - os.system(cmd) + #if the os is linux we replace the \ with / + + try: + os.system(f"marp.exe {cmd}") + except: + cmd = cmd.replace("'", "\\'") + os.system(f"./marp {cmd}") print(cmd) #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 - 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 = cmd.replace("'", "\\'") + cmd = f" --image png -o ./data/{uid}/{b64}{datenow}/{subject}.png --allow-local-files ./data/{uid}/{b64}{datenow}/{subject}.md" #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) #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 = cmd.replace("'", "\\'") - os.system(cmd) + cmd = f" --html --allow-local-files ./data/{uid}/{b64}{datenow}/{subject}.md" + try : os.system(f"marp.exe {cmd}") + except: + cmd = cmd.replace("'", "\\'") + os.system(f"./marp {cmd}") print(cmd) #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) @@ -197,6 +203,8 @@ async def get(ctx: discord.ApplicationContext, pid: str): @bot.event async def on_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 not os.path.exists("data"): os.mkdir("data")