Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
m3_webInterface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
m3
m3_webInterface
Commits
3b340562
Commit
3b340562
authored
Feb 18, 2025
by
Ulises Morales Ramírez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nueva api para reportes y update
parent
bfedde89
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
0 deletions
+55
-0
urls.py
catalog/urls.py
+2
-0
views.py
catalog/views.py
+53
-0
No files found.
catalog/urls.py
View file @
3b340562
...
@@ -41,6 +41,8 @@ urlpatterns = [
...
@@ -41,6 +41,8 @@ urlpatterns = [
url
(
r'^settings/password$'
,
views
.
settingsView
,
name
=
'settings-password'
),
url
(
r'^settings/password$'
,
views
.
settingsView
,
name
=
'settings-password'
),
url
(
r'^settings/searches$'
,
views
.
settingsSearches
,
name
=
'settings-search'
),
url
(
r'^settings/searches$'
,
views
.
settingsSearches
,
name
=
'settings-search'
),
url
(
r'^settings/apikey$'
,
views
.
settingsApiKey
,
name
=
'api-key'
),
url
(
r'^settings/apikey$'
,
views
.
settingsApiKey
,
name
=
'api-key'
),
#----------------------------------------------------------------------------
url
(
r'^api/run_update_and_report/'
,
views
.
run_update_and_report
,
name
=
'run_update_and_report'
),
]
]
catalog/views.py
View file @
3b340562
...
@@ -54,6 +54,11 @@ from django.db.models import Value
...
@@ -54,6 +54,11 @@ from django.db.models import Value
import
html
import
html
import
string
import
string
from
django.contrib.auth
import
logout
from
django.contrib.auth
import
logout
from
django.http
import
JsonResponse
from
django.core.management
import
call_command
from
django.views.decorators.csrf
import
csrf_exempt
import
json
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
...
@@ -560,3 +565,51 @@ def audioPlayerTest(request, publisher, start, end):
...
@@ -560,3 +565,51 @@ def audioPlayerTest(request, publisher, start, end):
filelist
=
[
f
[:
-
5
]
for
f
in
listAudioFiles
(
publisher
,
int
(
start
),
int
(
end
))]
filelist
=
[
f
[:
-
5
]
for
f
in
listAudioFiles
(
publisher
,
int
(
start
),
int
(
end
))]
return
render
(
request
,
'new/audioPlayerTest.html'
,{
"filelist"
:
filelist
,
"publisher"
:
publisher
})
return
render
(
request
,
'new/audioPlayerTest.html'
,{
"filelist"
:
filelist
,
"publisher"
:
publisher
})
#----------------------------------|----------------------------------------------
def
read_last_execution_date
(
log_file
=
'log.txt'
):
try
:
with
open
(
log_file
,
'r'
)
as
file
:
return
file
.
read
()
.
strip
()
except
FileNotFoundError
:
return
None
def
write_execution_date
(
log_file
=
'log.txt'
):
today
=
datetime
.
date
.
today
()
with
open
(
log_file
,
'w'
)
as
file
:
file
.
write
(
today
.
strftime
(
'
%
Y-
%
m-
%
d'
))
@
csrf_exempt
def
run_update_and_report
(
request
):
if
request
.
method
==
'POST'
:
try
:
# Leer parámetros del request
data
=
json
.
loads
(
request
.
body
)
db_path
=
data
.
get
(
'db_path'
,
'/data/m3/news/'
)
json_output_path
=
data
.
get
(
'output_path'
,
'catalog/static/js/data.js'
)
# Ejecutar los comandos
call_command
(
'updateDB'
,
db_path
)
call_command
(
'report'
,
json_output_path
)
# Obtener fechas
last_execution_date
=
read_last_execution_date
()
if
not
last_execution_date
:
last_execution_date
=
datetime
.
date
.
today
()
.
strftime
(
'
%
Y-
%
m-
%
d'
)
fecha_inicio
=
last_execution_date
fecha_final
=
(
datetime
.
date
.
today
()
-
datetime
.
timedelta
(
days
=
1
))
.
strftime
(
'
%
Y-
%
m-
%
d'
)
# Enviar POST a la URL
payload
=
{
"fecha_inicio"
:
fecha_inicio
,
"fecha_final"
:
fecha_final
}
response
=
requests
.
post
(
"https://em.geoint.mx/m3/processnews"
,
json
=
payload
)
response
.
raise_for_status
()
# Guardar nueva fecha de ejecución
write_execution_date
()
return
JsonResponse
({
'status'
:
'success'
,
'message'
:
f
'Report generated at {json_output_path}'
,
'api_response'
:
response
.
json
()})
except
Exception
as
e
:
return
JsonResponse
({
'status'
:
'error'
,
'message'
:
str
(
e
)},
status
=
500
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment