From cae08459d0fb07ba858b0d50cceeb14d15099a50 Mon Sep 17 00:00:00 2001 From: Guilherme Eduardo <gegs23@inf.ufpr.br> Date: Tue, 3 Sep 2024 12:01:25 -0300 Subject: [PATCH] issue #3: UPDATE including rotes for Projects collection type in the script --- app.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 01507a8..5f769c0 100644 --- a/app.py +++ b/app.py @@ -6,6 +6,7 @@ app = Flask(__name__) # Diretórios onde os arquivos Markdown serão salvos DIR_O_C3SL = os.path.join(os.getcwd(), '../cms-c3sl/themes/c3sl/exampleSite/content') DIR_POSTS = os.path.join(os.getcwd(), '../cms-c3sl/themes/c3sl/exampleSite/content/noticia') +DIR_PROJECTS = os.path.join(os.getcwd(), '../cms-c3sl/themes/c3sl/exampleSite/content/projetos') def create_or_update_post(post_id, data, event, content_type): if not data: @@ -26,6 +27,29 @@ layout: 'legal' --- {content} """ + elif content_type == 'projeto': + attributes = data.get('entry', {}) + title = attributes.get('Titulo', '') + status = attributes.get('Status', '') + partner = attributes.get('Parceiro', '') + content = attributes.get('Descricao', '') + + file_name = f"{post_id}.md" + file_path = os.path.join(DIR_PROJECTS, file_name) + + edited_line = 'Edited: true\n' if event == 'entry.update' else '' + + content_markdown = f"""--- +title: "{title}" +author: " Parceiro: {partner}" +status: "{status}" +{edited_line}ShowReadingTime: true +--- +--- + +{content} +""" + else: attributes = data.get('entry', {}) content = attributes.get('Descricao', '') @@ -67,7 +91,7 @@ summary: "{summary}" def delete_post(post_id, content_type): if content_type == 'post': - file_name = f"{post_id}.md" + file_name = f"{post_id}.md" file_path = os.path.join(DIR_POSTS, file_name) if os.path.exists(file_path): @@ -75,6 +99,16 @@ def delete_post(post_id, content_type): #print(f"Post com ID {post_id} deletado") else: print(f"Arquivo com ID {post_id} não encontrado para exclusão") + elif content_type == 'projeto': + file_name = f"{post_id}.md" + file_path = os.path.join(DIR_PROJECTS, file_name) + + if os.path.exists(file_path): + os.remove(file_path) + #print(f"Post com ID {post_id} deletado") + else: + print(f"Arquivo com ID {post_id} não encontrado para exclusão") + @app.route('/run-script', methods=['POST']) -- GitLab