Ejemplo n.º 1
0
    def test_check_login(self):
        client = self.new_client()
        user_cookie = anobbsclient.UserCookie(
            userhash="foo",
        )

        class Row(NamedTuple):
            policy: anobbsclient.options.LoginPolicy
            with_cookie: bool
            page_number: int
            expects_exception: bool
            expected_needs_login: bool

        gk_pn = client.get_thread_gatekeeper_page_number()

        for row in [
            Row("enforce", True, gk_pn, False, True),
            Row("enforce", True, gk_pn+1, False, True),
            Row("enforce", False, gk_pn, True, None),
            Row("enforce", False, gk_pn+1, True, None),
            Row("when_has_cookie", True, gk_pn, False, True),
            Row("when_has_cookie", True, gk_pn+1, False, True),
            Row("when_has_cookie", False, gk_pn, False, False),
            Row("when_has_cookie", False, gk_pn+1, True, None),
            Row("when_required", True, gk_pn, False, False),
            Row("when_required", True, gk_pn+1, False, True),
            Row("when_required", False, gk_pn, False, False),
            Row("when_required", False, gk_pn+1, True, None),
            Row("always_no", True, gk_pn, False, False),
            Row("always_no", True, gk_pn+1, True, None),
            Row("always_no", False, gk_pn, False, False),
            Row("always_no", False, gk_pn+1, True, None),
        ]:
            logging.debug(row)

            options = {
                "login_policy": row.policy,
            }
            if row.with_cookie:
                options["user_cookie"] = user_cookie

            if row.expects_exception:
                def fn(): return client.get_thread_page(
                    id=29556631,  # 无关。因为如果行为符合预期,将不会执行请求
                    page=row.page_number,
                    options=options,
                )
                self.assertRaises(anobbsclient.RequiresLoginException, fn)
            else:
                needs_login = client.thread_page_requires_login(
                    page=row.page_number,
                    options=options,
                )
                self.assertEqual(needs_login, row.expected_needs_login)
Ejemplo n.º 2
0
 def create_client(self) -> anobbsclient.Client:
     return anobbsclient.Client(
         user_agent=self.client_user_agent,
         host=self.host,
         appid=self.client_appid,
         default_request_options={
             'user_cookie':
             anobbsclient.UserCookie(userhash=self.user_userhash),
             'login_policy': 'when_required',
             'gatekeeper_page_number': 100,
         },
     )
Ejemplo n.º 3
0
 def case_gatekept():
     for (_, _, _) in create_walker(
         target=ReversalThreadWalkTarget(
             thread_id=29184693,
             gatekeeper_post_id=gatekeeper_post_id,
             start_page_number=101,
         ),
         client=client,
         options={
             "user_cookie": anobbsclient.UserCookie(
                 userhash="",  # 无效的饼干
             ),
         },
     ):
         assert(False)
Ejemplo n.º 4
0
    def test_request_options(self):
        client = self.new_client()

        self.assertEqual(client.has_cookie(), False)
        self.assertEqual(client.get_login_policy(), "when_required")
        self.assertEqual(
            client.get_thread_gatekeeper_page_number(), 100)
        self.assertEqual(client.get_uses_luwei_cookie_format(),
                         SimpleTest.luwei_cookie_expires)
        self.assertEqual(client.get_max_attempts(), 5)

        options = {
            "user_cookie": anobbsclient.UserCookie(
                userhash="foo",
            ),
        }
        self.assertEqual(client.get_user_cookie(options).userhash, "foo")
def main(args: List[str]):
    args: CollectArguments = parse_args(
        prog=args[0],
        args=args[1:],
        description="采集跑团版串",
        args_cls=CollectArguments,
    )
    assert(args.time_since.tzinfo != None)

    client = anobbsclient.Client(
        user_agent=args.user_agent,
        host=args.host,
        appid=args.appid,
        default_request_options={
            "user_cookie": anobbsclient.UserCookie(
                userhash=args.userhash,
            ),
        },
    )

    execute(args, client)
def main(args: List[str]):
    args: RunWorkflowArguments = parse_args(
        prog=args[0],
        args=args[1:],
        description="运行跑团版趋势工作流程",
        args_cls=RunWorkflowArguments,
        extra_args_fn=RunWorkflowArguments._parse_extra_args)

    logger = setup_aqt_logger(
        name="workflow",  # AQT = adnmb_quests_trend
        base_log_folder_path=args.base_log_folder_path,
        tz=args.time_zone,
    )

    logger.info(f"输入参数:{args}")

    client = anobbsclient.Client(
        user_agent=args.user_agent,
        host=args.host,
        appid=args.appid,
        default_request_options={
            "user_cookie": anobbsclient.UserCookie(userhash=args.userhash, ),
        },
    )

    logger.info(f"跑团版趋势工作流程:开始")
    sm = StepManager(logger)

    with sm.next("检查趋势串"):
        if args.trend_thread_id != None:
            (can_continue,
             quit_reason) = check_trend_thread(client, args.trend_thread_id)
            if not can_continue:
                raise QuitDueToTrendThreadRelatedIssueException(quit_reason)
        else:
            logger.info(f"未配置趋势串,跳过")

    now = datetime.now(tz=args.time_zone)
    if args.range in ("yesterday", "last-24-hours"):
        time_since = (now - timedelta(days=1))
        if args.range == "yesterday":
            time_since = time_since.replace(hour=0,
                                            minute=0,
                                            second=0,
                                            microsecond=0)
    else:
        raise ShouldNotReachException()

    with sm.next("采集跑团版"):
        collect_posts.execute(
            collect_posts.CollectArguments(
                board_id=args.board_id,
                db_file_path=args.db_file_path,
                base_log_folder_path=args.base_log_folder_path,
                metadata_folder_path=args.metadata_folder_path,
                user_agent=args.user_agent,
                host=args.host,
                appid=args.appid,
                userhash=args.userhash,
                time_zone=args.time_zone,
                time_since=time_since,
            ), client)

    logger.info(f"跑团版趋势工作流程:完成")
Ejemplo n.º 7
0
 def user_cookie(self) -> anobbsclient.UserCookie:
     assert(SimpleTest.user_hash != None)
     return anobbsclient.UserCookie(
         userhash=SimpleTest.user_hash,
     )
from src.dumppages import dump_page_range_back_to_front

sys.path.append(str(Path(__file__).parent.parent / "commons"))
from dumpedpages import PageInfo, get_page_info_list, get_page_ranges_for_dumping, get_page_name_and_status  # noqa: E402

HOST = os.environ["ANOBBS_HOST"]
USER_AGENT = os.environ["ANOBBS_CLIENT_ENVIRON"]
APPID = os.environ["ANOBBS_CLIENT_APPID"]
USERHASH = os.environ.get("ANOBBS_USERHASH", None)

client = anobbsclient.Client(
    user_agent=USER_AGENT,
    host=HOST,
    appid=APPID,
    default_request_options={
        "user_cookie": anobbsclient.UserCookie(userhash=USERHASH),
        "login_policy": "when_required",
        "gatekeeper_page_number": 100,
        "uses_luwei_cookie_format": {
            "expires": "Friday,24-Jan-2027 16:24:36 GMT",
        },
    },
)


def main(args: List[str]):
    logging.debug(f"args: {args}")
    args = parse_args(prog=args[0], args=args[1:])

    if args.dump_folder_path.exists():
        # 旧转存文件夹存在,检查串号前后是否一致