コード例 #1
0
ファイル: controllers.py プロジェクト: RicterZ/BGmi
def add(name, episode=None):
    """
    ret.name :str
    """
    # action add
    # add bangumi by a list of bangumi name
    # result = {}
    logger.debug('add name: {} episode: {}'.format(name, episode))
    if not Bangumi.get_updating_bangumi():
        website.fetch(save=True, group_by_weekday=False)

    try:
        bangumi_obj = Bangumi.fuzzy_get(name=name)
    except Bangumi.DoesNotExist:
        result = {'status': 'error',
                  'message': '{0} not found, please check the name'.format(name)}
        return result
    followed_obj, this_obj_created = Followed.get_or_create(bangumi_name=bangumi_obj.name,
                                                            defaults={'status': STATUS_FOLLOWED})
    if not this_obj_created:
        if followed_obj.status == STATUS_FOLLOWED:
            result = {'status': 'warning', 'message': '{0} already followed'.format(bangumi_obj.name)}
            return result
        else:
            followed_obj.status = STATUS_FOLLOWED
            followed_obj.save()

    Filter.get_or_create(bangumi_name=name)

    bangumi_data, _ = website.get_maximum_episode(bangumi_obj, subtitle=False, max_page=MAX_PAGE)
    followed_obj.episode = bangumi_data['episode'] if episode is None else episode
    followed_obj.save()
    result = {'status': 'success', 'message': '{0} has been followed'.format(bangumi_obj.name)}
    logger.debug(result)
    return result
コード例 #2
0
ファイル: controllers.py プロジェクト: RicterZ/BGmi
def filter_(name, subtitle=None, include=None, exclude=None, regex=None):
    result = {'status': 'success', 'message': ''}
    try:
        bangumi_obj = Bangumi.fuzzy_get(name=name)
    except Bangumi.DoesNotExist:
        result['status'] = 'error'
        result['message'] = 'Bangumi {0} does not exist.'.format(name)
        return result

    try:
        Followed.get(bangumi_name=bangumi_obj.name)
    except Followed.DoesNotExist as exc:
        result['status'] = 'error'
        result['message'] = 'Bangumi {name} has not subscribed, try \'bgmi add "{name}"\'.' \
            .format(name=bangumi_obj.name)
        return result

    followed_filter_obj, is_this_obj_created = Filter.get_or_create(bangumi_name=name)

    if is_this_obj_created:
        followed_filter_obj.save()

    if subtitle is not None:
        subtitle = [s.strip() for s in subtitle.split(',')]
        subtitle = [s['id'] for s in Subtitle.get_subtitle_by_name(subtitle)]
        subtitle_list = [s.split('.')[0] for s in bangumi_obj.subtitle_group.split(', ') if '.' in s]
        subtitle_list.extend(bangumi_obj.subtitle_group.split(', '))
        subtitle = filter(lambda s: s in subtitle_list, subtitle)
        subtitle = ', '.join(subtitle)
        followed_filter_obj.subtitle = subtitle

    if include is not None:
        followed_filter_obj.include = include

    if exclude is not None:
        followed_filter_obj.exclude = exclude

    if regex is not None:
        followed_filter_obj.regex = regex

    followed_filter_obj.save()
    subtitle_list = list(map(lambda s: s['name'],
                             Subtitle.get_subtitle_by_id(bangumi_obj.subtitle_group.split(', '))))

    result['data'] = {
        'name': name,
        'subtitle_group': subtitle_list,
        'followed': list(map(lambda s: s['name'], Subtitle.get_subtitle_by_id(followed_filter_obj.subtitle.split(', ')))
                         if followed_filter_obj.subtitle else []),
        'include': followed_filter_obj.include,
        'exclude': followed_filter_obj.exclude,
        'regex': followed_filter_obj.regex,
    }
    logger.debug(result)
    return result
コード例 #3
0
ファイル: controllers.py プロジェクト: rayyouxinsheng/BGmi
def add(name, episode=None):
    """
    ret.name :str
    """
    # action add
    # add bangumi by a list of bangumi name
    # result = {}
    logger.debug('add name: {} episode: {}'.format(name, episode))
    if not Bangumi.get_updating_bangumi():
        website.fetch(save=True, group_by_weekday=False)

    try:
        bangumi_obj = Bangumi.fuzzy_get(name=name)
    except Bangumi.DoesNotExist:
        result = {
            'status': 'error',
            'message': '{0} not found, please check the name'.format(name)
        }
        return result
    followed_obj, this_obj_created = Followed.get_or_create(
        bangumi_name=bangumi_obj.name, defaults={'status': STATUS_FOLLOWED})
    if not this_obj_created:
        if followed_obj.status == STATUS_FOLLOWED:
            result = {
                'status': 'warning',
                'message': '{0} already followed'.format(bangumi_obj.name)
            }
            return result
        else:
            followed_obj.status = STATUS_FOLLOWED
            followed_obj.save()

    Filter.get_or_create(bangumi_name=name)

    bangumi_data, _ = website.get_maximum_episode(bangumi_obj,
                                                  subtitle=False,
                                                  max_page=MAX_PAGE)
    followed_obj.episode = bangumi_data[
        'episode'] if episode is None else episode
    followed_obj.save()
    result = {
        'status': 'success',
        'message': '{0} has been followed'.format(bangumi_obj.name)
    }
    logger.debug(result)
    return result
