<jupyter_start><jupyter_text>Через сайт<jupyter_code>import numpy as np
import requests
from bs4 import BeautifulSoup
import urllib
import numpy as np
from imutils import contours
import matplotlib.pyplot as plt
from functools import cmp_to_key
import cv2 as cv


def scaleImg(image, scale: float):
    width, height = image.shape[1], image.shape[0]
    return cv.resize(image, (int(width * scale), int(height * scale)))


def clipImg(image, max_size, filter=cv.INTER_CUBIC):
    width, height = image.shape[1], image.shape[0]
    max_dim = max(width, height)
    ratio = float(max_size) / max_dim
    return cv.resize(image, (int(width*ratio), int(height*ratio)), interpolation=filter)
time_region_width = 40

def math_time(image):
    img = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
    # where to find match time
    template = cv.imread('win.jpg', 0)
    # seems to work 'OK'
    method = eval('cv.TM_CCOEFF_NORMED')
    top_left, bottom_right, _ = find_region(method, img, template)
    time_region = img[top_left[1]:bottom_right[1], bottom_right[0]:bottom_right[0] + time_region_width]
    # numeric templates
    numbers = []
    for i in range(10):
        numbers.append(cv.imread('' + str(i) + '.jpg', 0))
    colon_template = cv.imread('dev.jpg', 0)
    registered_numbers = []
    for idx, number in enumerate(numbers):
        boxes = find_boxes(method, time_region, number)
        for box in boxes:
            registered_numbers.append(Number_container(idx, box))
    boxes = find_boxes(method, time_region, colon_template)
    for box in boxes:
        registered_numbers.append(Number_container(-1, box, True))
    registered_numbers = sorted(registered_numbers, key=cmp_to_key(box_compare))
    time = ''
    for num in registered_numbers:
        time += ':' if num.isColon else str(num.number)
    return time, time_region, registered_numbers

def match_time_id(id, game_num=1):
    headers = {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', 'x-requested-with': 'XMLHttpRequest'}
    raw_data = 'game=&rid=matches&ajax=block_video&data%5Bid%5D=' + str(id) + '&data%5Bnum%5D=' + str(game_num)
    page = requests.post("https://game-tournaments.com/", headers=headers, data=raw_data)
    soup = BeautifulSoup(page.content, "html.parser")
    job_elements = soup.find_all("a", class_="g-rezults")
    address = job_elements[0]["href"]
    image_url = 'https://en.game-tournaments.com' + address
    page = requests.get(image_url) 
    image = np.asarray(bytearray(page.content), dtype="uint8")
    image = cv.imdecode(image, cv.IMREAD_COLOR)
    time, region, boxes = math_time(image)
    image = cv.resize(image, (1524, 520))
    return time, region, boxes, image

def match_time_number(number, game=1):
    page = np.int(number / 20) + 1
    idx = number % 20
    print(page)
    page_url = "https://game-tournaments.com/dota-2/matches"
    headers = {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', 'x-requested-with': 'XMLHttpRequest'}
    raw_data = 'game=dota-2&rid=matches&ajax=block_matches_past&data%5Bs%5D=' + str(
        page) + '&data%5Btype%5D=gg&data%5Bscore%5D=0'
    page = requests.post(page_url, headers=headers, data=raw_data)
    soup = BeautifulSoup(page.content, "html.parser")
    job_elements = soup.find_all("span", class_='mbutton tresult')
    id = job_elements[idx]["data-mid"]
    print(id)

    return match_time_id(id, game)
id = 25
time, region, boxes, img = match_time_number(id)
canvas = cv.cvtColor(region, cv.COLOR_GRAY2BGR)
for box in boxes:
    cv.rectangle(canvas, box.box[0], box.box[1], (200, 20, 20))
canvas = clipImg(canvas, 500, cv.INTER_NEAREST)
print(time)
cv.imshow('time', canvas)
cv.imshow('img', img)
cv.waitKey(0)
cv.destroyAllWindows()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13997879109225875, 'fraction_numerical': 0.017497348886532343, 'mean_word_length': 4.382310984308131, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 3, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '60695', 'license': 'MIT', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1325, 'n_words': 276, 'path': 'task14.ipynb', 'repo_name': 'SkivHisink/OpenCV_Practice', 'size': '3772'}