Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
scrapper-portabilidad
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
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
Javier
scrapper-portabilidad
Commits
caf4ba71
Commit
caf4ba71
authored
Apr 28, 2022
by
Javier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Recargas
parent
7906dc3f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
8 deletions
+69
-8
cli.py
cli.py
+69
-8
No files found.
cli.py
View file @
caf4ba71
from
typing
import
Tuple
import
typer
from
mbilling.functions
import
active_users
,
fully_ported_clis
,
get_cdrs
from
mbilling.functions
import
MagnusCommandError
,
active_users
,
fully_ported_clis
,
get_cdrs
,
add_balance
import
time
import
pyodbc
import
os
...
...
@@ -135,7 +135,8 @@ def update_balance(target_clis: list[str]) -> Tuple[int, int]:
# Cálculo de Parámetros
flat_rate
=
sip_account
[
'offer'
]
if
sip_account
[
'plan'
]
==
TARIFA_PLANA_ID
else
None
credit
=
999.00
if
sip_account
[
'credit'
]
<=
0
and
sip_account
[
'postpaid'
]
==
True
else
round
(
sip_account
[
'credit'
],
2
)
credit
=
999.00
if
sip_account
[
'credit'
]
<=
0
and
sip_account
[
'postpaid'
]
==
True
else
round
(
sip_account
[
'credit'
],
2
)
# Si la cuenta es emisora de llamadas, añadimos ClaveEXT
if
sip_account
[
'credit'
]
>
0
:
...
...
@@ -163,20 +164,18 @@ def update_balance(target_clis: list[str]) -> Tuple[int, int]:
else
:
non_updated
=
non_updated
+
1
return
updated
,
non_updated
def
add_cdrs
(
accounts
:
list
[
dict
])
->
'list[dict]'
:
cdrs
=
[]
with
typer
.
progressbar
(
accounts
.
keys
(),
label
=
"Descargando CDRs"
)
as
account_data
:
for
account
in
account_data
:
cdrs
.
extend
(
get_cdrs
(
phone_number
=
account
,
since
=
accounts
[
account
]))
for
account
in
(
accounts
.
keys
()):
cdrs
.
extend
(
get_cdrs
(
phone_number
=
account
,
since
=
accounts
[
account
]))
with
typer
.
progressbar
(
cdrs
,
label
=
'Sincronizando CDRs'
)
as
cdr_data
:
with
pyodbc
.
connect
(
SQL_SERVER_CNX_STRING
)
as
cnx
:
with
cnx
.
cursor
()
as
cursor
:
for
cdr
in
cdr_data
:
cursor
.
execute
(
'INSERT INTO bdd_wifi.dbo.TB_OMV_CDR_Cliente (Tipo, DDi, Fecha,
\
...
...
@@ -191,6 +190,57 @@ def add_cdrs(accounts: list[dict]) -> 'list[dict]':
cnx
.
commit
()
return
cdrs
def
process_refills
()
->
Tuple
[
int
,
float
]:
"""Ejecuta las Recargas pendientes
"""
total_refills
=
0
amount
=
0.0
# Actualización de Balance en Programa de Facturación
with
pyodbc
.
connect
(
SQL_SERVER_CNX_STRING
)
as
cnx
:
with
cnx
.
cursor
()
as
cursor
:
# Obtención de Recargas Pendientes
pending_refills
=
cnx
.
execute
(
'SELECT r.ID, f.DDI, r.Importe, r.Automatica
\
FROM [bdd_wifi].[dbo].[TB_Recargas] r
\
INNER JOIN [bdd_wifi].[dbo].[TB_ServicioFijo] f ON f.UsuarioEXT=r.Cuenta
\
WHERE Procesado=0'
)
# Procesamiento de Recargas
with
typer
.
progressbar
(
pending_refills
.
fetchall
(),
label
=
"Efectuando Recargas"
)
as
refills
:
for
refill
in
refills
:
try
:
# Generación de Descripción
description
=
'Recarga Automática ID '
if
refill
[
3
]
else
'Recarga Manual ID '
description
=
description
+
str
(
refill
[
0
])
# Insercción de Balance
add_balance
(
phone_number
=
refill
[
1
],
quantity
=
refill
[
2
],
description
=
description
)
total_refills
=
total_refills
+
1
amount
=
amount
+
refill
[
2
]
except
MagnusCommandError
:
# Número no registrado en Magnus
pass
finally
:
cnx
.
execute
(
'UPDATE [bdd_wifi].[dbo].[TB_Recargas] SET Procesado=1 WHERE ID=?'
,
(
refill
[
0
],)
)
cnx
.
commit
()
return
total_refills
,
amount
# Definición de Comandos
...
...
@@ -258,6 +308,8 @@ def import_cdr(account: str = typer.Argument(None), only_charged: bool = typer.A
@app.command
()
def
synchronize
():
"""Sincroniza el Servidor de Telefonía con el de Facturación
"""
start_time
=
datetime
.
now
()
# Verificación de SIP en Nueva Plataforma
...
...
@@ -271,6 +323,14 @@ def synchronize():
msg
=
msg
+
f
" de un total de {updated + non_updated} líneas."
typer
.
echo
(
msg
)
# Recargas
total_refills
,
amount
=
process_refills
()
msg
=
f
"Se han procesado "
msg
=
msg
+
typer
.
style
(
total_refills
,
fg
=
typer
.
colors
.
GREEN
,
bold
=
True
)
msg
=
msg
+
" recargas con un importe total de "
msg
=
msg
+
typer
.
style
(
f
'{amount}€'
,
fg
=
typer
.
colors
.
GREEN
,
bold
=
True
)
typer
.
echo
(
msg
)
# Actualización de CDRs
accounts
=
get_last_updated_cdr
()
cdrs
=
add_cdrs
(
accounts
)
...
...
@@ -281,7 +341,8 @@ def synchronize():
msg
=
msg
+
" líneas telefónicas."
typer
.
echo
(
msg
)
typer
.
echo
(
f
'Sincronización Finalizada en {round((datetime.now() - start_time).total_seconds(),2)} segundos.'
)
typer
.
echo
(
f
'Sincronización Finalizada en {round((datetime.now() - start_time).total_seconds(),2)} segundos.'
)
if
__name__
==
"__main__"
:
...
...
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