From 1861b4599d6102a03d2250c90dbab026970713ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=88=9A=28noham=29=C2=B2?= <100566912+NohamR@users.noreply.github.com> Date: Mon, 23 Dec 2024 22:53:09 +0100 Subject: [PATCH] timer --- code/process_torrent.py | 7 ++++--- ratio.py | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/code/process_torrent.py b/code/process_torrent.py index 6a3cf32..c8190eb 100644 --- a/code/process_torrent.py +++ b/code/process_torrent.py @@ -83,8 +83,8 @@ class process_torrent(): peers.append((ip, port)) self.interval = response['interval'] -def seedqueue(queue): - while True: +def seedqueue(queue, time): + while time > 0: waitingqueue = "" for torrent in queue: if torrent.timer <= 0: @@ -112,4 +112,5 @@ def seedqueue(queue): waitingqueue += f"Waiting {torrent.timer} seconds for {torrent.configuration['torrent']}" + "\n" os.system('cls' if os.name == 'nt' else 'clear') print(waitingqueue) - sleep(1) \ No newline at end of file + sleep(1) + time -= 1 \ No newline at end of file diff --git a/ratio.py b/ratio.py index 0dd3a7a..ce3e2f2 100644 --- a/ratio.py +++ b/ratio.py @@ -8,6 +8,8 @@ def parse_args(): """Create the arguments""" parser = argparse.ArgumentParser(description="Fake ratio") parser.add_argument("-c", "--configuration", help="Configuration file") + parser.add_argument("-t", "--time", help="Time to seed", type=str, default="1d") +# parser.add_argument("-s", "--speed", help="Speed to seed", type=str, default="350") return parser.parse_args() def load_configuration(configuration_file): @@ -17,6 +19,22 @@ def load_configuration(configuration_file): return None return configuration +def get_time(timestring): + days = hours = minutes = seconds = 0 + if 'd' in timestring: + days, timestring = timestring.split('d') + days = int(days) + if 'h' in timestring: + hours, timestring = timestring.split('h') + hours = int(hours) + if 'm' in timestring: + minutes, timestring = timestring.split('m') + minutes = int(minutes) + if 's' in timestring: + seconds = int(timestring.split('s')[0]) + total_seconds = days * 86400 + hours * 3600 + minutes * 60 + seconds + return total_seconds + if __name__ == "__main__": queue = [] args = parse_args() @@ -40,4 +58,5 @@ if __name__ == "__main__": torrent = process_torrent(config) queue.append(torrent) print(f'Got {len(queue)} torrents') - seedqueue(queue) \ No newline at end of file + time = get_time(args.time) + seedqueue(queue, time) \ No newline at end of file