diff --git a/app/parser.py b/app/parser.py index 64c241de8201a1fe4c854b37418528bcef632ae8..f4aea52ae84599ecf56959fb553fbe8195ea36f9 100644 --- a/app/parser.py +++ b/app/parser.py @@ -18,7 +18,7 @@ DIR_O_C3SL = os.path.join(os.getcwd(), '../../cms-c3sl/themes/c3sl/exampleSite/c 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_noticia(identifier, projeto_id, data, event, content_type): +def create_or_update_noticia(identifier, data, event, content_type): if not data: logging.error(f"Code: 400" f"Status: JSON file not found\n") @@ -50,7 +50,7 @@ layout: 'legal' partner = attributes.get('Parceiro', '') content = attributes.get('Descricao', '') - file_name = f"{projeto_id}.md" + file_name = f"{identifier}.md" file_path = os.path.join(DIR_PROJECTS, file_name) edited_line = 'Edited: true\n' if event == 'entry.update' else '' @@ -63,6 +63,7 @@ status: "{status}" {edited_line}ShowReadingTime: true --- --- + {content} """ ##Caso a requisição seja para criar/alterar uma notícia @@ -119,7 +120,7 @@ summary: "{summary}" return f"Error writing file{e}", 400 #Deleta algum tipo de conteudo enviado por requisição -def delete_noticia(identifier, projeto_id, content_type): +def delete_noticia(identifier, content_type): #Deletando uma notícia if content_type == 'noticia': file_name = f"{identifier}.md" @@ -133,14 +134,14 @@ def delete_noticia(identifier, projeto_id, content_type): #Deletando um projeto elif content_type == 'projeto': - file_name = f"{projeto_id}.md" + file_name = f"{identifier}.md" file_path = os.path.join(DIR_PROJECTS, file_name) if os.path.exists(file_path): os.remove(file_path) - logging.info(f"200 - DELETED: Project with ID number {projeto_id}") + logging.info(f"200 - DELETED: Project with ID name {identifier}") else: - logging.error(f"200 - ERROR: File of project with ID number {projeto_id} not found for exclusion") + logging.error(f"200 - ERROR: File of project with ID name {identifier} not found for exclusion") else: logging.error(f"400 - ERROR: Content type: '{content_type}' not recognized for deletion") @@ -157,17 +158,8 @@ def run_script(): identifier = attributes.get('Identificador', '') #Do arquivo JSON, separa ID do conteudo, tipo do evento e o conteúdo - projeto_id = data.get('entry', {}).get('id') event = data.get('event') content_type = data.get('model', '') # Obtém o tipo de conteúdo do Strapi - - if not projeto_id: - logging.error(f"Code: 400" - f"Status: ID not found in JSON: {data}") - logging.exception("error occurred while processing the event") - return "ID not found in JSON", 400 - else: - print(f"Event: {event}, ID: {projeto_id}, Type: {content_type}") if not identifier: logging.error(f"Code: 400" @@ -183,14 +175,14 @@ def run_script(): return f"File created in Strapi {identifier} - Type: {content_type}", 200 elif event in ['entry.update', 'entry.publish']: - create_or_update_noticia(identifier, projeto_id, data, event, content_type) + create_or_update_noticia(identifier, data, event, content_type) logging.info(f"\nFile created in Hugo- ID: {identifier} - Type: {content_type}" f"\nData: {data}\nOperation completed successfully\n") return f"Operation completed successfully\n Data: {data}", 200 elif event in ['entry.delete', 'entry.unpublish']: - delete_noticia(identifier, projeto_id, content_type) + delete_noticia(identifier, content_type) logging.info(f"File removed - ID: {identifier} - Type: {content_type}") return f"File removed with ID {identifier}", 200