<commit_before>#!/usr/bin/env python3
"""Start an HTTP server from a directory, optionally specifying the port"""

import optparse
import webbrowser
import http.server
import socket
import socketserver


def get_local_ip():
    with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
        s.connect(("8.8.8.8", 80))
        return s.getsockname()[0]

def main():
    p = optparse.OptionParser(description=__doc__)
    p.add_option("-p", "--port", dest="port", default=8000,
                  help="specify the port (default: 8000)")
    options, arguments = p.parse_args()
    Handler = http.server.SimpleHTTPRequestHandler

    with socketserver.TCPServer(("", int(options.port)), Handler) as httpd:
        print("   Local URL:", f"http://localhost:{options.port}")
        print("External URL:", f"http://{get_local_ip()}:{options.port}")
        httpd.serve_forever()

if __name__ == '__main__':
    main()<commit_msg>bin/server: copy local url to clipboard<commit_after>#!/usr/bin/env python3
"""Start an HTTP server from a directory, optionally specifying the port"""

import optparse
import webbrowser
import http.server
import socket
import socketserver
import subprocess


def copy_to_clipboard(txt):
    cmd=f'echo "{txt.strip()}" | xsel --clipboard --input'
    return subprocess.check_call(cmd, shell=True)

def get_local_ip():
    with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
        s.connect(("8.8.8.8", 80))
        return s.getsockname()[0]

def main():
    p = optparse.OptionParser(description=__doc__)
    p.add_option("-p", "--port", dest="port", default=8000,
                  help="specify the port (default: 8000)")
    options, arguments = p.parse_args()

    with socketserver.TCPServer(("", int(options.port)), http.server.SimpleHTTPRequestHandler) as httpd:
        local_url = f"http://localhost:{options.port}"
        external_url = f"http://{get_local_ip()}:{options.port}"
        print("   Local URL:", local_url)
        print("External URL:", external_url)
        copy_to_clipboard(local_url)
        httpd.serve_forever()

if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.14427157001414428, 'fraction_numerical': 0.015087223008015087, 'mean_word_length': 3.70509977827051, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '564059', 'n_tokens_mistral': 698, 'n_tokens_neox': 665, 'n_words': 159}