forked from grmpyktn11/FocusUp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (37 loc) · 1.38 KB
/
main.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import psutil
import time
import random
import http.client
import urllib
from config import token, user
from phrases import phrases
amountOfTime = float(input("How often do you want to be reminded (in minutes)? "))
#post request
conn = http.client.HTTPSConnection("api.pushover.net:443")
def sendNotif():
try:
conn.request("POST", "/1/messages.json",
urllib.parse.urlencode({
"token": token,
"user": user,
"message": phrases[random.randint(0, len(phrases) - 1)],
"title": "FocusUp!"
}), {"Content-type": "application/x-www-form-urlencoded"})
response = conn.getresponse()
# Wait for the response before reading it
while response.status == http.client.CONTINUE:
response = conn.getresponse()
# Check the response status
if response.status == 200:
print("Notification sent successfully.")
else:
print(f"Failed to send notification. Response status: {response.status}")
except Exception as e:
print(f"An error occurred during the HTTP request: {e}")
finally:
conn.close()
while True:
vscIsRunning = ('Code.exe' in (i.name() for i in psutil.process_iter()) )
if vscIsRunning:
sendNotif()
time.sleep(amountOfTime * 60)