Commit 75b0991f by Javier

Actualizacion en funcion get_cdr, para obtener datos de ddi en magnus que tengan el +34

parent 00b45e98
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "API", "name": "API",
"type": "python", "type": "python",
......
...@@ -295,13 +295,14 @@ def add_cdrs() -> 'list[dict]': ...@@ -295,13 +295,14 @@ def add_cdrs() -> 'list[dict]':
# Obtención de Parámetros # Obtención de Parámetros
sip_accounts = list(get_accounts(only_postpaid=True)) sip_accounts = list(get_accounts(only_postpaid=True))
last_update = get_last_updated_cdr(*[sip.callerid for sip in sip_accounts]) # Filtrar cuentas válidas (ni None ni sin callerid)
valid_accounts = [acc for acc in sip_accounts if acc and acc.callerid]
last_update = get_last_updated_cdr(*[acc.callerid for acc in valid_accounts])
cdrs = [] cdrs = []
# Carga en Memoria de CDRs # Carga en Memoria de CDRs
for account in sip_accounts: for account in valid_accounts:
since = last_update[account.callerid] if account.callerid in last_update.keys( since = last_update.get(account.callerid) # Más seguro que usar in + []
) else None
cdrs.extend(get_cdrs(phone_number=account.callerid, since=since)) cdrs.extend(get_cdrs(phone_number=account.callerid, since=since))
# Almacenamiento en Servidor SQL # Almacenamiento en Servidor SQL
......
...@@ -391,29 +391,29 @@ def get_cdrs(phone_number: str, since: datetime = None, upto: datetime = None) - ...@@ -391,29 +391,29 @@ def get_cdrs(phone_number: str, since: datetime = None, upto: datetime = None) -
cursor.execute( cursor.execute(
'SELECT callerid, calledstation dest, destination as description, starttime date, sessiontime duration, ROUND(sessionbill,3) \ 'SELECT callerid, calledstation dest, destination as description, starttime date, sessiontime duration, ROUND(sessionbill,3) \
price, ROUND(buycost,3) cost FROM mbilling.pkg_cdr c INNER JOIN mbilling.pkg_prefix as p ON p.id = id_prefix \ price, ROUND(buycost,3) cost FROM mbilling.pkg_cdr c INNER JOIN mbilling.pkg_prefix as p ON p.id = id_prefix \
WHERE callerid = ? AND starttime > ? AND starttime <= ?', WHERE callerid LIKE ? AND starttime > ? AND starttime <= ?',
(phone_number, since, upto) ('%' + phone_number + '%', since, upto)
) )
elif since: elif since:
cursor.execute( cursor.execute(
'SELECT callerid, calledstation dest, destination as description, starttime date, sessiontime duration, ROUND(sessionbill,3) \ 'SELECT callerid, calledstation dest, destination as description, starttime date, sessiontime duration, ROUND(sessionbill,3) \
price, ROUND(buycost,3) cost FROM mbilling.pkg_cdr INNER JOIN mbilling.pkg_prefix as p ON p.id = id_prefix\ price, ROUND(buycost,3) cost FROM mbilling.pkg_cdr INNER JOIN mbilling.pkg_prefix as p ON p.id = id_prefix\
WHERE callerid = ? AND starttime > ?', WHERE callerid LIKE ? AND starttime > ?',
(phone_number, since) ('%' + phone_number + '%', since)
) )
elif upto: elif upto:
cursor.execute( cursor.execute(
'SELECT callerid, calledstation dest, destination as description, starttime date, sessiontime duration, ROUND(sessionbill,3) \ 'SELECT callerid, calledstation dest, destination as description, starttime date, sessiontime duration, ROUND(sessionbill,3) \
price, ROUND(buycost,3) cost FROM mbilling.pkg_cdr INNER JOIN mbilling.pkg_prefix as p ON p.id = id_prefix \ price, ROUND(buycost,3) cost FROM mbilling.pkg_cdr INNER JOIN mbilling.pkg_prefix as p ON p.id = id_prefix \
WHERE callerid = ? AND starttime <= ?', WHERE callerid LIKE ? AND starttime <= ?',
(phone_number, upto) ('%' + phone_number + '%', upto)
) )
else: else:
cursor.execute( cursor.execute(
'SELECT callerid, calledstation dest, destination as description, starttime date, sessiontime duration, ROUND(sessionbill,3) \ 'SELECT callerid, calledstation dest, destination as description, starttime date, sessiontime duration, ROUND(sessionbill,3) \
price, ROUND(buycost,3) cost FROM mbilling.pkg_cdr INNER JOIN mbilling.pkg_prefix as p ON p.id = id_prefix \ price, ROUND(buycost,3) cost FROM mbilling.pkg_cdr INNER JOIN mbilling.pkg_prefix as p ON p.id = id_prefix \
WHERE callerid = ?', WHERE callerid LIKE ?',
(phone_number,) ('%' + phone_number + '%',)
) )
data = cursor.fetchall() data = cursor.fetchall()
...@@ -422,6 +422,13 @@ def get_cdrs(phone_number: str, since: datetime = None, upto: datetime = None) - ...@@ -422,6 +422,13 @@ def get_cdrs(phone_number: str, since: datetime = None, upto: datetime = None) -
headers = ['callerid', 'destination', 'description', headers = ['callerid', 'destination', 'description',
'timestamp', 'duration', 'price', 'cost'] 'timestamp', 'duration', 'price', 'cost']
for line in data: for line in data:
# Modificamos el callerid si empieza con '+34'
if line[0].startswith('+34'):
line = list(line) # Convertimos la tupla en lista para modificar elementos
line[0] = line[0][3:] # Quitamos el '+34' (3 caracteres)
line = tuple(line) # Volvemos a convertirlo en tupla
# Añadimos la línea al resultado final
cdr.append(dict(zip(headers, line))) cdr.append(dict(zip(headers, line)))
return cdr return cdr
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment