Example #1
0
def update_index():
    for item in ItemInfo.poll_status_index(TaskStage.Fetching,
                                           TaskStatus.Queued,
                                           limit=config.limit.fetch):
        service = get_service(item.service)
        ItemInfo.set_status(item.service, item.item_id, TaskStage.Fetching,
                            TaskStatus.Pending)
        try:
            full_item = service.pull_item(IndexItem(item.service,
                                                    item.item_id))
        except Exception as err:
            traceback.print_exc()
            ItemInfo.set_status(item.service, item.item_id, TaskStage.Fetching,
                                TaskStatus.Queued)
        else:
            print(item, full_item)
            if full_item is None:
                ItemInfo.set_status(item.service, item.item_id,
                                    TaskStage.Fetching, TaskStatus.Failed)
            else:
                ItemInfo.add_item(full_item, [])
                ItemInfo.set_status(item.service, item.item_id,
                                    TaskStage.Downloading, TaskStatus.Queued)
        time.sleep(1)
    ItemInfo.abandon_tasks(TaskStage.Fetching, TaskStatus.Queued, 20,
                           TaskStage.Fetching, TaskStatus.Failed)
Example #2
0
def update_subs():
    config = load_config()
    for (stype, sfunc), service_type in subscribe_services.items():
        if stype not in config.api:
            continue
        service_conf = list(config.api[stype].values())[0]
        service = service_type(service_conf)
        for name, channels in SubscribeSource.get_subs(stype, sfunc):
            for item in service.subscribe_index(name):
                if not ItemInfo.exists(item.service, item.item_id):
                    ItemInfo.add_index(item, channels)
                    print(stype.value, sfunc, name, item)
                    ItemInfo.set_status(item.service, item.item_id,
                                        TaskStage.Fetching, TaskStatus.Queued)
            for item in service.subscribe_full(name):
                if not ItemInfo.exists(item.service, item.item_id):
                    ItemInfo.add_item(item, channels)
                    print(stype.value, sfunc, name, item)
                    ItemInfo.set_status(item.service, item.item_id,
                                        TaskStage.Downloading,
                                        TaskStatus.Queued)