#!/usr/bin/python3 -u

## Copyright (C) 2017 - 2023 ENCRYPTED SUPPORT LP <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

import os
import time
import datetime
from sdwdate.remote_times import get_time_from_servers
from sdwdate.config import read_pools
from sdwdate.config import get_comment_pool_single
from sdwdate.proxy_settings import proxy_settings

# Helpers for a cludge to check only 3 urls at once
def chunks(my_list, n):
    """Yield successive n-sized chunks from my_list."""
    for i in range(0, len(my_list), n):
        yield my_list[i:i + n]

class Pool:
    def __init__(self, pool):
        self.url, self.comment = read_pools(pool, 'test')

class CheckRemotes:
    def __init__(self):
        self.number_of_pools = 3
        self.pools = [Pool(pool) for pool in range(self.number_of_pools)]
        self.proxy_ip, self.proxy_port = proxy_settings()

    def loop(self):
        for pool in self.pools:
            url_chunk_list = list(chunks(pool.url,1))
            for url_chunk in url_chunk_list:
                remote = url_chunk[0]
                comment = get_comment_pool_single(pool, remote)
                print(remote + " " + comment)

if __name__ == '__main__':
    remotes = CheckRemotes()
    remotes.loop()
