You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.6 KiB
72 lines
2.6 KiB
from globalState import AppState
|
|
import openpyxl
|
|
import requests
|
|
from requests.auth import HTTPBasicAuth
|
|
|
|
def download_all():
|
|
user = AppState.user
|
|
password = AppState.password
|
|
url = AppState.url
|
|
base_url = url.rstrip("/")
|
|
|
|
endpoints = {
|
|
'admins': {
|
|
'url': f"{base_url}:1443/api/admins",
|
|
'headers': ['ID', 'Reseller_id', 'Login', 'Role', 'Is_Master', 'Is_Active',
|
|
'Read_Only', 'Show_Passwords', 'Can_Reset_Password']
|
|
},
|
|
'customers': {
|
|
'url': f"{base_url}:1443/api/customers",
|
|
'headers': ["id", "external_id", "contact_id", "billing_profile_id", "status"]
|
|
},
|
|
'domains': {
|
|
'url': f"{base_url}:1443/api/domains",
|
|
'headers': ["id", "reseller_id", "domain"]
|
|
},
|
|
'peeringgroups': {
|
|
'url': f"{base_url}:1443/api/peeringgroups",
|
|
'headers': ["id", "contract_id", "name", "priority", "description"]
|
|
},
|
|
'rewriterulesets': {
|
|
'url': f"{base_url}:1443/api/rewriterulesets",
|
|
'headers': ["id", "reseller_id", "name", "description"]
|
|
},
|
|
'subscribers': {
|
|
'url': f"{base_url}:1443/api/subscribers",
|
|
'headers': ['id', "customer_id", "email", "username", "domain", "uuid", "status", "subscriber_number"]
|
|
}
|
|
}
|
|
|
|
wb = openpyxl.Workbook()
|
|
|
|
for sheet_name, info in endpoints.items():
|
|
url = info['url']
|
|
headers = info['headers']
|
|
|
|
try:
|
|
response = requests.get(url, auth=HTTPBasicAuth(user, password), verify=False)
|
|
response.raise_for_status()
|
|
data = response.json()['_embedded'].get(f'ngcp:{sheet_name}', [])
|
|
|
|
ws = wb.create_sheet(title=sheet_name)
|
|
ws.append(headers)
|
|
|
|
for item in data:
|
|
row = []
|
|
for header in headers:
|
|
if header == "subscriber_number" and sheet_name == "subscribers":
|
|
ac = item.get('primary_number', {}).get('ac', '')
|
|
cc = item.get('primary_number', {}).get('cc', '')
|
|
sn = item.get('primary_number', {}).get('sn', '')
|
|
value = f"{ac}{cc}{sn}"
|
|
else:
|
|
value = item.get(header.lower(), '')
|
|
row.append(value)
|
|
ws.append(row)
|
|
except requests.exceptions.RequestException as e:
|
|
print(f"Error al acceder a {url}: {e}")
|
|
|
|
if 'Sheet' in wb.sheetnames:
|
|
wb.remove(wb['Sheet'])
|
|
|
|
wb.save('data.xlsx') |