# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

# +
from PIL import Image, ImageOps

print('confirm')
ans = input()

block_size = 400

num, i, j = 0, 0, 0  # y, x

size_y = 5  # y
size_x = 5  # x

result = Image.new('RGB', (block_size * (size_x + 1), block_size * (size_y + 1)), (250, 250, 250))

for page_num in range(1, 65):
    for img_num in range(48):
        img = Image.open(f'res/{page_num}/{img_num}_th.png')  # Read the two images

        img = img.resize((block_size, block_size))  # Resize image

        result.paste(img, (j * block_size, i * block_size))

        if j < size_x:
            j += 1
        else:
            i += 1
            j = 0
            if i > size_y:
                inverted_image = ImageOps.invert(result)
                inverted_image.save(f"plates/{num}.png", "PNG")
                num += 1
                i, j = 0, 0
                
                result = Image.new('RGB', (block_size * (size_x + 1), block_size * (size_y + 1)), (250, 250, 250))


# result.save(f"plates/{num}.png", "PNG")

# +
from selenium import webdriver

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.support.ui import Select

from time import sleep

import random
import socket
import struct


def parse_paper():
    chromeOptions = webdriver.ChromeOptions()
    prefs = {"download.default_directory" : f"/home/pavtiger/Docs/SymbolsAnalyse-v2/svg/"}  # Download path
    chromeOptions.add_experimental_option("prefs", prefs)

    webdriver.DesiredCapabilities.CHROME['acceptSslCerts']=True

    driver = webdriver.Chrome('./chromedriver', options=chromeOptions)
    
    for number in range(85):
        if os.path.isfile(f"/home/pavtiger/Docs/SymbolsAnalyse-v2/svg/{number}.svg"):
            continue

        driver.get("https://www.autotracer.org")  # Access website

        driver.find_element_by_id("fileupfield").send_keys(os.getcwd() + f'/plates/{number}.png')  # Upload path
        sleep(3)
        
        try:
            # Open advanced menu
            content = driver.find_element_by_class_name('toggle-advanced-options-button')
            content.click()
            sleep(3)
        except:
            pass

        # Chose number of colors
        select = Select(driver.find_element_by_id('selectColorCount'))
        select.select_by_visible_text('2')

        select = Select(driver.find_element_by_id('selectSmooth'))
        select.select_by_visible_text('Smoother')
        sleep(3)

        check = driver.find_element_by_id('checkboxIgnoreWhiteBackground')
        check.click()

        driver.find_element_by_id("fbut").click()  # Generate result
        sleep(2)

        try:
            error = driver.find_elements_by_xpath("//*[contains(text(), 'Your IP Address did exhaust the maximum numbers')]")
            print(error.get_attribute('innerHTML'))
            print('banned')
        except:
            pass

        while True:
            try:
                driver.find_element_by_id("result").find_element_by_id("result-svg-preview")  # Check if exists

                result = driver.find_element_by_id("result")
                links = result.find_elements_by_xpath("//a[@href]")

                for l in links:
                    if "FW" in l.get_attribute("href"):
                        print(l.get_attribute("href"))
                        l.click()
                break
            except:
                continue

        sleep(30)
        
    driver.close()


# +
import os
    
parse_paper()
    
# if os.path.exists(f'res/{str(page)}_'):
#     parse_paper(str(page) + '_')
# -



StarcoderdataJupyterScriptsDedupFiltered