-
Notifications
You must be signed in to change notification settings - Fork 0
/
getdata.py
100 lines (84 loc) · 3.04 KB
/
getdata.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import csv
from applescript import asrun, asquote
import os
import subprocess, sys
import datetime
import time
import managedata
lol = []
def addData(li):
with open('/Users/r/PycharmProjects/focus-tracker/data.csv', 'a', newline='') as csvfile:
dwr = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
dwr.writerow(li)
endsupresstime = 0
while 1 > 0:
if time.time() >= endsupresstime:
endsupresstime = 0
time.sleep(.1)
fl = open("/Users/r/PycharmProjects/focus-tracker/communicate.txt", "r+")
# applescript = '''
# tell application "System Events"
# set processName to name of processes whose frontmost is true
# do shell script "echo " & processName
# end tell
# '''
# ret = asrun(applescript)
ret1 = os.popen("osascript -e 'tell application \"System Events\" to count every process whose name is \"zoom.us\"'").read().strip()
onzoom = "false"
if ret1 == "1":
onzoom = "true"
ret2 = os.popen("osascript -e 'tell application \"System Events\" to get name of application processes whose frontmost is true and visible is true'").read().strip()
ret3 = "no"
if ret2 == "Google Chrome":
ret3 = "yes"
if ret2 == "Shadow":
ret2 = "Xcode"
ret4 = "N/A"
if ret3 == "yes":
ret4 = os.popen("osascript -e 'tell application \"Google Chrome\" to return URL of active tab of front window'").read().strip()
ret5 = "N/A"
if ret3 == "yes":
ret5 = os.popen("osascript -e 'tell application \"Google Chrome\" to return title of active tab of front window'").read().strip()
import datetime
date_object = datetime.date.today()
from datetime import datetime
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
if endsupresstime != 0:
lol.append(["2", onzoom, ret2, ret3, ret4, ret5, date_object, current_time, " ", "Supressed"])
else:
lol.append(["2", onzoom, ret2, ret3, ret4, ret5, date_object, current_time, " ", "Not Supressed"])
if ret3 == "yes" and endsupresstime == 0:
managedata.tabulate()
if ret2 == "Discord" and endsupresstime == 0:
managedata.triggersequence()
if os.stat("/Users/r/PycharmProjects/focus-tracker/communicate.txt").st_size != 0:
inp = fl.readline().strip()
print(inp)
if inp == "1":
inp = fl.readline().strip()
print(inp)
fl.truncate(0)
fl.seek(0)
if inp == "Y":
for li in lol:
li[8] = "Yes"
addData(li)
lol.clear()
else:
for li in lol:
li[8] = "No"
addData(li)
lol.clear()
if inp == "2":
inp = fl.readline().strip()
print(inp)
fl.truncate(0)
fl.seek(0)
endsupresstime = time.time()+int(inp)*60
if now.second == 0:
for li in lol:
addData(li)
lol.clear()
fl.close()