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
4d3a5a32
Commit
4d3a5a32
authored
Dec 23, 2024
by
Luis Acosta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Version 1.0
parent
bc591291
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
17 deletions
+83
-17
Connect_CC2.py
Connect_CC2.py
+45
-2
app.py
app.py
+38
-15
No files found.
Connect_CC2.py
View file @
4d3a5a32
import
requests
import
json
class
Callcenter
:
def
__init__
(
self
,
api_key
,
url
):
self
.
url
=
url
...
...
@@ -29,6 +29,7 @@ class Callcenter:
}
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
=
{
...
...
@@ -41,5 +42,47 @@ class Callcenter:
"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
return
response
.
content
def
created_campaing
(
self
,
camp_name
,
date_ini_camp
,
time_ini_camp
,
date_fin_camp
,
time_fin_camp
,
campaign_queue
,
camp_obsv
):
url_center
=
f
"{self.url}/api/outgoingcampaigns/"
headers
=
{
"Content-Type"
:
"application/json"
,
"Accept"
:
"application/json"
,
"CCAuthorization"
:
f
"Bearer {self.token}"
,
"Cookie"
:
self
.
cookie
}
payload
=
{
"name"
:
camp_name
,
"datetime_init"
:
date_ini_camp
,
"datetime_end"
:
date_fin_camp
,
"daytime_init"
:
time_ini_camp
,
"daytime_end"
:
time_fin_camp
,
"retries"
:
"1"
,
"context"
:
"from-internal"
,
"queue"
:
campaign_queue
,
"max_channels"
:
"23"
,
"script"
:
camp_obsv
+
' <style type=
\"
text/css
\"
>
\r\n
body {
\r\n\t
background: #FFF;
\r\n
}
\r\n
</style>'
,
"forms"
:
[
"5"
]
}
response
=
requests
.
post
(
url_center
,
headers
=
headers
,
json
=
payload
,
verify
=
False
)
return
response
def
consult_campaing
(
self
,
campaign_id
,
campaign_date_in
,
campaign_date_out
):
#url_center = f"{self.url}/api/outgoingcampaigns/"
#url_center_aditional = url_center + f"{campaign_id}/general-metrics?page=1&search&date_from='{campaign_date_in}'&date_to='{campaign_date_out}'&maxPerPage=100"
url_center_aditional
=
"https://mxcc-gruposerviandina.hiperpbx.com/api/outgoingcampaigns/90/general-metrics?page=1&search&date_from=2024-12-23&date_to=2024-12-23&maxPerPage=1000"
headers
=
{
"Content-Type"
:
"application/json"
,
"Accept"
:
"application/json"
,
"CCAuthorization"
:
f
"Bearer {self.token}"
,
"Cookie"
:
self
.
cookie
}
response
=
requests
.
get
(
url_center_aditional
,
headers
=
headers
,
verify
=
False
)
return
response
.
content
app.py
View file @
4d3a5a32
...
...
@@ -158,31 +158,54 @@ def Generate_Campaign():
#Update de registros en la campaña
actualizar_campaign
=
db_cc
.
actualizar
(
"update campaign set datetime_init =
%
s, datetime_end =
%
s, daytime_init =
%
s, daytime_end =
%
s, estatus =
%
s where id =
%
s "
,(
f
'{str(date_ini_camp)}'
,
f
'{str(date_fin_camp)}'
,
f
'{str(time_ini_camp)}'
,
f
'{str(time_fin_camp)}'
,
f
'{camp_status}'
,
f
'{camp_id_search}'
))
#Conectar al CC2 para insertar datos en la la campaña
payload
=
{
"fields"
:
campaign_fields
,
"data"
:
campaign_data
}
print
(
payload
)
callcenter
=
Callcenter
(
api_key
,
cc_url
)
id_campaign
=
87
response
=
callcenter
.
search_campaing
(
id_campaign
)
#id_campaign= 87 #Modificar por el valor ingresado
response
=
callcenter
.
search_campaing
(
camp_id_search
)
data
=
response
.
json
()[
'id'
]
print
(
data
)
insert
=
callcenter
.
insert_number_campaing
(
data
,
campaign_fields
,
campaign_data
)
print
(
insert
)
data_response
=
json
.
loads
(
insert
)[
"status"
]
db_cc
.
cerrar
()
#return jsonify({{payload}}), 200
return
jsonify
({
"mensaje"
:
f
"Camp Ingreso Datos: {camp_data_input} Camp Resultado: {camp_data_search} Comparacion: {result} Resgistros: {payload}"
}),
200
#return jsonify({"mensaje": f"Encontrado Campaing ,ID: {camp_id_search} Name: {camp_name_search} Status: {camp_status_search} Fecha Comienzo: {camp_datetime_init_search} Hora Comienzo: {camp_daytime_init_search} Fecha Fin: {camp_datetime_end_search} Hora Fin: {camp_daytime_end_search} Queue: {camp_queue_search}
! Validar Registros de Ingreso"}), 200
#
return jsonify({"mensaje": f"Camp Ingreso Datos: {camp_data_input} Camp Resultado: {camp_data_search} Comparacion: {result} Resgistros: {payload}"}), 200
return
jsonify
({
"mensaje"
:
f
"Encontrado Campaing ,ID: {camp_id_search} Name: {camp_name_search} Status: {camp_status_search} Fecha Comienzo: {camp_datetime_init_search} Hora Comienzo: {camp_daytime_init_search} Fecha Fin: {camp_datetime_end_search} Hora Fin: {camp_daytime_end_search} Queue: {camp_queue_search} Responce: {data_response}
! Validar Registros de Ingreso"
}),
200
else
:
callcenter
=
Callcenter
(
api_key
,
cc_url
)
cread_camp
=
callcenter
.
created_campaing
(
camp_name
,
date_ini_camp
,
time_ini_camp
,
date_fin_camp
,
time_fin_camp
,
campaign_queue
,
camp_obsv
)
print
(
cread_camp
)
return
jsonify
({
"mensaje"
:
f
"No Encontrado Campaing , {camp_name}! Se debe crear una campaña"
}),
401
@
app
.
route
(
'/Consult_Campaign'
,
methods
=
[
'GET'
])
@
jwt_required
()
def
Consult_Campaign
():
usuario
=
get_jwt_identity
()
db
=
MySQLDatabase
(
host
=
db_host
,
user
=
db_user
,
password
=
""
,
database
=
db_name_hiper_service
)
nuevo_id
=
db
.
insertar
(
"INSERT INTO hiper_service_accesos (usuario, token ,fecha_hora, status, message) VALUES (
%
s,
%
s,
%
s,
%
s,
%
s)"
,(
f
'{usuario}'
,
''
,
f
'{fecha_hora}'
,
'Consult Campaing'
,
'Access'
))
db
.
cerrar
()
request_data
=
request
.
get_json
()
dataCollection
=
request_data
[
"dataCollection"
]
campaign_id
=
request_data
[
"id_campaign"
]
campaign_date_ini
=
request_data
[
"date_in"
]
campaign_date_fin
=
request_data
[
"date_out"
]
#Buscar Campaña
callcenter
=
Callcenter
(
api_key
,
cc_url
)
consult_calls
=
callcenter
.
consult_campaing
(
campaign_id
,
campaign_date_ini
,
campaign_date_fin
)
data_response
=
json
.
loads
(
consult_calls
)[
"hydra:member"
]
print
(
data_response
)
raw_json
=
data_response
[
0
]
#return jsonify({"mensaje": f"Datos Ingresados , {dataCollection} ;{campaign_id};{campaign_date_ini};{campaign_date_fin}"}), 401
return
jsonify
(
f
"{raw_json}"
,
200
)
@
jwt
.
expired_token_loader
...
...
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