Skip to content
Snippets Groups Projects

issue #3: UPDATE including rotes for Projects collection type in the script

Merged issue #3: UPDATE including rotes for Projects collection type in the script
Merged Guilherme Eduardo requested to merge issue-3/Update-script-for-projects into main
1 file
+ 35
1
Compare changes
  • Side-by-side
  • Inline
+ 35
1
@@ -6,6 +6,7 @@ app = Flask(__name__)
@@ -6,6 +6,7 @@ app = Flask(__name__)
# Diretórios onde os arquivos Markdown serão salvos
# Diretórios onde os arquivos Markdown serão salvos
DIR_O_C3SL = os.path.join(os.getcwd(), '../cms-c3sl/themes/c3sl/exampleSite/content')
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_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):
def create_or_update_post(post_id, data, event, content_type):
if not data:
if not data:
@@ -26,6 +27,29 @@ layout: 'legal'
@@ -26,6 +27,29 @@ layout: 'legal'
---
---
{content}
{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:
else:
attributes = data.get('entry', {})
attributes = data.get('entry', {})
content = attributes.get('Descricao', '')
content = attributes.get('Descricao', '')
@@ -67,7 +91,7 @@ summary: "{summary}"
@@ -67,7 +91,7 @@ summary: "{summary}"
def delete_post(post_id, content_type):
def delete_post(post_id, content_type):
if content_type == 'post':
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)
file_path = os.path.join(DIR_POSTS, file_name)
if os.path.exists(file_path):
if os.path.exists(file_path):
@@ -75,6 +99,16 @@ def delete_post(post_id, content_type):
@@ -75,6 +99,16 @@ def delete_post(post_id, content_type):
#print(f"Post com ID {post_id} deletado")
#print(f"Post com ID {post_id} deletado")
else:
else:
print(f"Arquivo com ID {post_id} não encontrado para exclusão")
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'])
@app.route('/run-script', methods=['POST'])
Loading