This repository has been archived by the owner on Oct 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tbn_schedule.py
80 lines (69 loc) · 2.03 KB
/
tbn_schedule.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
import os
import getpass
import sqlite3
from time import localtime, strftime
from datetime import date
import calendar
import time
user = getpass.getuser()
DEFAULTDIR = homedir
ACTIONLOG = homedir + "tbn_schedules.log"
try:
with open (ACTIONLOG, "r") as file:
log = file.read()
file.close()
except Exception:
with open (ACTIONLOG, "w+") as file:
file.write("File Opened\n")
file.close()
print ("Successfully created Log File.")
MYDB = DEFAULTDIR + "myplex.db"
sql = sqlite3.connect(MYDB)
cur = sql.cursor()
dte = date.today()
TODAY = str(calendar.day_name[dte.weekday()]).lower()
WEEKDAYS = ['monday','tuesday','wednesday','thursday','friday']
WEEKENDS = ['saturday','sunday']
thetime = strftime("%-I:%M %p", localtime())
#thetime = "4:46 PM"
if (thetime == "11:59 PM"):
cur.execute("DELETE FROM SCHEDULES WHERE day LIKE \"today\"")
sql.commit()
command = "SELECT * FROM SCHEDULES"
cur.execute(command)
if not cur.fetchall():
pass
else:
cur.execute(command)
found = cur.fetchall()
for item in found:
if item[1] == thetime:
actn = []
print (item[0])
actions = item[0]
actions = actions.split(";")
dcheck = item[2].lower()
if ("-x" in dcheck):
cur.execute("DELETE FROM SCHEDULES WHERE time LIKE \"" + thetime + "\" AND action LIKE \"" + str(item[0].strip()) + "\"")
sql.commit()
dcheck = dcheck.replace(" -x","")
if (((dcheck == "weekdays") and (TODAY in WEEKDAYS)) or ((dcheck == "weekends") and (TODAY in WEEKENDS))):
dcheck = TODAY
print dcheck
if ((dcheck == "today") or (dcheck == "everyday") or (dcheck == TODAY)):
for thing in actions:
if thing != "":
actn.append(thing)
for whatsit in actn:
if "wait " in whatsit:
num = whatsit.replace("wait ","")
num = int(num.strip())
#print ("sleeping " + str(num) + " seconds.")
time.sleep(num)
else:
action = "python " + DEFAULTDIR + "system.py " + whatsit + ""
print ("Executing: " + action)
os.system(action)
with open (ACTIONLOG, "a") as file:
file.write(str(item))
file.close()