<commit_before>#!/usr/bin/env python
from __future__ import absolute_import, division, print_function, \
    unicode_literals
import sys
import time
import socket
import urllib
import hashlib
import argparse

from zeroconf import ServiceBrowser, Zeroconf

filename = ""
filehash = ""
output = ""
downloaded = False


class ServiceListener(object):
    def remove_service(*args):
        pass

    def add_service(self, zeroconf, type, name):
        global downloaded, filename, filehash, output
        if name == filehash + "._gynt._http._tcp.local.":
            print("Peer found. Downloading...")
            info = zeroconf.get_service_info(type, name)
            if info:
                address = socket.inet_ntoa(info.address)
                port = info.port
                url = "http://" + address + ":" + str(port) + "/" + filename
                urllib.urlretrieve(url, output)
                downloaded = True


def get(inargs=None):
    global downloaded, filename, filehash, output

    parser = argparse.ArgumentParser()

    parser.add_argument('filename')
    parser.add_argument('output', nargs='?')
    args = parser.parse_args(inargs)

    filename = args.filename
    filehash = hashlib.sha1(filename).hexdigest()
    downloaded = False
    if args.output is not None:
        output = args.output
    else:
        output = filename

    zeroconf = Zeroconf()
    listener = ServiceListener()
    browser = ServiceBrowser(zeroconf, "_gynt._http._tcp.local.", listener)

    while not downloaded:
        time.sleep(0.1)
    print("Done.")
    zeroconf.close()


if __name__ == '__main__':
    get(sys.argv[1:])
<commit_msg>Sleep more slowly, maybe preventing errors<commit_after>#!/usr/bin/env python
from __future__ import absolute_import, division, print_function, \
    unicode_literals
import sys
import time
import socket
import urllib
import hashlib
import argparse

from zeroconf import ServiceBrowser, Zeroconf

filename = ""
filehash = ""
output = ""
downloaded = False


class ServiceListener(object):
    def remove_service(*args):
        pass

    def add_service(self, zeroconf, type, name):
        global downloaded, filename, filehash, output
        if name == filehash + "._gynt._http._tcp.local.":
            print("Peer found. Downloading...")
            info = zeroconf.get_service_info(type, name)
            if info:
                address = socket.inet_ntoa(info.address)
                port = info.port
                url = "http://" + address + ":" + str(port) + "/" + filename
                urllib.urlretrieve(url, output)
                downloaded = True


def get(inargs=None):
    global downloaded, filename, filehash, output

    parser = argparse.ArgumentParser()

    parser.add_argument('filename')
    parser.add_argument('output', nargs='?')
    args = parser.parse_args(inargs)

    filename = args.filename
    filehash = hashlib.sha1(filename).hexdigest()
    downloaded = False
    if args.output is not None:
        output = args.output
    else:
        output = filename

    zeroconf = Zeroconf()
    listener = ServiceListener()
    browser = ServiceBrowser(zeroconf, "_gynt._http._tcp.local.", listener)

    while not downloaded:
        time.sleep(0.5)
    print("Done.")
    zeroconf.close()


if __name__ == '__main__':
    get(sys.argv[1:])

{'fraction_non_alphanumeric': 0.10951095109510951, 'fraction_numerical': 0.0024002400240024004, 'mean_word_length': 2.688053097345133, 'pattern_counts': {'":': 4, '<': 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': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '166695', 'n_tokens_mistral': 1018, 'n_tokens_neox': 978, 'n_words': 243}