-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_ok.py
52 lines (40 loc) · 1.26 KB
/
update_ok.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
import os
import sqlite3
from datetime import datetime
from datetime import timedelta
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
# Connect to db
conn = sqlite3.connect("db/events.db")
c = conn.cursor()
# Get time interval
now = datetime.now()
in_hour = now + timedelta(hours=1)
# Fetch all events happening in the next hour
c.execute("SELECT name, date FROM events WHERE date BETWEEN ? AND ?;", (now, in_hour))
# Get all the events
res = c.fetchall()
# Check if any events going on
if len(res) > 0:
print(f"{bcolors.FAIL}=== UPDATE UNSAFE ==={bcolors.ENDC}", "")
# Ask if pull and pull if ok
else:
answer = input(f"{bcolors.OKGREEN}Update is ok. Pull?{bcolors.ENDC} [Y/n] ").lower()
if answer in ["yes", "y", ""]:
print(f"{bcolors.OKBLUE}=== Pulling ==={bcolors.ENDC}")
os.system("git pull")
elif answer not in ["n", "no"]:
print("Reply ambiguous, assuming no.")
# Print what went wrong
for event in res:
print(f"Event {bcolors.WARNING}{event[0]}{bcolors.ENDC} happening at {bcolors.WARNING}{event[1]}{bcolors.ENDC}")
# Close connection
conn.close()