-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuardian_2_0.py
More file actions
29 lines (26 loc) · 871 Bytes
/
Guardian_2_0.py
File metadata and controls
29 lines (26 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import request
import os
import time
def guardian():
today = requests.get("http://just-the-time.appspot.com").text.split()[0] + "\n" # dzisiejszą datę pobieram z zewnątrz
with open("newFile.txt", "a+") as file:
file.seek(0)
file.write(today)
data = file.readlines()[-1:-3:-1]
if data[0] == data[1] == today:
os.system('"' + "shutdown /s /f /t 60" + '"')
else:
os.system('"' + "shutdown /s /f /t 3660" + '"')
def sprawdz_polaczenie():
"""Sprawdza czy jest połączenie z internetem"""
try:
requests.get('http://www.google.com', timeout=3)
return True
except requests.exceptions.RequestException:
return False
while True:
if sprawdz_polaczenie():
guardian()
break
else:
time.sleep(5) # przy braku połączenia czekam 5 sekund