creación de scheduler.json para ejecución de servicio
This commit is contained in:
1 parent
839aad698d
commit
1c39f6f45f
11 files changed
+112
-400
No files matched your search
+8
-7
@@ -12,6 +12,7 @@ from datetime import datetime
|
||||
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
# ============================================================================
|
||||
class TokenExpiredError(Exception):
|
||||
pass
|
||||
|
||||
@@ -29,7 +30,7 @@ TIPO_COMPROBANTE = {
|
||||
|
||||
TIPO_DESCARGA = {"01": "PDF", "02": "XML", "03": "CDR"}
|
||||
|
||||
|
||||
# ============================================================================
|
||||
def load_token():
|
||||
if not TOKEN_FILE.exists():
|
||||
print(f"❌ No se encontró {TOKEN_FILE}")
|
||||
@@ -49,11 +50,11 @@ def load_token():
|
||||
print(f"🔑 Token válido por {int(remaining // 60)} min {int(remaining % 60)} seg")
|
||||
return token
|
||||
|
||||
|
||||
# ============================================================================
|
||||
def cpe_id(ruc, tipo, serie, numero):
|
||||
return f"{ruc}-{tipo}-{serie}-{numero}-2"
|
||||
|
||||
|
||||
# ============================================================================
|
||||
def get_headers(token):
|
||||
return {
|
||||
"Authorization": f"Bearer {token}",
|
||||
@@ -63,7 +64,7 @@ def get_headers(token):
|
||||
"Referer": "https://e-factura.sunat.gob.pe/",
|
||||
}
|
||||
|
||||
|
||||
# ============================================================================
|
||||
def consultar_cpe(token, ruc_emisor, tipo, serie, numero, descargar=True, verbose=True):
|
||||
cid = cpe_id(ruc_emisor, tipo, serie, numero)
|
||||
url = f"{API_HOST}{BASE_PATH}/{cid}"
|
||||
@@ -125,7 +126,7 @@ def consultar_cpe(token, ruc_emisor, tipo, serie, numero, descargar=True, verbos
|
||||
|
||||
return None, r.status_code
|
||||
|
||||
|
||||
# ============================================================================
|
||||
def descargar_archivo(token, cid, tipo, ts, verbose=True):
|
||||
label = TIPO_DESCARGA.get(tipo, tipo)
|
||||
url = f"{API_HOST}{BASE_PATH}/{cid}/{tipo}"
|
||||
@@ -219,7 +220,7 @@ def descargar_archivo(token, cid, tipo, ts, verbose=True):
|
||||
|
||||
return False
|
||||
|
||||
|
||||
# ============================================================================
|
||||
def main():
|
||||
print("=" * 60)
|
||||
print("🔍 CONSULTA CPE - SUNAT API")
|
||||
@@ -239,6 +240,6 @@ def main():
|
||||
|
||||
consultar_cpe(token, args.ruc, args.tipo, args.serie, args.numero, descargar=not args.no_download)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user