Changeset - 8cab6a80215a
[Not reviewed]
default
0 3 1
drewp@bigasterisk.com - 20 months ago 2023-05-19 23:59:45
drewp@bigasterisk.com
asco cleanup, including a bugfix (rdflib dropped graph.label?)
4 files changed with 18 insertions and 7 deletions:
0 comments (0 inline, 0 general)
bin/ascoltami
Show inline comments
 
#!/bin/zsh
 
pnpm exec vite -c light9/ascoltami/vite.config.ts &
 
PYTHONPATH=`pwd` pdm run python light9/ascoltami/main.py
 
pdm run python light9/ascoltami/main.py
 
wait
light9/ascoltami/musictime_client.py
Show inline comments
 
import time, json, logging
 
from typing import Dict
 
from typing import Dict, cast
 
from twisted.internet.interfaces import IReactorTime
 

	
 
from twisted.internet import reactor
 
from twisted.internet.defer import inlineCallbacks
 
import treq
 

	
 
from light9 import networking
 
@@ -77,17 +78,17 @@ class MusicTime(object):
 
            # fraction of the way through)
 
            self.positionFetchTime = time.time()
 

	
 
            self.position = position
 
            self.onChange(position)
 

	
 
            reactor.callLater(self.period, self.pollMusicTime)
 
            cast(IReactorTime, reactor).callLater(self.period, self.pollMusicTime)
 

	
 
        def eb(err):
 
            log.warn("talking to ascoltami: %s", err.getErrorMessage())
 
            reactor.callLater(2, self.pollMusicTime)
 
            cast(IReactorTime, reactor).callLater(2, self.pollMusicTime)
 

	
 
        d = treq.get(networking.musicPlayer.path("time").toPython())
 
        d.addCallback(cb)
 
        d.addErrback(eb)  # note this includes errors in cb()
 

	
 
    def sendTime(self, t):
light9/ascoltami/webapp.py
Show inline comments
 
@@ -8,13 +8,13 @@ from typing import cast
 
import cyclone.web
 
import cyclone.websocket
 
from cycloneerr import PrettyErrorHandler
 
from light9.metrics import metricsRoute
 
from light9.namespaces import L9
 
from light9.showconfig import getSongsFromShow, showUri, songOnDisk
 
from rdflib import URIRef
 
from rdflib import RDFS, Graph, URIRef
 
from twisted.internet import reactor
 
from twisted.internet.interfaces import IReactorTime
 

	
 
log = logging.getLogger()
 
_songUris = {}  # locationUri : song
 

	
 
@@ -121,18 +121,26 @@ class timeStreamResource(cyclone.websock
 
        log.info("bye ws client %r: %s", self, reason)
 

	
 

	
 
class songs(PrettyErrorHandler, cyclone.web.RequestHandler):
 

	
 
    def get(self):
 
        graph = self.settings.app.graph
 
        graph = cast(Graph, self.settings.app.graph)
 

	
 
        songs = getSongsFromShow(graph, self.settings.app.show)
 

	
 
        self.set_header("Content-Type", "application/json")
 
        self.write(json.dumps({"songs": [{"uri": s, "path": graph.value(s, L9['showPath']), "label": graph.label(s)} for s in songs]}))
 
        self.write(json.dumps({
 
            "songs": [
 
                {  #
 
                    "uri": s,
 
                    "path": graph.value(s, L9['songFilename']),
 
                    "label": graph.value(s, RDFS.label)
 
                } for s in songs
 
            ]
 
        }))
 

	
 

	
 
class songResource(PrettyErrorHandler, cyclone.web.RequestHandler):
 

	
 
    def post(self):
 
        """post a uri of song to switch to (and start playing)"""
light9/ascoltami/webapp_test.py
Show inline comments
 
new file 100644
 
# todo
 
# test that GET /songs doesn't break, etc
0 comments (0 inline, 0 general)