mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-03 05:34:23 -04:00
Listen to watch status events to call simkl
This commit is contained in:
parent
c6f12ab2a8
commit
e1f889f862
@ -1,17 +1,24 @@
|
|||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import pika
|
import pika
|
||||||
from pika import spec
|
from pika import spec
|
||||||
from pika.adapters.blocking_connection import BlockingChannel
|
from pika.adapters.blocking_connection import BlockingChannel
|
||||||
import pika.credentials
|
import pika.credentials
|
||||||
|
|
||||||
|
from autosync.services.simkl import Simkl
|
||||||
|
|
||||||
def callback(
|
# TODO: declare multiples services
|
||||||
|
service = Simkl()
|
||||||
|
|
||||||
|
|
||||||
|
def on_message(
|
||||||
ch: BlockingChannel,
|
ch: BlockingChannel,
|
||||||
method: spec.Basic.Deliver,
|
method: spec.Basic.Deliver,
|
||||||
properties: spec.BasicProperties,
|
properties: spec.BasicProperties,
|
||||||
body: bytes,
|
body: bytes,
|
||||||
):
|
):
|
||||||
print(f" [x] {method.routing_key}:{body}")
|
status = json.loads(body)
|
||||||
|
service.update(status.user, status.resource, status)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -31,5 +38,7 @@ def main():
|
|||||||
queue_name = result.method.queue
|
queue_name = result.method.queue
|
||||||
channel.queue_bind(exchange="events.watched", queue=queue_name, routing_key="#")
|
channel.queue_bind(exchange="events.watched", queue=queue_name, routing_key="#")
|
||||||
|
|
||||||
channel.basic_consume(queue=queue_name, on_message_callback=callback, auto_ack=True)
|
channel.basic_consume(
|
||||||
|
queue=queue_name, on_message_callback=on_message, auto_ack=True
|
||||||
|
)
|
||||||
channel.start_consuming()
|
channel.start_consuming()
|
||||||
|
20
autosync/autosync/models/message.py
Normal file
20
autosync/autosync/models/message.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
from autosync.models.episode import Episode
|
||||||
|
from autosync.models.movie import Movie
|
||||||
|
from autosync.models.show import Show
|
||||||
|
from autosync.models.user import User
|
||||||
|
from autosync.models.watch_status import WatchStatus
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class WatchStatusMessage(WatchStatus):
|
||||||
|
user: User
|
||||||
|
resource: Movie | Show | Episode
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Message:
|
||||||
|
action: str
|
||||||
|
type: str
|
||||||
|
value: WatchStatusMessage
|
Loading…
x
Reference in New Issue
Block a user