Moved independent files to separate markup folder
This commit is contained in:
91
markup/bells.py
Executable file
91
markup/bells.py
Executable file
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from subprocess import Popen
|
||||
|
||||
from pydub import AudioSegment
|
||||
|
||||
bell1path = "res/wav/bellhit1.wav"
|
||||
bell2path = "res/wav/bellhit2.wav"
|
||||
bell3path = "res/wav/bellhit3.wav"
|
||||
bell4path = "res/wav/bellhit4.wav"
|
||||
bell5path = bell4path
|
||||
|
||||
g = AudioSegment.from_file(bell1path)
|
||||
e = AudioSegment.from_file(bell2path)
|
||||
f = AudioSegment.from_file(bell3path)
|
||||
b = AudioSegment.from_file(bell4path)
|
||||
e3 = AudioSegment.from_file(bell5path)
|
||||
|
||||
try:
|
||||
horn = AudioSegment.from_file("/home/pi/sound/traphorn.wav")
|
||||
except FileNotFoundError:
|
||||
horn = AudioSegment.empty()
|
||||
|
||||
phrase1 = [(g, .25), (f, .25), (e, .25), (b, .50)]
|
||||
phrase2 = [(e, .25), (g, .25), (f, .25), (b, .50)]
|
||||
phrase3 = [(e, .25), (f, .25), (g, .25), (e, .50)]
|
||||
phrase4 = [(g, .25), (e, .25), (f, .25), (b, .50)]
|
||||
phrase5 = [(b, .25), (f, .25), (g, .25), (e, .50)]
|
||||
rest = [(AudioSegment.empty(), .50)]
|
||||
strike = [(e3, .75)]
|
||||
trap_horn = [(horn, 0)]
|
||||
|
||||
whole_time = 3000
|
||||
|
||||
|
||||
def chime_length(chime):
|
||||
return sum(c[1] for c in chime) * whole_time + len(chime[-1][0])
|
||||
|
||||
|
||||
def play(audio):
|
||||
audio.export('/tmp/clock_chime.wav', 'wav')
|
||||
Popen(['aplay', '/tmp/clock_chime.wav', '-q'])
|
||||
|
||||
|
||||
def play_phrase(phrase):
|
||||
audio = AudioSegment.silent(chime_length(phrase))
|
||||
time = 0
|
||||
|
||||
for a, t in phrase:
|
||||
audio = audio.overlay(a, int(time))
|
||||
time += t * whole_time
|
||||
|
||||
play(audio)
|
||||
|
||||
|
||||
last_chime = None
|
||||
|
||||
|
||||
def play_chime(hour, minute):
|
||||
global last_chime
|
||||
this_chime = hour, minute
|
||||
if last_chime == this_chime:
|
||||
return
|
||||
last_chime = this_chime
|
||||
|
||||
chime = []
|
||||
|
||||
if hour == 16 and minute == 20:
|
||||
chime = trap_horn
|
||||
|
||||
if minute == 15:
|
||||
chime = phrase1
|
||||
if minute == 30:
|
||||
chime = phrase2 + phrase3
|
||||
if minute == 45:
|
||||
chime = phrase4 + phrase5 + phrase1
|
||||
if minute == 0:
|
||||
if hour > 12:
|
||||
hour -= 12
|
||||
if hour == 0:
|
||||
hour = 12
|
||||
chime = phrase2 + phrase3 + phrase4 + phrase5 + rest + strike * hour
|
||||
|
||||
if not chime:
|
||||
return
|
||||
|
||||
play_phrase(chime)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
play_chime(2, 00)
|
||||
62
markup/clock.json
Normal file
62
markup/clock.json
Normal file
@@ -0,0 +1,62 @@
|
||||
[
|
||||
{
|
||||
"surf": "panel_script::time",
|
||||
"anchor": "0.5, 0.4",
|
||||
"args": {
|
||||
"size": 360
|
||||
}
|
||||
},
|
||||
{
|
||||
"surf": "1280 500",
|
||||
"anchor": "0.5,0.4",
|
||||
"position": "0 250",
|
||||
"children": [
|
||||
{
|
||||
"surf": "panel_script::time",
|
||||
"args": {
|
||||
"fmt": "%A, %B %d",
|
||||
"size": 60
|
||||
},
|
||||
"position": "0 -60",
|
||||
"anchor": ".5 .5"
|
||||
},
|
||||
{
|
||||
"surf": "panel_script::image",
|
||||
"args": {
|
||||
"path": "'res/png/'+str(get_weather().current_conditions.icon)+'.png'",
|
||||
"do_eval": true
|
||||
},
|
||||
"position": "0 80",
|
||||
"anchor": ".5 .5",
|
||||
"pivot": "1 .5"
|
||||
},
|
||||
{
|
||||
"surf": "panel_script::weather",
|
||||
"args": {
|
||||
"fmt": "{current_conditions.temperature}\u00b0{units.temperature}"
|
||||
},
|
||||
"position": "0 80",
|
||||
"anchor": ".5 .5",
|
||||
"pivot": "0 .5"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"surf": "1280 100",
|
||||
"children": [
|
||||
{
|
||||
"surf": "panel_script::header",
|
||||
"anchor": ".5 .5"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"surf": "panel_script::weather",
|
||||
"args": {
|
||||
"fmt": "Weather updated {current_conditions.last_updated}",
|
||||
"size": 30
|
||||
},
|
||||
"anchor": ".5 1",
|
||||
"position": "0 -20"
|
||||
}
|
||||
]
|
||||
55
markup/countdown.py
Executable file
55
markup/countdown.py
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import datetime
|
||||
import os
|
||||
|
||||
import timestring
|
||||
|
||||
|
||||
class Event(object):
|
||||
def __init__(self, date, label):
|
||||
self.label = label
|
||||
self.date = date
|
||||
|
||||
@property
|
||||
def time(self):
|
||||
r = timestring.Date(self.date).date - timestring.now().date # type: datetime.timedelta
|
||||
s = int(r.seconds)
|
||||
m, s = s // 60, s % 60
|
||||
h, m = m // 60, m % 60
|
||||
d, h = r.days, h % 25
|
||||
return {'days': d, 'hours': h, 'minutes': m, 'seconds': s, 'label': self.label}
|
||||
|
||||
def __format__(self, format_spec):
|
||||
return format_spec.format(**self.time)
|
||||
|
||||
def __str__(self):
|
||||
return format(self, '{days}d {hours}h {minutes}m {seconds}s to {label}')
|
||||
|
||||
|
||||
__events = []
|
||||
__event_load = 0
|
||||
|
||||
|
||||
def update_events(force=False):
|
||||
global __events, __event_load
|
||||
|
||||
event_time = os.stat('markup/events.txt').st_mtime_ns
|
||||
if force or __event_load != event_time:
|
||||
with open('markup/events.txt') as f:
|
||||
etext = [tuple(i.strip() for i in l.split('|')) for l in f.readlines() if
|
||||
l.strip() and not l.startswith('#')]
|
||||
__events = [Event(date, lbl) for lbl, date in etext]
|
||||
__event_load = event_time
|
||||
|
||||
|
||||
def get_events(force_update=False):
|
||||
update_events(force_update)
|
||||
|
||||
return __events
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(timestring.now())
|
||||
for e in get_events():
|
||||
print(e)
|
||||
8
markup/events.txt
Executable file
8
markup/events.txt
Executable file
@@ -0,0 +1,8 @@
|
||||
# datetime | event name
|
||||
# space before and after | omitted
|
||||
|
||||
Solar Eclipse | 8/21/2017 2:46:22PM
|
||||
Untrump | 1/20/2021 9:00AM
|
||||
Move-out | 5/12/2017 noon
|
||||
|
||||
# Dinner Tomorrow | Tomorrow 6:30pm
|
||||
76
markup/panel_script.py
Normal file
76
markup/panel_script.py
Normal file
@@ -0,0 +1,76 @@
|
||||
from datetime import datetime
|
||||
|
||||
import pygame
|
||||
|
||||
from markup.countdown import get_events
|
||||
from panel import Panel
|
||||
from wxget import get_weather
|
||||
|
||||
pygame.font.init()
|
||||
|
||||
WHITE = (255, 255, 255)
|
||||
GRAY = (175, 175, 175)
|
||||
BLACK = (0, 0, 0)
|
||||
|
||||
|
||||
class Font(object):
|
||||
def __init__(self, name):
|
||||
self.file = name
|
||||
self.fonts = {}
|
||||
|
||||
def __getitem__(self, size):
|
||||
if size not in self.fonts:
|
||||
self.fonts[size] = pygame.font.Font(self.file, size)
|
||||
return self.fonts[size]
|
||||
|
||||
|
||||
roboto = Font('res/RobotoSlab-Regular.ttf')
|
||||
|
||||
|
||||
def __do_eval(t):
|
||||
try:
|
||||
return eval(t)
|
||||
except:
|
||||
return t
|
||||
|
||||
|
||||
def text(size=60, t="", do_eval=False):
|
||||
if do_eval:
|
||||
t = __do_eval(t)
|
||||
return roboto[size].render(t, True, WHITE)
|
||||
|
||||
|
||||
def time(size=60, fmt='%I:%M', strip='0'):
|
||||
return roboto[size].render(format(datetime.now(), fmt).lstrip(strip), True, WHITE)
|
||||
|
||||
|
||||
def weather(size=60, fmt='{current_conditions.temperature}\u00b0'):
|
||||
return roboto[size].render(fmt.format(**get_weather()), True, WHITE)
|
||||
|
||||
|
||||
def image(path="", do_eval=False):
|
||||
if do_eval:
|
||||
path = __do_eval(path)
|
||||
try:
|
||||
return pygame.image.load(path)
|
||||
except:
|
||||
return text(size=15, t=path)
|
||||
|
||||
|
||||
def header():
|
||||
es = get_events()
|
||||
|
||||
def item(i):
|
||||
f = roboto[30]
|
||||
e = es[i]
|
||||
l = e.label
|
||||
t = '{days}d {hours}h {minutes}m'.format(**e.time)
|
||||
|
||||
return Panel((1280 // len(es), 70), anchor=((i + 1) / (len(es) + 1), .5), children=[
|
||||
Panel(f.render(l, True, WHITE), anchor=(.5, .5), pivot=(.5, .9)),
|
||||
Panel(f.render(t, True, GRAY), anchor=(.5, .5), pivot=(.5, .1)),
|
||||
])
|
||||
|
||||
return Panel((1280, 70), anchor=(.5, .5), children=[
|
||||
item(i) for i in range(len(get_events()))
|
||||
]).surf
|
||||
Reference in New Issue
Block a user