<commit_before>from urllib.request import urlopen
from antigate import AntiGate, AntiGateError
import log
import socket
import urllib.error
import os
import time

_key = open('antigate.txt').read().strip()

def receive(url, timeout=10):
    try:
        data = urlopen(url, timeout=timeout).read()
    except (urllib.error.URLError, socket.timeout):
        log.warning('captcha timeout')
        time.sleep(5)
        receive(url, timeout)
    except Exception:
        log.error('captcha.receive error', True)
        time.sleep(5)
        receive(url, timeout)
    with open('captcha.png', 'wb') as f:
        f.write(data)

def delete():
    try:
        os.remove('captcha.png')
    except FileNotFoundError:
        pass

def solve():
    try:
        return str(AntiGate(_key, 'captcha.png')) or None
    except AntiGateError as e:
        log.warning(str(e))
        return None
    except Exception:
        log.error('captcha.solve error', True)
        return ''

<commit_msg>Missing captcha.png is not an error<commit_after>from urllib.request import urlopen
from antigate import AntiGate, AntiGateError
import log
import socket
import urllib.error
import os
import time

_key = open('antigate.txt').read().strip()

def receive(url, timeout=10):
    try:
        data = urlopen(url, timeout=timeout).read()
    except (urllib.error.URLError, socket.timeout):
        log.warning('captcha timeout')
        time.sleep(5)
        receive(url, timeout)
    except Exception:
        log.error('captcha.receive error', True)
        time.sleep(5)
        receive(url, timeout)
    with open('captcha.png', 'wb') as f:
        f.write(data)

def delete():
    try:
        os.remove('captcha.png')
    except FileNotFoundError:
        pass

def solve():
    if not os.path.isfile('captcha.png'):
        log.warning('captcha.png does not exist')
        return None
    try:
        return str(AntiGate(_key, 'captcha.png')) or None
    except AntiGateError as e:
        log.warning(str(e))
        return None
    except Exception:
        log.error('captcha.solve error', True)
        return ''


{'fraction_non_alphanumeric': 0.11622390891840607, 'fraction_numerical': 0.003795066413662239, 'mean_word_length': 2.7065026362038664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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}}
{'dir': 'git-commits-cleaned', 'id': '162563', 'n_tokens_mistral': 669, 'n_tokens_neox': 645, 'n_words': 170}