<commit_before>#!/usr/bin/python3
peers = dict()
count = 0
from http.server import BaseHTTPRequestHandler, HTTPServer
import json

class Handler(BaseHTTPRequestHandler):
    def do_HEAD(self, content_type='text/html'):
        global count
        count += 1
        print('#'*10)
        print('Received {} connection #{}'.format(self.command, count))
        print(self.client_address)
        #print(self.headers.__dict__)

        self.send_response(200)
        self.send_header('Content-type', content_type)
        self.end_headers()

    def do_GET(self): #todo
        self.do_HEAD('text/plain')
        jsondata = json.dumps(peers)
        self.wfile.write(bytes(jsondata, 'utf-8'))

    def do_POST(self):
        self.do_HEAD()

        ip = self.client_address[0]
        nick = self.rfile.read(self.headers['Content-lenght']).decode('utf-8')
        print(nick)
        if ip in peers.values():
            peers.pop(list(peers.keys())[list(peers.values()).index(ip)]) # delete existing name
        peers[nick] = ip
        print(peers)



host = ''
port = 8080

try:
    server = HTTPServer((host, port), Handler)
    [print(item) for item in server.__dict__.values()]
    server.serve_forever()
except KeyboardInterrupt:
    print('Shutting down on ^C')
    server.server_close()<commit_msg>start<commit_after>#!/usr/bin/python3
peers = dict()
count = 0
from http.server import BaseHTTPRequestHandler, HTTPServer
import json,urllib.request

class Handler(BaseHTTPRequestHandler):
    def do_HEAD(self, content_type='text/html'):
        global count
        count += 1
        print('#'*10)
        print('Received {} connection #{}'.format(self.command, count))
        print(self.client_address)
        #print(self.headers.__dict__)

        self.send_response(200)
        self.send_header('Content-type', content_type)
        self.end_headers()

    def do_GET(self): #todo
        self.do_HEAD('text/plain')
        ip = self.client_address[0]
        jsondata = json.dumps(peers)
        self.wfile.write(bytes(jsondata, 'utf-8'))
        print('sent ', jsondata,' to {}@{}'.format(peers[ip],ip))

    def do_POST(self):
        self.do_HEAD()

        ip = self.client_address[0]
        nick = self.rfile.read(self.headers['Content-lenght']).decode('utf-8')
        
        if ip in peers.keys():
            peers.pop(ip) # delete existing name
        peers[ip] = nick
        print('Added {} @ {}'.format(nick, ip))
        print(peers)



host = ''
port = 8080

try:
    server = HTTPServer((host, port), Handler)
    print(server.server_name,'@',str(urllib.request.urlopen('http://www.biranchi.com/ip.php').read()),':',server.server_port)
    server.serve_forever()
except KeyboardInterrupt:
    print('Shutting down on ^C')
    server.server_close()
{'fraction_non_alphanumeric': 0.14624505928853754, 'fraction_numerical': 0.011139058569888609, 'mean_word_length': 2.9101123595505616, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '4348689', 'n_tokens_mistral': 921, 'n_tokens_neox': 900, 'n_words': 163}