示例#1
0
 def test_a_cal(self):
     r = cal()
     assert isinstance(r, dict)
     for day in r.keys():
         assert day.lower() in (x.lower() for x in BANGUMI_UPDATE_TIME)
         assert isinstance(r[day], list)
         for bangumi in r[day]:
             assert "status" in bangumi
             assert "subtitle_group" in bangumi
             assert "name" in bangumi
             assert "update_time" in bangumi
             assert "cover" in bangumi
示例#2
0

API_MAP_POST = {
    ACTION_ADD: add,
    ACTION_DELETE: delete,
    ACTION_SEARCH: search,
    ACTION_CONFIG: config,
    ACTION_DOWNLOAD: download_prepare,
    ACTION_AUTH: auth_,
    ACTION_MARK: mark,
    ACTION_STATUS: status_,
    ACTION_FILTER: filter_,
}

API_MAP_GET = {
    ACTION_CAL: lambda: {'data': cal()},
    ACTION_CONFIG: lambda: config(None, None)
}

NO_AUTH_ACTION = (ACTION_CAL, ACTION_AUTH)


def auth(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        if kwargs.get('action', None) in NO_AUTH_ACTION:
            return f(*args, **kwargs)

        token = args[0].request.headers.get('bgmi-token')
        if token == ADMIN_TOKEN:
            return f(*args, **kwargs)
示例#3
0
API_MAP_POST = {
    ACTION_ADD: add,
    ACTION_DELETE: delete,
    ACTION_SEARCH: search,
    ACTION_CONFIG: config,
    ACTION_DOWNLOAD: download_prepare,
    ACTION_AUTH: auth_,
    ACTION_MARK: mark,
    ACTION_STATUS: status_,
    ACTION_FILTER: filter_,
}

API_MAP_GET = {
    ACTION_CAL: lambda: {
        'data': cal()
    },
    ACTION_CONFIG: lambda: config(None, None)
}

NO_AUTH_ACTION = (ACTION_CAL, ACTION_AUTH)


def auth(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        if kwargs.get('action', None) in NO_AUTH_ACTION:
            return f(*args, **kwargs)

        token = args[0].request.headers.get('bgmi-token')
        if token == ADMIN_TOKEN:
示例#4
0
API_MAP_POST = {
    ACTION_ADD: add,
    ACTION_DELETE: delete,
    ACTION_SEARCH: search,
    ACTION_CONFIG: config,
    ACTION_DOWNLOAD: download_prepare,
    ACTION_AUTH: auth_,
    ACTION_MARK: mark,
    ACTION_STATUS: status_,
    ACTION_FILTER: filter_,
}  # type: Dict[str, Callable]

API_MAP_GET = {
    ACTION_CAL: lambda: {
        "data": cal()
    },
    ACTION_CONFIG: lambda: config(None, None),
}

NO_AUTH_ACTION = (ACTION_CAL, ACTION_AUTH)


def auth(f):  # type: ignore
    @functools.wraps(f)
    def wrapped(self: RequestHandler, *args: Any, **kwargs: Any) -> Any:
        if kwargs.get("action", None) in NO_AUTH_ACTION:
            return f(self, *args, **kwargs)

        token = self.request.headers.get("bgmi-token")
        if token == ADMIN_TOKEN:
示例#5
0
def cal_wrapper(ret: Any) -> None:
    force_update = ret.force_update
    today = ret.today
    save = not ret.no_save

    runner = ScriptRunner()
    cover = None  # type: Optional[List[str]]

    if ret.download_cover:
        cover = runner.get_download_cover()

    weekly_list = cal(force_update=force_update, save=save, cover=cover)

    def shift(seq: Tuple[str, ...], n: int) -> Tuple[str, ...]:
        n %= len(seq)
        return seq[n:] + seq[:n]

    order_without_unknown = BANGUMI_UPDATE_TIME[:-1]
    if today:
        weekday_order = (
            order_without_unknown[datetime.datetime.today().weekday()],
        )  # type: Tuple[str, ...]
    else:
        weekday_order = shift(order_without_unknown,
                              datetime.datetime.today().weekday())

    col = max(
        wcwidth.wcswidth(bangumi["name"]) for value in weekly_list.values()
        for bangumi in value)
    env_columns = col if os.environ.get("TRAVIS_CI",
                                        False) else get_terminal_col()

    if env_columns < col:
        print_warning("terminal window is too small.")
        env_columns = col

    row = int(env_columns / col if env_columns / col <= 3 else 3)

    def print_line() -> None:
        num = col - 3
        split = "-" * num + "   "
        print(split * row)

    for weekday in weekday_order + ("Unknown", ):
        if weekly_list[weekday.lower()]:
            print(
                "{}{}. {}".format(
                    GREEN,
                    weekday if not today else
                    f"Bangumi Schedule for Today ({weekday})",
                    COLOR_END,
                ),
                end="",
            )
            print()
            print_line()
            for i, bangumi in enumerate(weekly_list[weekday.lower()]):
                if (bangumi["status"] in (STATUS_UPDATED, STATUS_FOLLOWED)
                        and "episode" in bangumi):
                    bangumi["name"] = "{}({:d})".format(
                        bangumi["name"], bangumi["episode"])

                width = wcwidth.wcswidth(bangumi["name"])
                space_count = col - 2 - width

                for s in SPACIAL_APPEND_CHARS:
                    if s in bangumi["name"]:
                        space_count += bangumi["name"].count(s)

                for s in SPACIAL_REMOVE_CHARS:
                    if s in bangumi["name"]:
                        space_count -= bangumi["name"].count(s)

                if bangumi["status"] == STATUS_FOLLOWED:
                    bangumi["name"] = "{}{}{}".format(YELLOW, bangumi["name"],
                                                      COLOR_END)

                if bangumi["status"] == STATUS_UPDATED:
                    bangumi["name"] = "{}{}{}".format(GREEN, bangumi["name"],
                                                      COLOR_END)
                try:
                    print(" " + bangumi["name"], " " * space_count, end="")
                except UnicodeEncodeError:
                    continue

                if (i + 1) % row == 0 or i + 1 == len(
                        weekly_list[weekday.lower()]):
                    print()
            print()