Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Parser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CMS
Parser
Commits
eb319fd3
Commit
eb319fd3
authored
8 months ago
by
esrsc23
Browse files
Options
Downloads
Patches
Plain Diff
UPDATE Fixing configuration for modifying/adding projects
parent
88be5a3b
Branches
Branches containing commit
No related tags found
1 merge request
!8
UPDATE Fixing configuration for modifying/adding projects
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/parser.py
+9
-17
9 additions, 17 deletions
app/parser.py
with
9 additions
and
17 deletions
app/parser.py
+
9
−
17
View file @
eb319fd3
...
@@ -18,7 +18,7 @@ DIR_O_C3SL = os.path.join(os.getcwd(), '../../cms-c3sl/themes/c3sl/exampleSite/c
...
@@ -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_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
'
)
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
:
if
not
data
:
logging
.
error
(
f
"
Code: 400
"
logging
.
error
(
f
"
Code: 400
"
f
"
Status: JSON file not found
\n
"
)
f
"
Status: JSON file not found
\n
"
)
...
@@ -50,7 +50,7 @@ layout: 'legal'
...
@@ -50,7 +50,7 @@ layout: 'legal'
partner
=
attributes
.
get
(
'
Parceiro
'
,
''
)
partner
=
attributes
.
get
(
'
Parceiro
'
,
''
)
content
=
attributes
.
get
(
'
Descricao
'
,
''
)
content
=
attributes
.
get
(
'
Descricao
'
,
''
)
file_name
=
f
"
{
projeto_id
}
.md
"
file_name
=
f
"
{
identifier
}
.md
"
file_path
=
os
.
path
.
join
(
DIR_PROJECTS
,
file_name
)
file_path
=
os
.
path
.
join
(
DIR_PROJECTS
,
file_name
)
edited_line
=
'
Edited: true
\n
'
if
event
==
'
entry.update
'
else
''
edited_line
=
'
Edited: true
\n
'
if
event
==
'
entry.update
'
else
''
...
@@ -63,6 +63,7 @@ status: "{status}"
...
@@ -63,6 +63,7 @@ status: "{status}"
{
edited_line
}
ShowReadingTime: true
{
edited_line
}
ShowReadingTime: true
---
---
---
---
{
content
}
{
content
}
"""
"""
##Caso a requisição seja para criar/alterar uma notícia
##Caso a requisição seja para criar/alterar uma notícia
...
@@ -119,7 +120,7 @@ summary: "{summary}"
...
@@ -119,7 +120,7 @@ summary: "{summary}"
return
f
"
Error writing file
{
e
}
"
,
400
return
f
"
Error writing file
{
e
}
"
,
400
#Deleta algum tipo de conteudo enviado por requisição
#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
#Deletando uma notícia
if
content_type
==
'
noticia
'
:
if
content_type
==
'
noticia
'
:
file_name
=
f
"
{
identifier
}
.md
"
file_name
=
f
"
{
identifier
}
.md
"
...
@@ -133,14 +134,14 @@ def delete_noticia(identifier, projeto_id, content_type):
...
@@ -133,14 +134,14 @@ def delete_noticia(identifier, projeto_id, content_type):
#Deletando um projeto
#Deletando um projeto
elif
content_type
==
'
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
)
file_path
=
os
.
path
.
join
(
DIR_PROJECTS
,
file_name
)
if
os
.
path
.
exists
(
file_path
):
if
os
.
path
.
exists
(
file_path
):
os
.
remove
(
file_path
)
os
.
remove
(
file_path
)
logging
.
info
(
f
"
200 - DELETED: Project with ID n
umber
{
projeto_id
}
"
)
logging
.
info
(
f
"
200 - DELETED: Project with ID n
ame
{
identifier
}
"
)
else
:
else
:
logging
.
error
(
f
"
200 - ERROR: File of project with ID n
umber
{
projeto_id
}
not found for exclusion
"
)
logging
.
error
(
f
"
200 - ERROR: File of project with ID n
ame
{
identifier
}
not found for exclusion
"
)
else
:
else
:
logging
.
error
(
f
"
400 - ERROR: Content type:
'
{
content_type
}
'
not recognized for deletion
"
)
logging
.
error
(
f
"
400 - ERROR: Content type:
'
{
content_type
}
'
not recognized for deletion
"
)
...
@@ -157,18 +158,9 @@ def run_script():
...
@@ -157,18 +158,9 @@ def run_script():
identifier
=
attributes
.
get
(
'
Identificador
'
,
''
)
identifier
=
attributes
.
get
(
'
Identificador
'
,
''
)
#Do arquivo JSON, separa ID do conteudo, tipo do evento e o conteúdo
#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
'
)
event
=
data
.
get
(
'
event
'
)
content_type
=
data
.
get
(
'
model
'
,
''
)
# Obtém o tipo de conteúdo do Strapi
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
:
if
not
identifier
:
logging
.
error
(
f
"
Code: 400
"
logging
.
error
(
f
"
Code: 400
"
f
"
Status: ID not found in JSON:
{
data
}
"
)
f
"
Status: ID not found in JSON:
{
data
}
"
)
...
@@ -183,14 +175,14 @@ def run_script():
...
@@ -183,14 +175,14 @@ def run_script():
return
f
"
File created in Strapi
{
identifier
}
- Type:
{
content_type
}
"
,
200
return
f
"
File created in Strapi
{
identifier
}
- Type:
{
content_type
}
"
,
200
elif
event
in
[
'
entry.update
'
,
'
entry.publish
'
]:
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
"
\n
File created in Hugo- ID:
{
identifier
}
- Type:
{
content_type
}
"
logging
.
info
(
f
"
\n
File created in Hugo- ID:
{
identifier
}
- Type:
{
content_type
}
"
f
"
\n
Data:
{
data
}
\n
Operation completed successfully
\n
"
)
f
"
\n
Data:
{
data
}
\n
Operation completed successfully
\n
"
)
return
f
"
Operation completed successfully
\n
Data:
{
data
}
"
,
200
return
f
"
Operation completed successfully
\n
Data:
{
data
}
"
,
200
elif
event
in
[
'
entry.delete
'
,
'
entry.unpublish
'
]:
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
}
"
)
logging
.
info
(
f
"
File removed - ID:
{
identifier
}
- Type:
{
content_type
}
"
)
return
f
"
File removed with ID
{
identifier
}
"
,
200
return
f
"
File removed with ID
{
identifier
}
"
,
200
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment