<commit_before>import sys
import os
import subprocess
import json 

from tqdm import tqdm
import click
from pick import pick

def which(program):
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file
    raise


@click.command()
@click.option('-a','--adapter', default='', help='adapter to use')
@click.option('-v','--verbose', help='verbose mode', is_flag=True)
@click.option('-t','--time', default='60', help='time in seconds to scan')
def find_people(adapter,time,verbose):
    """Simple program that greets NAME for a total of COUNT times."""
    try:
        tshark = which("tshark")
    except:
        print("tshark not found, you must install using\n\napt-get install tshark")
        return

    adapters = []
    for line in subprocess.check_output(['ifconfig']).decode('utf-8').split('\n'):
        if ' Link' in line and line[0] == 'w':
            adapters.append(line.split()[0])
    if len(adapter) == 0:
        title = 'Please choose the adapter you want to use: '
        adapter, index = pick(adapters, title)
    print("Using %s adapter and scanning for %s seconds..." % (adapter,time))
    # Scan with tshark
    command = "%s -I -i %s -a duration:%s -w /tmp/tshark-temp" % (tshark,adapter,time)
    run_tshark = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    stdout, nothing = run_tshark.communicate()   

    # Read tshark output
    command = "%s -r /tmp/tshark-temp -T fields -e wlan.sa -e wlan.bssid -e radiotap.dbm_antsignal" % tshark
    run_tshark = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    output, nothing = run_tshark.communicate()   
    oui = json.load(open('data/oui.json','r'))
    foundMacs = []
    for line in output.decode('utf-8').split('\n'):
        if verbose:
            print(line)
        if len(line.strip()) == 0:
            continue
        mac = line.split()[0].strip()
        if mac not in foundMacs:
            foundMacs.append(mac)

    num_cellphones = 0
    cellphone = ['Motorola Mobility LLC, a Lenovo Company','GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP.,LTD','Huawei Symantec Technologies Co.,Ltd.','Microsoft','HTC Corporation','Samsung Electronics Co.,Ltd','BlackBerry RTS','LG ELECTRONICS INC','Apple, Inc.','LG Electronics','LG Electronics (Mobile Communications)']
    for mac in foundMacs:<commit_msg>Added timer, better tshark output suppression<commit_after>import threading
import sys
import os
import subprocess
import json 
import time
import datetime

import humanize
import click
from pick import pick

def which(program):
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file
    raise

def showTimer(timeleft):
    total = int(timeleft)*10
    for i in range(total):
        sys.stdout.write('\r')
        # the exact output you're looking for:
        timeleft_string = humanize.naturaltime(datetime.datetime.now() - datetime.timedelta(seconds=(total-i+1)/10))
        timeleft_string = ' '.join(timeleft_string.split()[:2])
        sys.stdout.write("[%-50s] %d%% %s left" % ('='*int(50.5*i/total), 101*i/total,timeleft_string))
        sys.stdout.flush()
        time.sleep(0.1)

@click.command()
@click.option('-a','--adapter', default='', help='adapter to use')
@click.option('-v','--verbose', help='verbose mode', is_flag=True)
@click.option('-s','--scantime', default='60', help='time in seconds to scan')
def find_people(adapter,scantime,verbose):
    """Uses tshark to determine approximately how many people are around"""
    try:
        tshark = which("tshark")
    except:
        print("tshark not found, you must install using\n\napt-get install tshark")
        return

    adapters = []
    for line in subprocess.check_output(['ifconfig']).decode('utf-8').split('\n'):
        if ' Link' in line and line[0] == 'w':
            adapters.append(line.split()[0])
    if len(adapter) == 0:
        title = 'Please choose the adapter you want to use: '
        adapter, index = pick(adapters, title)
    print("Using %s adapter and scanning for %s seconds..." % (adapter,scantime))
    # Start timer 
    t1 = threading.Thread(target=showTimer,args=(scantime,))
    t1.start()

    # Scan with tshark
    command = "%s -I -i %s -a duration:%s -w /tmp/tshark-temp" % (tshark,adapter,scantime)
    run_tshark = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    stdout, nothing = run_tshark.communicate()   
    t1.join()

    # Read tshark output
    command = "%s -r /tmp/tshark-temp -T fields -e wlan.sa -e wlan.bssid -e radiotap.dbm_antsignal" % tshark
    run_tshark = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    output, nothing = run_tshark.communicate()   
    oui = json.load(open('data/oui.json','r'))
    foundMacs = []
    for line in output.decode('utf-8').split('\n'):
        if verbose:
            print(line)
        if len(line.strip()) == 0:
            continue
        mac = line.split()[0].strip()
        if mac not in foundMacs:
            foundMacs.append(mac)

    num_cellphones = 0
    cellphone = ['Motorola Mobility LLC, a Lenovo Company','GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP.,LTD','Huawei Symantec Technologies Co.,Ltd.','Microsoft','HTC Corporation','Samsung Electronics Co.,Ltd','BlackBerry RTS','LG ELECTRONICS INC','Apple, Inc.','LG Electronics','LG Electronics (Mobile Communications)']
    for mac in foundMacs:
{'fraction_non_alphanumeric': 0.14250893727656808, 'fraction_numerical': 0.006337341566460838, 'mean_word_length': 3.076158940397351, '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': '1573918', 'n_tokens_mistral': 2085, 'n_tokens_neox': 2002, 'n_words': 499}