Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
W
Webservice Marcimex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Luis Acosta
Webservice Marcimex
Commits
bc591291
Commit
bc591291
authored
Dec 19, 2024
by
Luis Acosta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Version 1.0
parent
692b5127
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
452 additions
and
7 deletions
+452
-7
Connect_CC2.py
Connect_CC2.py
+45
-0
Connect_Db.py
Connect_Db.py
+53
-0
README.md
README.md
+3
-0
app.py
app.py
+237
-7
functions.py
functions.py
+114
-0
requirements.txt
requirements.txt
+0
-0
No files found.
Connect_CC2.py
0 → 100644
View file @
bc591291
import
requests
class
Callcenter
:
def
__init__
(
self
,
api_key
,
url
):
self
.
url
=
url
# Paso 1: Hacer un POST para obtener el token
requests
.
packages
.
urllib3
.
disable_warnings
()
url_token
=
f
"{self.url}/api/authentication_apikey_token"
payload
=
{
"api_key"
:
f
"{api_key}"
}
response
=
requests
.
post
(
url_token
,
json
=
payload
,
verify
=
False
)
self
.
token
=
response
.
json
()[
"token"
]
# Paso 2: Enviar un GET con el token obtenido en el encabezado y obtener la Cookie
self
.
user_center_id
=
42
url_center
=
f
"{self.url}/api/centers/select/{self.user_center_id}"
headers
=
{
"CCAuthorization"
:
f
"Bearer {self.token}"
}
response
=
requests
.
get
(
url_center
,
headers
=
headers
,
verify
=
False
)
self
.
cookie
=
response
.
headers
[
"Set-Cookie"
]
print
(
self
.
cookie
)
def
search_campaing
(
self
,
id_campaign
):
url_center
=
f
"{self.url}/api/outgoingcampaigns/{id_campaign}"
print
(
f
"url: {url_center}"
)
headers
=
{
"Content-Type"
:
"application/json"
,
"Accept"
:
"application/json"
,
"CCAuthorization"
:
f
"Bearer {self.token}"
,
"Cookie"
:
self
.
cookie
}
response
=
requests
.
get
(
url_center
,
headers
=
headers
,
verify
=
False
)
return
response
def
insert_number_campaing
(
self
,
id_campaign
,
campaign_fields
,
campaign_data
):
url_center
=
f
"{self.url}/api/outgoingcampaigns/{id_campaign}/add-calls"
headers
=
{
"Content-Type"
:
"application/json"
,
"Accept"
:
"application/json"
,
"CCAuthorization"
:
f
"Bearer {self.token}"
,
"Cookie"
:
self
.
cookie
}
payload
=
{
"fields"
:
campaign_fields
,
"data"
:
campaign_data
}
response
=
requests
.
post
(
url_center
,
headers
=
headers
,
json
=
payload
,
verify
=
False
)
return
response
.
content
\ No newline at end of file
Connect_Db.py
0 → 100644
View file @
bc591291
import
mysql.connector
class
MySQLDatabase
:
def
__init__
(
self
,
host
,
user
,
password
,
database
):
try
:
self
.
connection
=
mysql
.
connector
.
connect
(
host
=
host
,
user
=
user
,
password
=
password
,
database
=
database
)
self
.
cursor
=
self
.
connection
.
cursor
(
dictionary
=
True
)
print
(
"Conexión exitosa a la base de datos "
,
database
)
except
mysql
.
connector
.
Error
as
err
:
print
(
f
"Error al conectar: {err}"
)
def
consultar
(
self
,
query
,
params
=
None
):
try
:
self
.
cursor
.
execute
(
query
,
params
)
return
self
.
cursor
.
fetchall
()
except
mysql
.
connector
.
Error
as
err
:
print
(
f
"Error en la consulta: {err}"
)
return
None
def
insertar
(
self
,
query
,
params
=
None
):
try
:
self
.
cursor
.
execute
(
query
,
params
)
self
.
connection
.
commit
()
print
(
"Inserción exitosa"
)
return
self
.
cursor
.
lastrowid
except
mysql
.
connector
.
Error
as
err
:
print
(
f
"Error al insertar: {err}"
)
self
.
connection
.
rollback
()
return
None
def
actualizar
(
self
,
query
,
params
=
None
):
result
=
False
try
:
self
.
cursor
.
execute
(
query
,
params
)
self
.
connection
.
commit
()
print
(
"Actualizar OK: "
,
params
)
result
=
True
return
result
except
mysql
.
connector
.
Error
as
err
:
print
(
f
"Error al insertar: {err}"
)
self
.
connection
.
rollback
()
result
=
False
return
result
def
cerrar
(
self
):
self
.
cursor
.
close
()
self
.
connection
.
close
()
print
(
"Conexión cerrada"
)
README.md
View file @
bc591291
# Webservice Marcimex
# Webservice Marcimex
Webservice para la inserción de númros a una campaña existente.
Chequeos de ingreso de datos en la misma
Primer test sobre base local e inserción de números en una campaña
\ No newline at end of file
app.py
View file @
bc591291
This diff is collapsed.
Click to expand it.
functions.py
0 → 100644
View file @
bc591291
import
re
from
datetime
import
datetime
,
timedelta
def
convertir_fecha_hora
(
fecha_hora_str
):
result
=
False
fecha_formato
=
False
hora_formato
=
False
#validar el tipo de formato de hora 7/11/2024 08:05:00(j/m/Y H:i:s) o 07/11/2024 08:05:00(d/m/Y H:i:s)
format_date
=
[
"
%
d/
%
m/
%
Y
%
H:
%
M:
%
S"
,
"
%-
d/
%
m/
%
Y
%
H:
%
M:
%
S"
]
for
formato
in
format_date
:
try
:
fecha_hora
=
datetime
.
strptime
(
fecha_hora_str
,
formato
)
result
=
True
fecha_formato
=
fecha_hora
.
strftime
(
"
%
Y-
%
m-
%
d"
)
hora_formato
=
fecha_hora
.
strftime
(
"
%
H:
%
M:
%
S"
)
return
result
,
fecha_formato
,
hora_formato
except
ValueError
:
continue
return
result
,
fecha_formato
,
hora_formato
def
convertir_hora
(
time_ing
):
time_ini
=
datetime
.
strptime
(
time_ing
,
"
%
H:
%
M:
%
S"
)
time_ini
=
str
(
time_ini
)
time_ini
=
time_ini
.
split
()
time_ini
=
time_ini
[
1
]
return
time_ini
def
check_date_in_out
(
date_in
,
date_out
):
# Convertir a objetos datetime
result
=
False
date_ing
=
datetime
.
strptime
(
date_in
,
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
date_fin
=
datetime
.
strptime
(
date_out
,
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
time_ing
=
str
(
date_ing
)
time_ing
=
time_ing
.
split
()
time_ing
=
time_ing
[
1
]
time_fin
=
str
(
date_fin
)
time_fin
=
time_fin
.
split
()
time_fin
=
time_fin
[
1
]
# Validar fechas y horas
if
date_ing
>=
date_fin
:
result
=
False
else
:
result
=
True
if
time_ing
>=
time_fin
:
result
=
False
else
:
result
=
True
return
result
def
limpiar_texto
(
string
):
result
=
True
texto_limpio
=
re
.
sub
(
r'[^a-zA-Z0-9-_\s]'
,
''
,
string
)
#texto_limpio = texto_limpio.encode('utf-8')
if
(
texto_limpio
==
''
):
result
=
False
texto_limpio
=
''
return
result
,
texto_limpio
def
status_camp
(
status_num
):
#status_num = re.sub(r'[0-9]', '', status)
result
=
False
status_data
=
False
if
(
status_num
==
'0'
):
result
=
True
status_data
=
'A'
elif
(
status_num
==
'1'
):
result
=
True
status_data
=
'T'
elif
(
status_num
==
'9'
):
result
=
True
status_data
=
'I'
else
:
result
=
False
status_data
=
False
return
result
,
status_data
def
valid_array_fields
(
array_in
):
result
=
False
cantidad
=
0
datos_limpios
=
[]
# Validar si es una lista
if
isinstance
(
array_in
,
list
):
cantidad
=
len
(
array_in
)
# Verificar si el primer campo es 'phone'
if
array_in
[
0
]
==
"phone"
:
datos_limpios
=
[
re
.
sub
(
r'[^a-zA-Z0-9-_\s]'
,
''
,
item
)
for
item
in
array_in
]
result
=
True
else
:
result
=
False
else
:
result
=
False
return
result
,
cantidad
,
datos_limpios
def
valid_array_data
(
array_in
,
count
):
result
=
False
cantidad
=
0
if
isinstance
(
array_in
,
list
):
patron
=
re
.
compile
(
r'[\w\s.,]+'
)
# Acepta letras, dígitos, espacios, puntos y comas
for
i
,
registro
in
enumerate
(
array_in
,
1
):
elementos_validos
=
all
(
patron
.
fullmatch
(
campo
)
for
campo
in
registro
)
if
elementos_validos
:
if
(
len
(
registro
)
==
count
):
result
=
True
else
:
result
=
False
else
:
result
=
False
else
:
result
=
False
return
result
\ No newline at end of file
requirements.txt
View file @
bc591291
B
blinker
==1.9.0
B
blinker
==1.9.0
...
...
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