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
c651b8d1
Commit
c651b8d1
authored
May 16, 2022
by
Javier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Nueva Versión
parent
d64a0615
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
30 deletions
+95
-30
cli.py
cli.py
+95
-30
db.py
ptv/db.py
+0
-0
No files found.
cli.py
View file @
c651b8d1
from
decimal
import
Decimal
from
typing
import
Tuple
import
typer
from
mbilling.functions
import
MagnusCommandError
,
SipAccount
,
active_users
,
fully_ported_users
,
get_sip_accounts
,
get_cdrs
,
add_balance
,
get_user
,
get_plan_consumption
from
mbilling.functions
import
MagnusCommandError
,
SipAccount
,
active_users
,
fully_ported_users
from
mbilling.functions
import
get_sip_accounts
,
get_cdrs
,
add_balance
,
get_user
,
get_plan_consumption
from
mbilling.functions
import
get_accounts
import
time
import
pyodbc
import
os
...
...
@@ -43,34 +45,31 @@ def update_sip_accounts() -> 'Tuple[int,int]':
with
pyodbc
.
connect
(
SQL_SERVER_CNX_STRING
)
as
cnx
:
with
cnx
.
cursor
()
as
cursor
:
with
typer
.
progressbar
(
get_sip_accounts
(),
label
=
"Sincronizando Cuentas"
)
as
sips
:
for
sip
in
sips
:
# Llamadas Salientes por Nueva Plataforma
if
sip
.
credit
==
0.0
:
with
typer
.
progressbar
(
get_accounts
(
only_fullyported
=
True
),
label
=
"Sincronizando Cuentas"
)
as
accounts
:
for
account
in
accounts
:
cursor
.
execute
(
"SELECT NuevaPlataforma FROM [bdd_wifi].[dbo].[TB_ServicioFijo]
\
WHERE DDI IN (?,?) AND NuevaPlataforma=1"
,
(
sip
.
callerid
,
sip
.
account
)
"UPDATE [bdd_wifi].[dbo].[TB_ServicioFijo]
\
SET SaldoActual=?, Activo=?, TarifaPlana=?, Pospago=?, IdTarifa=?,
\
UsuarioEXT=?, ClaveEXT=?, NuevaPlataforma=1 WHERE DDI=? AND FechaBaja is NULL"
,
(
account
.
credit
,
account
.
active
,
account
.
plan
==
4
,
account
.
postpaid
,
account
.
plan
,
account
.
account
,
account
.
secret
,
account
.
account
)
)
nueva_plataforma
=
1
if
cursor
.
fetchone
()
else
0
else
:
nueva_plataforma
=
1
cursor
.
execute
(
"UPDATE [bdd_wifi].[dbo].[TB_ServicioFijo]
\
SET SaldoActual=?, Activo=?, TarifaPlana=?, Pospago=?, IdTarifa=?, UsuarioEXT=?,
\
ClaveEXT=?, NuevaPlataforma=? WHERE DDI=? AND FechaBaja is NULL"
,
sip_accounts_updated
+=
1
(
sip
.
credit
,
sip
.
active
,
sip
.
offer
!=
0
,
sip
.
postpaid
,
sip
.
plan
,
sip
.
callerid
if
sip
.
account
==
sip
.
callerid
else
None
,
sip
.
secret
if
sip
.
account
==
sip
.
callerid
else
None
,
nueva_plataforma
,
sip
.
callerid
)
for
did
in
account
.
dids
:
if
did
!=
account
.
account
:
cursor
.
execute
(
'UPDATE [bdd_wifi].[dbo].[TB_ServicioFijo] SET CuentaA2Billing=NULL,
\
UsuarioEXT=NULL, ClaveEXT=NULL, Activo=?, TarifaPlana=0, Pospago=0,
\
IdTarifa=0, SaldoActual=0.0 WHERE DDI=?'
,
(
account
.
active
,
did
)
)
if
sip
.
account
==
sip
.
callerid
:
sip_accounts_updated
=
sip_accounts_updated
+
1
else
:
did_accounts_updated
=
did_accounts_updated
+
1
did_accounts_updated
+=
1
cnx
.
commit
()
return
sip_accounts_updated
,
did_accounts_updated
...
...
@@ -82,9 +81,11 @@ def activate_new_plataform():
with
pyodbc
.
connect
(
SQL_SERVER_CNX_STRING
)
as
cnx
:
with
cnx
.
cursor
()
as
cursor
:
for
sip
,
account
in
fully_ported_users
():
user
=
get_user
(
sip
)
account
=
account
if
sip
==
account
else
None
cursor
.
execute
(
'UPDATE [bdd_wifi].[dbo].[TB_ServicioFijo] SET NuevaPlataforma=1 WHERE DDI=?'
,
'UPDATE [bdd_wifi].[dbo].[TB_ServicioFijo] SET NuevaPlataforma=1 WHERE DDI=?
\
AND FechaBaja is not NULL'
,
(
sip
,)
)
...
...
@@ -105,6 +106,7 @@ def perform_migration():
for
ddi
in
migration_targets
.
fetchall
():
ddi
=
ddi
[
0
]
# Obtención Cuenta MagnusBilling
user
=
get_user
(
ddi
)
a2billing_user
=
a2billing
.
account_data
(
ddi
)
...
...
@@ -121,11 +123,9 @@ def perform_migration():
cursor
.
execute
(
'UPDATE [bdd_wifi].[dbo].[TB_Recargas] SET Cuenta=? WHERE Cuenta=?'
,
(
user
[
'username'
],
a2billing_user
[
'account'
])
(
user
[
'username'
],
a2billing_user
[
'account'
]
if
a2billing_user
else
None
)
)
print
(
user
[
'username'
])
else
:
cursor
.
execute
(
'UPDATE [bdd_wifi].[dbo].[TB_ServicioFijo] SET CuentaA2Billing=NULL,
\
...
...
@@ -258,6 +258,7 @@ def update_plan_consumption():
with
pyodbc
.
connect
(
SQL_SERVER_CNX_STRING
)
as
cnx
:
with
cnx
.
cursor
()
as
cursor
:
for
account
,
consumption
in
get_plan_consumption
()
.
items
():
cursor
.
execute
(
'UPDATE [bdd_wifi].[dbo].[TB_ServicioFijo] SET ConsumoTarifa=?, LimiteTarifa=? WHERE
\
UsuarioEXT=?'
,
...
...
@@ -318,7 +319,72 @@ def process_refills() -> Tuple[int, float]:
cnx
.
commit
()
return
total_refills
,
amount
# Definición de Comandos
@app.command
()
def
restore
():
# Restaura las Cuentas Originales
with
pyodbc
.
connect
(
SQL_SERVER_CNX_STRING
)
as
cnx
:
with
cnx
.
cursor
()
as
cursor
:
cursor
.
execute
(
'SELECT [UsuarioEXT] FROM [bdd_wifi].[dbo].[TB_ServicioFijo]
\
WHERE NuevaPlataforma=1'
)
for
username
in
cursor
.
fetchall
():
cli
=
username
[
0
]
user
=
get_user
(
cli
)
a2billing_account
=
a2billing
.
account_data
(
cli
)
if
user
and
a2billing_account
:
cursor
.
execute
(
'UPDATE [bdd_wifi].[dbo].[TB_Recargas] SET Cuenta=? WHERE Cuenta=?'
,
(
a2billing_account
[
'account'
],
user
[
'username'
])
)
cursor
.
execute
(
'UPDATE [bdd_wifi].[dbo].[TB_ServicioFijo] SET
\
UsuarioExt=?, ClaveEXT=?, NuevaPlataforma=?, SaldoActual=?
\
WHERE DDI=?'
,
(
a2billing_account
[
'account'
],
a2billing_account
[
'secret'
],
0
,
a2billing_account
[
'credit'
],
cli
)
)
cursor
.
commit
()
# Realiza las Migraciones a la Nueva Plataforma
activate_new_plataform
()
perform_migration
()
# Restaura los Valores de Cuentas que ya no están en Nueva Plataforma
with
pyodbc
.
connect
(
SQL_SERVER_CNX_STRING
)
as
cnx
:
with
cnx
.
cursor
()
as
cursor
:
cursor
.
execute
(
'SELECT DDI FROM[bdd_wifi].[dbo].[TB_ServicioFijo]
\
WHERE NuevaPlataforma=0 AND UsuarioEXT != CuentaA2Billing'
)
for
username
in
cursor
.
fetchall
():
cli
=
username
[
0
]
user
=
get_user
(
cli
)
a2billing_account
=
a2billing
.
account_data
(
cli
)
if
user
and
a2billing_account
:
cursor
.
execute
(
'UPDATE [bdd_wifi].[dbo].[TB_Recargas] SET Cuenta=? WHERE Cuenta=?'
,
(
a2billing_account
[
'account'
],
user
[
'username'
])
)
cursor
.
execute
(
'UPDATE [bdd_wifi].[dbo].[TB_ServicioFijo] SET
\
UsuarioExt=?, ClaveEXT=?, NuevaPlataforma=?, SaldoActual=?
\
WHERE DDI=?'
,
(
a2billing_account
[
'account'
],
a2billing_account
[
'secret'
],
0
,
a2billing_account
[
'credit'
],
cli
)
)
cursor
.
commit
()
@app.command
()
...
...
@@ -396,8 +462,7 @@ def synchronize():
@app.command
()
def
test
():
print
(
a2billing
.
account_data
(
'956373434'
))
update_sip_accounts
()
if
__name__
==
"__main__"
:
app
()
ptv/db.py
0 → 100644
View file @
c651b8d1
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