pjmakey2

GetHistoricInvoicePersonaldotCom

Sep 19th, 2021 (edited)
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. import requests
  2. import datetime
  3. import os
  4. token = 'bazofia'
  5. for a in range(1, 5):
  6.     ri = requests.get('https://www.personal.com.py/mimundo/rest/v1/grupos-facturacion/facturas-digitales?token={}&ordenadoPor=numeroFactura;desc&registros=10&inicio={}&_=1632061768737'.format(token, a))
  7.     invoices = map(lambda x: (x.get('numeroFactura'), x.get('fechaEmision')), ri.json().get('lista'))
  8.     for number, date in invoices:
  9.         dateobj = datetime.datetime.fromtimestamp(int(str(date)[0:10]))
  10.         datestr = dateobj.strftime('%Y%m')
  11.         try:
  12.             os.mkdir('/home/peter/Documents/Contabilidad/PJL/{}'.format(datestr))
  13.         except:
  14.             pass
  15.         url = "https://www.personal.com.py/mimundo/rest/v1/grupos-facturacion/facturas-digitales/FT/{}/exportar?token={}".format(number, token)
  16.         riin = requests.get(url)
  17.         with open('/home/peter/Documents/Contabilidad/PJL/{}/personal_invoice_{}.pdf'.format(datestr, number), 'w') as ff:
  18.             ff.write(riin.content)
Add Comment
Please, Sign In to add comment