Store

Memory runs through the entire process of script execution, helping you collect and store information during the script execution process

Implement Store

Before using Store, you need to implement a storage class that inherits from StoreBase and defines your own storage variables. When you implement the set method (or not), during script execution, if the return value of an action method is not null, the set method will be automatically called, with the method name and corresponding return value passed in.

import crawlipt as cpt
class Store(cpt.StoreBase):

    @check
    def __init__(self, is_replace: bool = False):
        """
        :param is_replace: need replace the value of method or not
        """
        self.is_replace = is_replace
        self.data = {}

    @check
    def set(self, method: str, value: Any) -> None:
        if method in self.data.keys():
            if self.is_replace:
                self.data[method] = value
            else:
                self.data[method].append(value)
            return
        if self.is_replace:
            self.data[method] = value
        else:
            self.data[method] = [value]

The above implementation is already built-in in crawlipt

Built-in Store object

Using Store

Store needs to be passed as a parameter in your own defined action or condition

Last updated