This commit is contained in:
unknown 2024-09-12 19:26:24 +02:00 committed by draxaris1010
parent 64d8012945
commit 4fc9c9db41
4 changed files with 63 additions and 9 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
venv
last_quotes.json
denylist.py
__pycache__

5
autostart.desktop Normal file
View file

@ -0,0 +1,5 @@
[Desktop Entry]
Type=Application
Name=Quotes
Exec=alacritty -e ~/quotes_display/start.sh
Hidden=true

View file

@ -1,13 +1,46 @@
from rich.align import Align
from rich.console import Console
from rich.layout import Layout
from rich.live import Live
from rich.text import Text
from rich.padding import Padding
import time
import requests
from rich.text import Text
import json
import random
import requests
import time
quotes = requests.get('https://mattermore.zeus.gent/quotes.json').json()
from denylist import get_deny_list
denylist = get_deny_list()
def refresh_quotes():
res = None
try:
# Fetch quotes
res = requests.get('https://mattermore.zeus.gent/quotes.json').json()
assert len(res) > 100
res = res[-100:]
except:
pass
if res is None:
# Fallback: load last quotes
try:
with open('last_quotes.json') as f:
res = json.load(f)
except:
assert False, "Failed to fetch quotes, and failed to load fallback json"
else:
try:
# Fetched successfully
# Save to disk for the fallback
with open('last_quotes.json', 'w') as f:
json.dump(res, f)
except:
pass
# Only keep non-denied quotes
res = [q for q in res if not any(denied in q['quote'] for denied in denylist)]
return res
def render_quote(quote):
for i in range(len(quote['quote'])):
@ -19,9 +52,17 @@ def render_quote(quote):
)
yield l
with Live(Layout(Align.center(Text("Yeet"), vertical="middle")), refresh_per_second=30) as live:
with Live(
renderable=Layout(Align.center(Text("Yeet"), vertical="middle")),
console=Console(highlighter=None),
refresh_per_second=30
) as live:
first_it = True
while True:
for q in render_quote(random.choice(quotes[-100:])):
quotes = refresh_quotes()
for _ in range(500):
for q in render_quote(random.choice(quotes) if not first_it else quotes[-1]):
live.update(q)
time.sleep(0.05)
time.sleep(30)
first_it = False

4
start.sh Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
cd $(dirname $(realpath $0))
. venv/bin/activate
python quotes.py