コード例 #4
0
ファイル: controllers.py プロジェクト: Trim21/BGmi
def add(name: str, episode: int = None) -> ControllerResult:
    """
    ret.name :str
    """
    # action add
    # add bangumi by a list of bangumi name
    logger.debug("add name: %s episode: %d", name, episode)
    if not Bangumi.get_updating_bangumi():
        website.fetch(save=True, group_by_weekday=False)

    try:
        bangumi_obj = Bangumi.fuzzy_get(name=name)
    except Bangumi.DoesNotExist:
        result = {
            "status": "error",
            "message": f"{name} not found, please check the name",
        }
        return result
    followed_obj, this_obj_created = Followed.get_or_create(
        bangumi_name=bangumi_obj.name, defaults={"status": STATUS_FOLLOWED})
    if not this_obj_created:
        if followed_obj.status == STATUS_FOLLOWED:
            result = {
                "status": "warning",
                "message": f"{bangumi_obj.name} already followed",
            }
            return result
        else:
            followed_obj.status = STATUS_FOLLOWED
            followed_obj.save()

    Filter.get_or_create(bangumi_name=name)

    max_episode, _ = website.get_maximum_episode(bangumi_obj,
                                                 max_page=int(MAX_PAGE))
    followed_obj.episode = max_episode if episode is None else episode

    followed_obj.save()
    result = {
        "status": "success",
        "message": f"{bangumi_obj.name} has been followed",
    }
    logger.debug(result)
    return result
コード例 #5
0
ファイル: controllers.py プロジェクト: rayyouxinsheng/BGmi
def filter_(name, subtitle=None, include=None, exclude=None, regex=None):
    result = {'status': 'success', 'message': ''}
    try:
        bangumi_obj = Bangumi.fuzzy_get(name=name)
    except Bangumi.DoesNotExist:
        result['status'] = 'error'
        result['message'] = 'Bangumi {0} does not exist.'.format(name)
        return result

    try:
        Followed.get(bangumi_name=bangumi_obj.name)
    except Followed.DoesNotExist as exc:
        result['status'] = 'error'
        result['message'] = 'Bangumi {name} has not subscribed, try \'bgmi add "{name}"\'.' \
            .format(name=bangumi_obj.name)
        return result

    followed_filter_obj, is_this_obj_created = Filter.get_or_create(
        bangumi_name=name)

    if is_this_obj_created:
        followed_filter_obj.save()

    if subtitle is not None:
        subtitle = [s.strip() for s in subtitle.split(',')]
        subtitle = [s['id'] for s in Subtitle.get_subtitle_by_name(subtitle)]
        subtitle_list = [
            s.split('.')[0] for s in bangumi_obj.subtitle_group.split(', ')
            if '.' in s
        ]
        subtitle_list.extend(bangumi_obj.subtitle_group.split(', '))
        subtitle = filter(lambda s: s in subtitle_list, subtitle)
        subtitle = ', '.join(subtitle)
        followed_filter_obj.subtitle = subtitle

    if include is not None:
        followed_filter_obj.include = include

    if exclude is not None:
        followed_filter_obj.exclude = exclude

    if regex is not None:
        followed_filter_obj.regex = regex

    followed_filter_obj.save()
    subtitle_list = list(
        map(
            lambda s: s['name'],
            Subtitle.get_subtitle_by_id(
                bangumi_obj.subtitle_group.split(', '))))

    result['data'] = {
        'name':
        name,
        'subtitle_group':
        subtitle_list,
        'followed':
        list(
            map(
                lambda s: s['name'],
                Subtitle.
                get_subtitle_by_id(followed_filter_obj.subtitle.split(', ')
                                   )) if followed_filter_obj.subtitle else []),
        'include':
        followed_filter_obj.include,
        'exclude':
        followed_filter_obj.exclude,
        'regex':
        followed_filter_obj.regex,
    }
    logger.debug(result)
    return result
