Suppenbiatch

CSGO AUTO ACCPET V1.1.5

Apr 16th, 2020
1,388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 23.50 KB | None | 0 0
  1. import configparser
  2. import operator
  3. import os
  4. import sys
  5. import time
  6. import webbrowser
  7. from datetime import datetime, timedelta
  8.  
  9. import pushbullet
  10. import pyperclip
  11. import pytesseract
  12. import requests
  13. import win32api
  14. import win32con
  15. import win32gui
  16. from PIL import ImageGrab, Image
  17. from playsound import playsound
  18.  
  19.  
  20. def Avg(lst: list):
  21.     return sum(lst) / len(lst)
  22.  
  23.  
  24. # noinspection PyShadowingNames
  25. def enum_cb(hwnd, results):
  26.     winlist.append((hwnd, win32gui.GetWindowText(hwnd)))
  27.  
  28.  
  29. # noinspection PyShadowingNames
  30. def write(message, add_time: bool = True, push: int = 0, push_now: bool = False, output: bool = True, overwrite: tuple = (False, '0')):
  31.     if output:
  32.         message = str(message)
  33.         if add_time:
  34.             message = datetime.now().strftime('%H:%M:%S') + ': ' + message
  35.         log_file = open(log_path + '\\log.txt', 'rb')
  36.         lines = log_file.readlines()
  37.         log_file.close()
  38.         last_key = lines[0].split(b'\\')[0]
  39.         last_line = lines[-1].split(b'\r')[-1]
  40.         if overwrite[0]:
  41.             ending = ''
  42.             if last_key == overwrite[1].encode():
  43.                 message = '\r' + message
  44.             else:
  45.                 if last_line != b'\n':
  46.                     message = '\n' + message
  47.         else:
  48.             ending = '\n'
  49.             if last_line != b'\n':
  50.                 message = '\n' + message
  51.  
  52.         log_file = open(log_path + '\\log.txt', 'w')
  53.         log_file.write(overwrite[1] + '\\' + message + ending)
  54.         log_file.close()
  55.         print(message, end=ending)
  56.  
  57.     if push >= 3:
  58.         global note
  59.         if message:
  60.             note = note + str(message) + '\n'
  61.         if push_now:
  62.             device.push_note('CSGO AUTO ACCEPT', note)
  63.             note = ''
  64.  
  65.  
  66. # noinspection PyShadowingNames
  67. def click(x: int, y: int):
  68.     win32api.SetCursorPos((x, y))
  69.     win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
  70.     win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
  71.  
  72.  
  73. # noinspection PyShadowingNames
  74. def relate_list(l_org, l1, l2=None, relate: operator = operator.le):
  75.     if not l_org:
  76.         return False
  77.     truth_list, l3 = [], []
  78.     for i, val in enumerate(l1, start=0):
  79.         l3.append(relate(l_org[i], val))
  80.     truth_list.append(all(l3))
  81.     l3 = []
  82.     if l2:
  83.         for i, val in enumerate(l2, start=len(l1)):
  84.             l3.append(relate(l_org[i], val))
  85.         truth_list.append(all(l3))
  86.     return any(truth_list)
  87.  
  88.  
  89. # noinspection PyShadowingNames
  90. def color_average(image: Image, compare_list: list):
  91.     average = []
  92.     r, g, b = [], [], []
  93.     data = image.getdata()
  94.     for i in data:
  95.         r.append(i[0])
  96.         g.append(i[1])
  97.         b.append(i[2])
  98.  
  99.     rgb = [Avg(r), Avg(g), Avg(b)] * int(len(compare_list) / 3)
  100.     for i, val in enumerate(compare_list, start=0):
  101.         average.append(val - rgb[i])
  102.     average = list(map(abs, average))
  103.  
  104.     return average
  105.  
  106.  
  107. # noinspection PyShadowingNames
  108. def getScreenShot(window_id: int, area: tuple = (0, 0, 0, 0)):
  109.     area = list(area)
  110.     win32gui.ShowWindow(window_id, win32con.SW_MAXIMIZE)
  111.     scaled_area = [screen_width / 2560, screen_height / 1440]
  112.     scaled_area = 2 * scaled_area
  113.     for i, _ in enumerate(area[-2:], start=len(area) - 2):
  114.         area[i] += 1
  115.     for i, val in enumerate(area, start=0):
  116.         scaled_area[i] = scaled_area[i] * val
  117.     scaled_area = list(map(int, scaled_area))
  118.     image = ImageGrab.grab(scaled_area)
  119.     return image
  120.  
  121.  
  122. # noinspection PyShadowingNames
  123. def getAccountsFromCfg():
  124.     steam_ids = ''
  125.     for i in config.sections():
  126.         if i.startswith('Account'):
  127.             steam_id = config.get(i, 'Steam ID')
  128.             auth_code = config.get(i, 'Authentication Code')
  129.             match_token = config.get(i, 'Match Token')
  130.             steam_ids += steam_id + ','
  131.             accounts.append({'steam_id': steam_id, 'auth_code': auth_code, 'match_token': match_token})
  132.  
  133.     steam_ids = steam_ids.lstrip(',').rstrip(',')
  134.     profiles = requests.get('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' + cfg['steam_api_key'] + '&steamids=' + steam_ids).json()['response']['players']
  135.     for i in profiles:
  136.         for n in accounts:
  137.             if n['steam_id'] == i['steamid']:
  138.                 n['name'] = i['personaname']
  139.                 break
  140.  
  141.  
  142. # noinspection PyShadowingNames
  143. def getOldSharecodes(num: int = -1):
  144.     try:
  145.         last_game = open(log_path+'last_game_' + accounts[current_account]['steam_id'] + '.txt', 'r')
  146.         games = last_game.readlines()
  147.         last_game.close()
  148.     except FileNotFoundError:
  149.         last_game = open(log_path+'last_game_' + accounts[current_account]['steam_id'] + '.txt', 'w')
  150.         last_game.write(accounts[current_account]['match_token'] + '\n')
  151.         games = [accounts[current_account]['match_token']]
  152.         last_game.close()
  153.     last_game = open(log_path+'last_game_' + accounts[current_account]['steam_id'] + '.txt', 'w')
  154.     games = games[-200:]
  155.     for i, val in enumerate(games):
  156.         games[i] = 'CSGO' + val.strip('\n').split('CSGO')[1]
  157.         last_game.write(games[i] + '\n')
  158.     last_game.close()
  159.     return games[num:]
  160.  
  161.  
  162. # noinspection PyShadowingNames
  163. def getNewCSGOMatches(game_id: str):
  164.     sharecodes = []
  165.     next_code = game_id
  166.     last_game = open(log_path+'last_game_' + accounts[current_account]['steam_id'] + '.txt', 'a')
  167.     while next_code != 'n/a':
  168.         steam_url = 'https://api.steampowered.com/ICSGOPlayers_730/GetNextMatchSharingCode/v1?key=' + cfg['steam_api_key'] + '&steamid=' + accounts[current_account]['steam_id'] + '&steamidkey=' + accounts[current_account][
  169.             'auth_code'] + '&knowncode=' + game_id
  170.         try:
  171.             next_code = (requests.get(steam_url).json()['result']['nextcode'])
  172.         except KeyError:
  173.             write('WRONG Match Token, Authentication Code or Steam ID ')
  174.             return [game_id]
  175.  
  176.         if next_code:
  177.             if next_code != 'n/a':
  178.                 sharecodes.append(next_code)
  179.                 game_id = next_code
  180.                 last_game.write(next_code + '\n')
  181.     if sharecodes:
  182.         return sharecodes
  183.     else:
  184.         return [game_id]
  185.  
  186.  
  187. # noinspection PyShadowingNames
  188. def UpdateCSGOstats(sharecodes: list, num_completed: int = 1):
  189.     completed_games, not_completed_games, = [], []
  190.     for val in sharecodes:
  191.         response = requests.post('https://csgostats.gg/match/upload/ajax', data={'sharecode': val, 'index': '1'})
  192.         if response.json()['status'] == 'complete':
  193.             completed_games.append(response.json())
  194.         else:
  195.             not_completed_games.append(response.json())
  196.  
  197.     # TEST GAME:
  198.  
  199.     queued_games = [game['data']['queue_pos'] for game in not_completed_games if game['status'] != 'error']
  200.     global retrying_games
  201.     retrying_games = []
  202.  
  203.     if queued_games:
  204.         if queued_games[0] < cfg['max_queue_position']:
  205.             global time_table
  206.             retrying_games = [game['data']['sharecode'] for game in not_completed_games]
  207.             time_table['error_check_time'] = time.time()
  208.         temp_string = ''
  209.         for i, val in enumerate(queued_games):
  210.             temp_string += '#' + str(i + 1) + ': in Queue #' + str(val) + '. - '
  211.         temp_string = temp_string.rstrip(' - ')
  212.         write(temp_string, add_time=False, overwrite=(True, '5'))
  213.  
  214.     if len(not_completed_games) - len(queued_games) > 0:
  215.         write('An error occurred in %s game[s].' % (len(not_completed_games) - len(queued_games)), add_time=False)
  216.         retrying_games.append([game['data']['sharecode'] for game in not_completed_games if game['status'] == 'error'])
  217.  
  218.     if completed_games:
  219.         for i in completed_games[num_completed * - 1:]:
  220.             sharecode = i['data']['sharecode']
  221.             game_url = i['data']['url']
  222.             info = ' '.join(i['data']['msg'].replace('-', '').replace('<br />', '. ').split('<')[0].rstrip(' ').split())
  223.             write('Sharecode: %s' % sharecode, add_time=False, push=push_urgency)
  224.             write('URL: %s' % game_url, add_time=False, push=push_urgency)
  225.             write('Status: %s.' % info, add_time=False, push=push_urgency)
  226.             pyperclip.copy(game_url)
  227.         write(None, add_time=False, push=push_urgency, push_now=True, output=False)
  228.  
  229.  
  230. # noinspection PyShadowingNames
  231. def Image_to_Text(image: Image, size: tuple, white_threshold: list, arg: str = ''):
  232.     image_data = image.getdata()
  233.     pixel_map, image_text = [], ''
  234.     for y in range(size[1]):
  235.         for x in range(size[0]):
  236.             if relate_list(image_data[y * size[0] + x], white_threshold, relate=operator.ge):
  237.                 pixel_map.append((0, 0, 0))
  238.             else:
  239.                 pixel_map.append((255, 255, 255))
  240.     temp_image = Image.new('RGB', (size[0], size[1]))
  241.     temp_image.putdata(pixel_map)
  242.     try:
  243.         image_text = pytesseract.image_to_string(temp_image, timeout=0.3, config=arg)
  244.     except RuntimeError as timeout_error:
  245.         pass
  246.     if image_text:
  247.         image_text = ' '.join(image_text.replace(': ', ':').split())
  248.         global truth_table
  249.         if truth_table['debugging']:
  250.             image.save(str(cfg['debug_path']) + '\\' + datetime.now().strftime('%H-%M-%S') + '_' + image_text.replace(':', '-') + '.png', format='PNG')
  251.             temp_image.save(str(cfg['debug_path']) + '\\' + datetime.now().strftime('%H-%M-%S') + '_' + image_text.replace(':', '-') + '_temp.png', format='PNG')
  252.         return image_text
  253.     else:
  254.         return False
  255.  
  256.  
  257. def getCfgData():
  258.     try:
  259.         get_cfg = {'activate_script': int(config.get('HotKeys', 'Activate Script'), 16), 'activate_push_notification': int(config.get('HotKeys', 'Activate Push Notification'), 16),
  260.                    'info_newest_match': int(config.get('HotKeys', 'Get Info on newest Match'), 16), 'info_multiple_matches': int(config.get('HotKeys', 'Get Info on multiple Matches'), 16),
  261.                    'open_live_tab': int(config.get('HotKeys', 'Live Tab Key'), 16), 'switch_accounts': int(config.get('HotKeys', 'Switch accounts for csgostats.gg'), 16),
  262.                    'end_script': int(config.get('HotKeys', 'End Script'), 16),
  263.                    'screenshot_interval': config.getint('Screenshot', 'Interval'), 'debug_path': config.get('Screenshot', 'Debug Path'), 'steam_api_key': config.get('csgostats.gg', 'API Key'),
  264.                    'last_x_matches': config.getint('csgostats.gg', 'Number of Requests'),
  265.                    'completed_matches': config.getint('csgostats.gg', 'Completed Matches'), 'max_queue_position': config.getint('csgostats.gg', 'Auto-Retrying for queue position below'),
  266.                    'auto_retry_interval': config.getint('csgostats.gg', 'Auto-Retrying-Interval'), 'pushbullet_device_name': config.get('Pushbullet', 'Device Name'), 'pushbullet_api_key': config.get('Pushbullet', 'API Key'),
  267.                    'tesseract_path': config.get('Warmup', 'Tesseract Path'), 'warmup_test_interval': config.getint('Warmup', 'Test Interval'), 'warmup_push_interval': config.get('Warmup', 'Push Interval'),
  268.                    'warmup_no_text_limit': config.getint('Warmup', 'No Text Limit')}
  269.         return get_cfg
  270.         # 'imgur_id': config.get('Imgur', 'Client ID'), 'imgur_secret': config.get('Imgur', 'Client Secret'), 'stop_warmup_ocr': int(config.get('HotKeys', 'Stop Warmup OCR'), 16),
  271.     except (configparser.NoOptionError, configparser.NoSectionError, ValueError):
  272.         write('ERROR IN CONFIG')
  273.         exit('CHECK FOR NEW CONFIG')
  274.  
  275.  
  276. # LOG FILE
  277. log_path = os.getenv('APPDATA') + '\\CSGO AUTO ACCEPT\\'
  278. try:
  279.     os.mkdir(log_path)
  280. except FileExistsError:
  281.     pass
  282. log_file = open(log_path+'\\log.txt', 'w')
  283. log_file.write('0\\\n')
  284. log_file.close()
  285.  
  286. # CONFIG HANDLING
  287. config = configparser.ConfigParser()
  288. config.read('config.ini')
  289. cfg = getCfgData()
  290. device = 0
  291.  
  292. # ACCOUNT HANDLING, GETTING ACCOUNT NAME
  293. accounts, current_account = [], 0
  294. getAccountsFromCfg()
  295.  
  296. # INITIALIZATION FOR getScreenShot
  297. screen_width, screen_height = win32api.GetSystemMetrics(0), win32api.GetSystemMetrics(1)
  298. toplist, winlist = [], []
  299. hwnd = 0
  300.  
  301. # BOOLEAN, TIME INITIALIZATION
  302. truth_table = {'test_for_live_game': False, 'test_for_success': False, 'test_for_warmup': False, 'first_ocr': True, 'testing': False, 'debugging': False, 'first_push': True}
  303. time_table = {'screenshot_time': time.time(), 'error_check_time': time.time(), 'warmup_test_timer': time.time(), 'time_searching': time.time()}
  304.  
  305. # csgostats.gg VAR
  306. retrying_games = []
  307.  
  308. # WARMUP DETECTION SETUP
  309. pytesseract.pytesseract.tesseract_cmd = cfg['tesseract_path']
  310. push_times, no_text_found, push_counter = [], 0, 0
  311. for i in cfg['warmup_push_interval'].split(','):
  312.     push_times.append(int(i))
  313. push_times.sort(reverse=True)
  314. join_warmup_time = push_times[0] + 1
  315.  
  316. # PUSHBULLET VAR
  317. note = ''
  318. push_urgency = 0
  319.  
  320. write('READY')
  321. write('Current account is: %s\n' % accounts[current_account]['name'], add_time=False)
  322.  
  323. while True:
  324.     if win32api.GetAsyncKeyState(cfg['activate_script']) & 1:  # F9 (ACTIVATE / DEACTIVATE SCRIPT)
  325.         truth_table['test_for_live_game'] = not truth_table['test_for_live_game']
  326.         write('TESTING: %s' % truth_table['test_for_live_game'], overwrite=(True, '1'))
  327.         if truth_table['test_for_live_game']:
  328.             playsound('sounds/activated_2.mp3')
  329.             time_table['time_searching'] = time.time()
  330.         else:
  331.             playsound('sounds/deactivated.mp3')
  332.  
  333.     if win32api.GetAsyncKeyState(cfg['activate_push_notification']) & 1:  # F8 (ACTIVATE / DEACTIVATE PUSH NOTIFICATION)
  334.         if not device:
  335.             try:
  336.                 device = pushbullet.PushBullet(cfg['pushbullet_api_key']).get_device(cfg['pushbullet_device_name'])
  337.             except (pushbullet.errors.PushbulletError, pushbullet.errors.InvalidKeyError):
  338.                 write('Pushbullet is wrongly configured.\nWrong API Key or DeviceName in config.ini')
  339.         if device:
  340.             push_urgency += 1
  341.             if push_urgency > 3:
  342.                 push_urgency = 0
  343.             push_info = ['not active', 'only if accepted', 'all game status related information', 'all information (game status/csgostats.gg information)']
  344.             write('Pushing: %s' % push_info[push_urgency], overwrite=(True, '2'))
  345.  
  346.     if win32api.GetAsyncKeyState(cfg['info_newest_match']) & 1:  # F7 Key (UPLOAD NEWEST MATCH)
  347.         write('Uploading / Getting status on newest match')
  348.         sharecodes = getNewCSGOMatches(getOldSharecodes()[0])
  349.         UpdateCSGOstats(sharecodes, num_completed=len(sharecodes))
  350.  
  351.     if win32api.GetAsyncKeyState(cfg['info_multiple_matches']) & 1:  # F6 Key (GET INFO ON LAST X MATCHES)
  352.         write('Getting Info from last %s matches' % cfg['last_x_matches'])
  353.         getNewCSGOMatches(getOldSharecodes()[0])
  354.         UpdateCSGOstats(getOldSharecodes(num=cfg['last_x_matches'] * -1), num_completed=cfg['completed_matches'])
  355.  
  356.     if win32api.GetAsyncKeyState(cfg['open_live_tab']) & 1:  # F13 Key (OPEN WEB BROWSER ON LIVE GAME TAB)
  357.         win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
  358.         webbrowser.open_new_tab('https://csgostats.gg/player/' + accounts[current_account]['steam_id'] + '#/live')
  359.         write('new tab opened', add_time=False)
  360.         time.sleep(0.5)
  361.         win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
  362.  
  363.     if win32api.GetAsyncKeyState(cfg['switch_accounts']) & 1:  # F15 (SWITCH ACCOUNTS)
  364.         current_account += 1
  365.         if current_account > len(accounts) - 1:
  366.             current_account = 0
  367.         write('current account is: %s' % accounts[current_account]['name'], add_time=False, overwrite=(True, '4'))
  368.  
  369.     if win32api.GetAsyncKeyState(cfg['end_script']) & 1:  # POS1 (END SCRIPT)
  370.         write('Exiting Script')
  371.         break
  372.  
  373.     if retrying_games:
  374.         if time.time() - time_table['error_check_time'] > cfg['auto_retry_interval']:
  375.             time_table['error_check_time'] = time.time()
  376.             UpdateCSGOstats(retrying_games, num_completed=len(retrying_games))
  377.  
  378.     winlist = []
  379.     win32gui.EnumWindows(enum_cb, toplist)
  380.     csgo = [(hwnd, title) for hwnd, title in winlist if 'counter-strike: global offensive' in title.lower()]
  381.  
  382.     # ONLY CONTINUING IF CSGO IS RUNNING
  383.     if not csgo:
  384.         continue
  385.     hwnd = csgo[0][0]
  386.  
  387.     # TESTING HERE
  388.     if win32api.GetAsyncKeyState(0x6F) & 1:  # UNBOUND, TEST CODE
  389.         # write('Executing Debugging\n')
  390.         # truth_table['testing'] = not truth_table['testing']
  391.         # truth_table['debugging'] = not truth_table['debugging']
  392.         truth_table['test_for_warmup'] = not truth_table['test_for_warmup']
  393.         time_table['warmup_test_timer'] = time.time() + 2
  394.         # write('DEBUGGING: %s\n' % truth_table['debugging'])
  395.  
  396.     if truth_table['testing']:
  397.         # time_table['screenshot_time'] = time.time()
  398.         pass
  399.         # print('Took: %s ' % str(timedelta(milliseconds=int(time.time(*1000 - time_table['screenshot_time']*1000))))
  400.     # TESTING ENDS HERE
  401.  
  402.     if truth_table['test_for_live_game']:
  403.         if time.time() - time_table['screenshot_time'] < cfg['screenshot_interval']:
  404.             continue
  405.         time_table['screenshot_time'] = time.time()
  406.         img = getScreenShot(hwnd, (1265, 760, 1295, 785))
  407.         if not img:
  408.             continue
  409.         accept_avg = color_average(img, [76, 176, 80, 90, 203, 95])
  410.  
  411.         if relate_list(accept_avg, [1, 2, 1], l2=[1, 1, 2]):
  412.             write('Trying to Accept', push=push_urgency + 1)
  413.  
  414.             truth_table['test_for_success'] = True
  415.             truth_table['test_for_live_game'] = False
  416.             accept_avg = []
  417.  
  418.             for _ in range(5):
  419.                 click(int(screen_width / 2), int(screen_height / 1.78))
  420.  
  421.             write('Trying to catch a loading map')
  422.             playsound('sounds/accept_found.mp3')
  423.             time_table['screenshot_time'] = time.time()
  424.  
  425.     if truth_table['test_for_success']:
  426.         if time.time() - time_table['screenshot_time'] < 40:
  427.             img = getScreenShot(hwnd, (2435, 65, 2555, 100))
  428.             not_searching_avg = color_average(img, [6, 10, 10])
  429.             searching_avg = color_average(img, [6, 163, 97, 4, 63, 35])
  430.  
  431.             not_searching = relate_list(not_searching_avg, [2, 5, 5])
  432.             searching = relate_list(searching_avg, [2.7, 55, 35], l2=[1, 50, 35])
  433.  
  434.             img = getScreenShot(hwnd, (467, 1409, 1300, 1417))
  435.             success_avg = color_average(img, [21, 123, 169])
  436.             success = relate_list(success_avg, [1, 8, 7])
  437.  
  438.             if success:
  439.                 write('Took %s since pressing accept.' % str(timedelta(seconds=int(time.time() - time_table['screenshot_time']))), add_time=False, push=push_urgency + 1)
  440.                 write('Took %s since trying to find a game.' % str(timedelta(seconds=int(time.time() - time_table['time_searching']))), add_time=False, push=push_urgency + 1)
  441.                 write('Game should have started', push=push_urgency + 2, push_now=True)
  442.                 truth_table['test_for_success'] = False
  443.                 truth_table['test_for_warmup'] = True
  444.                 playsound('sounds/done_testing.mp3')
  445.                 time_table['warmup_test_timer'] = time.time() + 5
  446.  
  447.             if any([searching, not_searching]):
  448.                 write('Took: %s ' % str(timedelta(seconds=int(time.time() - time_table['screenshot_time']))), add_time=False, push=push_urgency + 1)
  449.                 write('Game doesnt seem to have started. Continuing to search for accept Button!', push=push_urgency + 1, push_now=True)
  450.                 playsound('sounds/back_to_testing.mp3')
  451.                 truth_table['test_for_success'] = False
  452.                 truth_table['test_for_live_game'] = True
  453.  
  454.         else:
  455.             write('40 Seconds after accept, did not find loading map nor searching queue')
  456.             truth_table['test_for_success'] = False
  457.             print(success_avg)
  458.             print(searching_avg)
  459.             print(not_searching_avg)
  460.             playsound('sounds/fail.mp3')
  461.             img.save(os.path.expanduser('~') + '\\Unknown Error.png')
  462.  
  463.     if truth_table['test_for_warmup']:
  464.         for i in range(112, 113):  # 136
  465.             win32api.GetAsyncKeyState(i) & 1
  466.         while True:
  467.             keys = []
  468.             for i in range(112, 113):
  469.                 keys.append(win32api.GetAsyncKeyState(i) & 1)
  470.             if any(keys):
  471.                 write('Break from warmup-loop')
  472.                 truth_table['test_for_warmup'] = False
  473.                 truth_table['first_ocr'] = True
  474.                 truth_table['first_push'] = True
  475.                 break
  476.  
  477.             if time.time() - time_table['warmup_test_timer'] >= cfg['warmup_test_interval']:
  478.                 img = getScreenShot(hwnd, (1036, 425, 1525, 456))  # 'WAITING FOR PLAYERS X:XX'
  479.                 img_text = Image_to_Text(img, img.size, [225, 225, 225], arg='--psm 6')
  480.                 time_table['warmup_test_timer'] = time.time()
  481.                 if img_text:
  482.                     time_left = img_text.split()[-1].split(':')
  483.                     # write(img_text, add_time=False)
  484.                     try:
  485.                         time_left = int(time_left[0]) * 60 + int(time_left[1])
  486.                         if truth_table['first_ocr']:
  487.                             join_warmup_time = time_left
  488.                             time_table['screenshot_time'] = time.time()
  489.                             truth_table['first_ocr'] = False
  490.  
  491.                     except ValueError:
  492.                         time_left = push_times[0] + 1
  493.  
  494.                     time_left_data = timedelta(seconds=int(time.time() - time_table['screenshot_time'])), time.strftime('%H:%M:%S', time.gmtime(abs((join_warmup_time - time_left) - (time.time() - time_table['screenshot_time'])))), img_text
  495.                     write('Time since start: %s - Time Difference: %s - Time left: %s' % (time_left_data[0], time_left_data[1], time_left_data[2]), add_time=False, overwrite=True, key='1')
  496.                     if no_text_found > 0:
  497.                         no_text_found -= 1
  498.  
  499.                     if time_left <= push_times[push_counter]:
  500.                         push_counter += 1
  501.                         write('Time since start: %s\nTime Difference: %s\nTime left: %s' % (time_left_data[0], time_left_data[1], time_left_data[2]), add_time=True, push=push_urgency + 1, output=False, push_now=True)
  502.  
  503.                     if truth_table['first_push']:
  504.                         if abs((join_warmup_time - time_left) - (time.time() - time_table['screenshot_time'])) >= 5:
  505.                             truth_table['first_push'] = False
  506.                             write('Match should start in ' + str(time_left) + 'seconds, All players have connected', push=push_urgency + 2, push_now=True, add_time=True)
  507.  
  508.                 else:
  509.                     no_text_found += 1
  510.  
  511.             if push_counter >= len(push_times):
  512.                 push_counter = 0
  513.                 no_text_found = 0
  514.                 truth_table['test_for_warmup'] = False
  515.                 truth_table['first_ocr'] = True
  516.                 truth_table['first_push'] = True
  517.                 write('Warmup should be over in less then %s seconds!' % push_times[-1], add_time=True, push=push_urgency + 2, push_now=True)
  518.                 break
  519.  
  520.             if no_text_found >= cfg['warmup_no_text_limit']:
  521.                 push_counter = 0
  522.                 no_text_found = 0
  523.                 truth_table['test_for_warmup'] = False
  524.                 truth_table['first_ocr'] = True
  525.                 truth_table['first_push'] = True
  526.                 write('Did not find any warmup text.', add_time=True, push=push_urgency + 2, push_now=True)
  527.                 break
  528.  
  529. exit('ENDED BY USER')
Add Comment
Please, Sign In to add comment