Created
August 4, 2022 21:21
-
-
Save mothdotmonster/b34be76e3df4c40cd6e04ad1a67f4cf0 to your computer and use it in GitHub Desktop.
sleep with random delay, so you don't overload the server at midnight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# fuzzysleep - sleep with random delay, so you don't overload the server at midnight | |
import time, random, argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument("delay", help="Desired maximum delay", type=int) | |
parser.add_argument("--verbose", help="Prints extra info", action="store_true") | |
group = parser.add_mutually_exclusive_group() | |
group.add_argument("--minutes", action="store_true", help="Use minutes instead of seconds") | |
group.add_argument("--hours", action="store_true", help="Use hours instead of seconds") | |
args=parser.parse_args() | |
if args.minutes: | |
delay = random.randint(0, (args.delay*60)) | |
elif args.hours: | |
delay = random.randint(0, (args.delay*3600)) | |
else: | |
delay = random.randint(0, args.delay) | |
if args.verbose: | |
print("Sleeping for {} seconds...".format(delay)) | |
time.sleep(delay) | |
if args.verbose: | |
print("Sleeping finished!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment