<commit_before>#!/usr/bin/env python3

import time
import contextlib
import subprocess
import dhcpctl


def generate_leases(server, port, subnet, start, end, ping):
    with contextlib.closing(dhcpctl.Connection(server, port)) as dhcp:
        print("IN")

        for i in range(start, end):
            ip, ttl, name = dhcp.get_lease("%s.%d" % (subnet, i))

            if not ttl:
                continue

            status, output = subprocess.getstatusoutput(
                ping % {"ip": ip}
            )

            if not status:
                diff = int(time.time()) - ttl
                hours = int((diff / 60) / 60)
                mins = int((diff / 60) % 60)

                yield "ip=%s, uptime=(%dh, %dm), name=%s" % (
                    ip,
                    hours,
                    mins,
                    name
                )


if __name__ == "__main__":
    server = "192.168.1.2"
    port = 20999
    subnet = "192.168.1"
    start = 50
    end = 200
    ping = "ping -q -c 1 %(ip)s &>/dev/null"

    for lease in generate_leases(server, port, subnet, start, end, ping):
        print(lease)
<commit_msg>Uses cleaner integer division instead of casting.<commit_after>#!/usr/bin/env python3

import time
import contextlib
import subprocess
import dhcpctl


def generate_leases(server, port, subnet, start, end, ping):
    with contextlib.closing(dhcpctl.Connection(server, port)) as dhcp:
        print("IN")

        for i in range(start, end):
            ip, ttl, name = dhcp.get_lease("%s.%d" % (subnet, i))

            if not ttl:
                continue

            status, output = subprocess.getstatusoutput(
                ping % {"ip": ip}
            )

            if not status:
                diff = int(time.time()) - ttl
                hours = (diff // 60) // 60
                mins = (diff // 60) % 60

                yield "ip=%s, uptime=(%dh, %dm), name=%s" % (
                    ip,
                    hours,
                    mins,
                    name
                )


if __name__ == "__main__":
    server = "192.168.1.2"
    port = 20999
    subnet = "192.168.1"
    start = 50
    end = 200
    ping = "ping -q -c 1 %(ip)s &>/dev/null"

    for lease in generate_leases(server, port, subnet, start, end, ping):
        print(lease)

{'fraction_non_alphanumeric': 0.12267818574514039, 'fraction_numerical': 0.03023758099352052, 'mean_word_length': 1.482315112540193, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, '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': '1811278', 'n_tokens_mistral': 813, 'n_tokens_neox': 701, 'n_words': 200}