コード例 #6
0
def filter_(name, subtitle=None, include=None, exclude=None, regex=None):
    result = {"status": "success", "message": ""}
    try:
        bangumi_obj = Bangumi.fuzzy_get(name=name)
    except Bangumi.DoesNotExist:
        result["status"] = "error"
        result["message"] = "Bangumi {} does not exist.".format(name)
        return result

    try:
        Followed.get(bangumi_name=bangumi_obj.name)
    except Followed.DoesNotExist as exc:
        result["status"] = "error"
        result[
            "message"] = "Bangumi {name} has not subscribed, try 'bgmi add \"{name}\"'.".format(
                name=bangumi_obj.name)
        return result

    followed_filter_obj, is_this_obj_created = Filter.get_or_create(
        bangumi_name=name)

    if is_this_obj_created:
        followed_filter_obj.save()

    if subtitle is not None:
        subtitle = [s.strip() for s in subtitle.split(",")]
        subtitle = [s["id"] for s in Subtitle.get_subtitle_by_name(subtitle)]
        subtitle_list = [
            s.split(".")[0] for s in bangumi_obj.subtitle_group.split(", ")
            if "." in s
        ]
        subtitle_list.extend(bangumi_obj.subtitle_group.split(", "))
        subtitle = filter(lambda s: s in subtitle_list, subtitle)
        subtitle = ", ".join(subtitle)
        followed_filter_obj.subtitle = subtitle

    if include is not None:
        followed_filter_obj.include = include

    if exclude is not None:
        followed_filter_obj.exclude = exclude

    if regex is not None:
        followed_filter_obj.regex = regex

    followed_filter_obj.save()
    subtitle_list = list(
        map(
            lambda s: s["name"],
            Subtitle.get_subtitle_by_id(
                bangumi_obj.subtitle_group.split(", ")),
        ))

    result["data"] = {
        "name":
        name,
        "subtitle_group":
        subtitle_list,
        "followed":
        list(
            map(
                lambda s: s["name"],
                Subtitle.
                get_subtitle_by_id(followed_filter_obj.subtitle.split(", ")),
            ) if followed_filter_obj.subtitle else []),
        "include":
        followed_filter_obj.include,
        "exclude":
        followed_filter_obj.exclude,
        "regex":
        followed_filter_obj.regex,
    }
    logger.debug(result)
    return result
コード例 #7
0
ファイル: controllers.py プロジェクト: Trim21/BGmi
def filter_(
    name: str,
    subtitle: Optional[str] = None,
    include: Optional[str] = None,
    exclude: Optional[str] = None,
    regex: Optional[str] = None,
) -> ControllerResult:
    result = {"status": "success", "message": ""}  # type: Dict[str, Any]
    try:
        bangumi_obj = Bangumi.fuzzy_get(name=name)
    except Bangumi.DoesNotExist:
        result["status"] = "error"
        result["message"] = f"Bangumi {name} does not exist."
        return result

    try:
        Followed.get(bangumi_name=bangumi_obj.name)
    except Followed.DoesNotExist:
        result["status"] = "error"
        result[
            "message"] = "Bangumi {name} has not subscribed, try 'bgmi add \"{name}\"'.".format(
                name=bangumi_obj.name)
        return result

    followed_filter_obj, is_this_obj_created = Filter.get_or_create(
        bangumi_name=bangumi_obj.name)

    if is_this_obj_created:
        followed_filter_obj.save()

    if subtitle is not None:
        _subtitle = [s.strip() for s in subtitle.split(",")]
        _subtitle = [s["id"] for s in Subtitle.get_subtitle_by_name(_subtitle)]
        subtitle_list = [
            s.split(".")[0] for s in bangumi_obj.subtitle_group.split(", ")
            if "." in s
        ]
        subtitle_list.extend(bangumi_obj.subtitle_group.split(", "))
        followed_filter_obj.subtitle = ", ".join(
            filter(lambda s: s in subtitle_list, _subtitle))

    if include is not None:
        followed_filter_obj.include = include

    if exclude is not None:
        followed_filter_obj.exclude = exclude

    if regex is not None:
        followed_filter_obj.regex = regex

    followed_filter_obj.save()
    subtitle_list = [
        s["name"] for s in Subtitle.get_subtitle_by_id(
            bangumi_obj.subtitle_group.split(", "))
    ]

    result["data"] = {
        "name":
        bangumi_obj.name,
        "subtitle_group":
        subtitle_list,
        "followed": [
            s["name"] for s in Subtitle.get_subtitle_by_id(
                followed_filter_obj.subtitle.split(", "))
        ] if followed_filter_obj.subtitle else [],
        "include":
        followed_filter_obj.include,
        "exclude":
        followed_filter_obj.exclude,
        "regex":
        followed_filter_obj.regex,
    }
    logger.debug(result)
    return result