Kurobeats

ThreadedPOSTClient.py

Nov 5th, 2018
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | None | 0 0
  1. import requests, queue, sys
  2. from threading import Lock, Thread
  3.  
  4. class ThreadedPOSTClient:
  5.     def __init__(self, endpoint):
  6.         self.endpoint = endpoint
  7.         self.lines, self.success, self.fails = 0, 0, 0
  8.         self.queue = queue.Queue()
  9.         self._start()
  10.  
  11.     def print_status(self):
  12.         while True:
  13.             sys.stdout.write("Successful Uploads: {}    Failed Uploads: {}\r".format(str(self.success), str(self.fails)))
  14.  
  15.     def _post(self, data):
  16.         try:
  17.             status = requests.post(self.endpoint, data=data).text
  18.             if status == "success":
  19.                 self.success += 1
  20.             else:
  21.                 self.fails += 1
  22.         except Exception as e:
  23.             pass
  24.  
  25.     def _thread(self):
  26.         while True:
  27.             worker = self.queue.get()
  28.             self._post(worker)
  29.             self.queue.task_done()
  30.  
  31.     def _start(self):
  32.         for x in range(128):
  33.             t = Thread(target=self._thread, args=())
  34.             t.daemon = True
  35.             t.start()
  36.  
  37.         thread = Thread(target=self.print_status, args=(), daemon=True)
  38.         thread.start()
  39.            
  40.         with open('Xsplit Plain SHA1 Parsed-full.txt', 'r', encoding='latin-1') as inf:
  41.             try:
  42.                 line = inf.readline().split('\t')
  43.  
  44.                 while len(line) > 1:
  45.                     data = {
  46.                     'username': line[0],
  47.                     'first_name': line[1].split(' ')[0],
  48.                     'last_name': line[1].split(' ')[1:],
  49.                     'full_name': line[1],
  50.                     'email': line[2],
  51.                     'password_hash': line[3].strip(),
  52.                     'encryption_method': "SHA-1",
  53.                     'website': "xsplit",
  54.                     'date': "11-2013"
  55.                     }
  56.  
  57.                     self.queue.put(data)
  58.             except Exception as e:
  59.                 self.fails += 1
  60.             finally:
  61.                 line = inf.readline().split('\t')
  62.                 lines += 1
  63.  
  64.         self.queue.join()
  65.  
  66. ThreadedPOSTClient('http://????.com')
Advertisement
Add Comment
Please, Sign In to add comment