MCPcopy Create free account
hub / github.com/WwwwwyDev/crawlipt / add_condition

Method add_condition

crawlipt/script.py:482–516  ·  view source on GitHub ↗

add your own condition

(func: callable)

Source from the content-addressed store, hash-verified

480
481 @staticmethod
482 def add_condition(func: callable) -> None:
483 """
484 add your own condition
485 """
486 if not callable(func):
487 raise ParamTypeError("func must be a callable")
488 if "driver" not in signature(func).parameters:
489 raise ParamTypeError("func must have a 'driver' parameter")
490 if "driver" in signature(func).parameters:
491 if not issubclass(signature(func).parameters["driver"].annotation, WebDriver):
492 raise ParamTypeError("the 'driver' parameter must be a subclass of WebDriver")
493 if "store" in signature(func).parameters:
494 if not issubclass(signature(func).parameters["store"].annotation, StoreBase):
495 raise ParamTypeError("the 'store' parameter must be a subclass of StoreBase")
496 if signature(func).parameters["driver"].annotation is not WebDriver:
497 raise ParamTypeError("the 'driver' parameter must be a WebDriver of selenium.")
498 if signature(func).return_annotation is not bool:
499 raise ParamTypeError("the return of func must be the type of bool.")
500 for name in signature(func).parameters.keys():
501 if name in ScriptProcess.__POP_KEY:
502 raise ParamTypeError(f"the parameter name: {name} conflicts with the keyword")
503 cnt = 0
504 if func.__name__ not in ScriptProcess.CONDITIONS:
505 cnt += 1
506 ScriptProcess.CONDITIONS[func.__name__] = func
507 func_bak = func
508 try:
509 func = func.__func__
510 except Exception:
511 pass
512 if "__crawlipt_func_name__" in func.__dict__:
513 cnt += 1
514 ScriptProcess.CONDITIONS[func.__crawlipt_func_name__] = func_bak
515 if not cnt:
516 raise ParamTypeError(f"Add failed")
517
518
519class Script(ScriptProcess):

Callers 1

test_loopMethod · 0.80

Calls 1

ParamTypeErrorClass · 0.85

Tested by 1

test_loopMethod · 0.64