scheduler shutdown reboots

This commit is contained in:
Justin 2023-04-21 16:46:43 +08:00 committed by GitHub
parent ff1b4d8030
commit e8cb455c35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,6 +36,23 @@ try:
except: except:
pass pass
try:
f = open('csv/scheduler.json', 'r')
schedules = json.load(f)
f.close()
shutdown_schedule = schedules['shutdown']['time']
reboot_schedule = schedules['reboot']['time']
timezone = schedules['timezone']
shutdown_enabled = schedules['shutdown']['enabled']
reboot_enabled = schedules['reboot']['enabled']
except:
shutdown_schedule = "00:00"
reboot_schedule = "00:00"
timezone = "GMT"
shutdown_enabled = False
reboot_enabled = False
def getInput(Block=False): def getInput(Block=False):
if Block or select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []): if Block or select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
@ -1240,13 +1257,42 @@ if __name__ == '__main__':
f.close() f.close()
except: except:
last_updates = {"stocks": {"time": "06/03/2022 04:12:09", "force": True}, "crypto": {"time": "06/03/2022 04:10:39", "force": True}, last_updates = {"scheduler":{"force": False}, "stocks": {"time": "06/03/2022 04:12:09", "force": True}, "crypto": {"time": "06/03/2022 04:10:39", "force": True},
"news": {"time": "06/03/2022 04:07:09", "force": True}, "weather": {"time": "06/03/2022 04:08:20", "force": True}, "news": {"time": "06/03/2022 04:07:09", "force": True}, "weather": {"time": "06/03/2022 04:08:20", "force": True},
"forex": {"time": "06/03/2022 03:54:02", "force": True}, "sports_l": {"time": "06/03/2022 04:10:09", "force": True}, "forex": {"time": "06/03/2022 03:54:02", "force": True}, "sports_l": {"time": "06/03/2022 04:10:09", "force": True},
"sports_p": {"time": "06/03/2022 04:10:09", "force": True}, "sports_p": {"time": "06/03/2022 04:10:09", "force": True},
"sports_u": {"time": "06/03/2022 04:10:09", "force": True},"sports_t": {"time": "06/03/2022 04:10:09", "force": True}, "commodities": {"time": "06/03/2022 04:10:09", "force": True}, "indices": {"time": "06/03/2022 04:10:09", "force": True}, "movies": {"time": "06/03/2022 04:10:09", "force": True}, "ipo": {"time": "06/03/2022 04:10:09", "force": True}, "prepost": {"time": "06/03/2022 04:10:09", "force": True}} "sports_u": {"time": "06/03/2022 04:10:09", "force": True},"sports_t": {"time": "06/03/2022 04:10:09", "force": True}, "commodities": {"time": "06/03/2022 04:10:09", "force": True}, "indices": {"time": "06/03/2022 04:10:09", "force": True}, "movies": {"time": "06/03/2022 04:10:09", "force": True}, "ipo": {"time": "06/03/2022 04:10:09", "force": True}, "prepost": {"time": "06/03/2022 04:10:09", "force": True}}
try:
if last_updates['scheduler']['force']:
try:
f = open('csv/scheduler.json','r')
schedules = json.load(f)
shutdown_schedule = schedules['shutdown']['time']
reboot_schedule = schedules['reboot']['time']
timezone = schedules['timezone']
shutdown_enabled = schedules['shutdown']['enabled']
reboot_enabled = schedules['reboot']['enabled']
except:
shutdown_schedule = "00:00"
reboot_schedule = "00:00"
timezone = "GMT"
shutdown_enabled = False
reboot_enabled = False
except:
pass
#SHUTDOWN
try:
if datetime.now(pytz.timezone(timezone)).strftime("%H:%M") == shutdown_schedule and shutdown_enabled:
os.system('sudo shutdown now')
except:
pass
#REBOOT
try:
if datetime.now(pytz.timezone(timezone)).strftime("%H:%M") == reboot_schedule and reboot_enabled:
os.system('sudo reboot')
except:
pass
NY_time = datetime.now(NY_zone).replace(tzinfo=None) NY_time = datetime.now(NY_zone).replace(tzinfo=None)