This repository was archived by the owner on Jan 6, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountdown.py
More file actions
80 lines (63 loc) · 2.38 KB
/
countdown.py
File metadata and controls
80 lines (63 loc) · 2.38 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import sys
import time
import datetime
# File watching
from watchdog.events import PatternMatchingEventHandler
from watchdog.observers import Observer
# Configuration parsing
import configparser
config = configparser.ConfigParser()
config.read('countdown.ini', encoding="utf-8")
from rich.logging import RichHandler
from rich.console import Console
from rich import print
from rich.panel import Panel
console = Console()
FORMAT = "%(message)s"
logging.basicConfig(
level=config['debug']['loglevel'], format=FORMAT, datefmt="[%X]", handlers=[RichHandler()]
)
log = logging.getLogger("rich")
from obswebsocket import obsws, requests
#! (C)2020 Tibet Tornaci/oofdere. All rights reserved.
#* OBS Websocket Settings
obshost = config['obs-websockets']['host']
obsport = config['obs-websockets']['port']
obspass = str(config['obs-websockets']['password'])
obsinstance = obsws(obshost, obsport, obspass)
obsinstance.connect()
log.info("Connected to OBS!")
class MyEventHandler(PatternMatchingEventHandler):
def on_modified(self, event):
# open and read duration
fileduration = open("duration.txt", 'r', encoding="utf-8")
global t
t = int(float(fileduration.read()))
log.info(f"Update!")
if __name__ == '__main__':
path = "."
event_handler = MyEventHandler(patterns=['*duration.txt'])
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
log.info("Started Watchdog")
t = int(config['debug']['launchtime']) # initial countdown value used until song update
log.info("t initialized as " + str(t))
try:
starttime = time.time()
while True:
if t > 0:
obsinstance.call(requests.SetTextGDIPlusProperties("countdown", text=str(datetime.timedelta(seconds=int(t)))))
console.log(str(datetime.timedelta(seconds=int(t))), highlight=False)
t -= 1
else:
obsinstance.call(requests.SetTextGDIPlusProperties("countdown", text="0:00:00"))
log.error("DEAD AIR!")
time.sleep(1.0 - ((time.time() - starttime) % 1.0)) # sync to system clock
except KeyboardInterrupt:
observer.stop()
console.log(obsinstance.call(requests.SetTextGDIPlusProperties("countdown", text="")))
observer.join()