Пример #1
0
async def dump_state():
    channel_state = {
        channel: [video.dump() for video in videos]
        for channel, videos in channel_list.items()
    }
    read_state = {"videos": [video.dump() for video in read_list]}

    await app.plugin_state.put(KVPair("youtube_live_state", channel_state))
    await app.plugin_state.put(KVPair("youtube_video_state", read_state))
Пример #2
0
async def load_state():
    global channel_list
    global read_list
    try:
        channel_state = await app.plugin_state.get("youtube_live_state")
    except KeyError:
        logging.warning("Missing live state dict. Ignoring.")
        channel_state = KVPair("youtube_live_state", {})
    try:
        read_state = await app.plugin_state.get("youtube_video_state")
    except KeyError:
        logging.warning("Missing video state dict. Ignoring.")
        read_state = KVPair("youtube_video_state", {"videos": []})

    for channel, videos in channel_state.value.items():
        for _video in videos:
            video = Video.load(_video)
            if await video.fetch() and not video.actual_start_time:
                logging.debug(f"Load saved broadcast: {video}")
                event_reminder = YoutubeEvent(type=video.type,
                                              event=YoutubeEventType.REMINDER,
                                              channel=channel,
                                              video=video)

                # set a reminder
                job_id = f"reminder_{channel}_{video.video_id}"
                reminder_time = video.scheduled_start_time - datetime.timedelta(
                    minutes=30)
                if reminder_time > datetime.datetime.now().replace(
                        tzinfo=tz.tzlocal()):
                    scheduler.add_job(partial(send_youtube_event,
                                              event_reminder),
                                      trigger="cron",
                                      id=job_id,
                                      year=reminder_time.year,
                                      month=reminder_time.month,
                                      day=reminder_time.day,
                                      hour=reminder_time.hour,
                                      minute=reminder_time.minute,
                                      second=reminder_time.second)
                channel_list[channel].append(video)

    read_list = [Video.load(video) for video in read_state.value["videos"]]
Пример #3
0
    async def delete(self, request: Request):
        table = get_table(request.path_params["table"])

        key = request.path_params["prime_key"]
        try:
            await table.get(key)
        except KeyError:
            return PlainTextResponse("Not Found",
                                     status_code=HTTP_404_NOT_FOUND)

        await table.delete(KVPair(key, {}))
        return Response()
Пример #4
0
    async def post(self, request: Request):
        try:
            table = get_table(request.path_params["table"])
        except KeyError:
            return PlainTextResponse("Not Found",
                                     status_code=HTTP_404_NOT_FOUND)

        key = (await request.body()).decode("utf-8")
        try:
            await table.get(key)
        except KeyError:
            await table.put(KVPair(key, {}))
            return RedirectResponse(url=urljoin(
                app.credentials.get("base_url"), key),
                                    status_code=HTTP_201_CREATED)

        return PlainTextResponse("Conflict", status_code=HTTP_409_CONFLICT)
Пример #5
0
async def bilibili_setup():
    try:
        await app.plugin_state.get("bilibili_since")
    except KeyError:
        await app.plugin_state.put(KVPair("bilibili_since", {}))
Пример #6
0
async def twitter_startup():
    try:
        await app.plugin_state.get("twitter_since")
    except KeyError:
        await app.plugin_state.put(KVPair("twitter_since", {}))