Skip to content

Instantly share code, notes, and snippets.

@MobCat
Created May 27, 2022 03:06
Show Gist options
  • Select an option

  • Save MobCat/944a853d7f355a3f3e69d4e5a31b0f55 to your computer and use it in GitHub Desktop.

Select an option

Save MobCat/944a853d7f355a3f3e69d4e5a31b0f55 to your computer and use it in GitHub Desktop.
Shitty python script that runs more python scripts
#!/env/Python3.8.10
#!/MobCat (2022)
import schedule # Re-run our script once per day
import time # Shitty wait timer
import subprocess # Yo dawg, I heard you like python, so we used python to run your python.
import datetime # Set time for the clock... why this and time idk...
# The script we are going to run with this scheduler
def main():
print("\nTime to boop the bot.")
subprocess.call(["python", "DiscordOneShot.py"], shell=True)
print("Back to sleep.")
###########################################################################
# Scheduler setup for when we are going to run the script
#schedule.every().hour.at(":05").do(main) # Run script evrey hour, 5 mins past the hour. 10:05, 11:05, 12:05, etc
schedule.every(10).minutes.do(main) # Run script evrey 10 mins
#schedule.every().hour.do(main) # Run script evrey hour
#schedule.every().day.at("10:30").do(main) # Run script evrey day at 10:30AM
#schedule.every().monday.do(main) # Run script evrey monday at 00:00 (midnight)
#schedule.every().wednesday.at("13:15").do(main) # Run script evrey wednesday at 1:15PM
#schedule.every().minute.at(":17").do(main) # Run script evrey minute at 17 secs past the min 10:05:17, 10:06:17, 10:07:17
# User string to remind you when the Scheduler is running so you don't have to check the code
#print("Scheduler is running.\nEvery day at 10:30AM.")
print("Scheduler is running.\nEvery 10 minutes.")
###############################################################################
# Everey one second, check if your script needs to be ran.
# If not mark down what time we last checked the schedule and go to sleep for 1 secs.
# So if it crashes or get stuck, we know how long ago it crashed. Or how long it hasn't been running for.
# Sleep time can be increased but you have less of a chance of hitting your desired target time.
# Repeat this check forever.
while True:
try:
schedule.run_pending()
current_time = datetime.datetime.now().strftime("%H:%M:%S")
print(f" {current_time}: Sleeping Zzz...", end="\r", flush=True)
time.sleep(1) # seconds
except KeyboardInterrupt:
print("\nScript terminated by user.\nGoodbye ^__^/")
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment