Skip to content

✨ Add abstraction #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions fastcrawler/core/contracts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from abc import ABC, abstractmethod


class ProcessItem(ABC):

@property
def instances(self) -> list["ProcessItem"]:
if not hasattr(self, "_instances"):
self._instances = [self]
return self._instances

def __rshift__(self, other: "ProcessItem") -> "ProcessItem":
"""
leveraged RSHIFT method for magic in flow >>
objA >> objB >> objC >> objD
"""
self.instances.append(other)
setattr(other, "instances", self.instances)
return other

@abstractmethod
async def start(self):
...

3 changes: 2 additions & 1 deletion fastcrawler/core/spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
from fastcrawler.parsers.schema import BaseModel
from fastcrawler.utils.injection import _Depends

from .contracts import ProcessItem

class Spider:
class Spider(ProcessItem):
"""
Spider class to create the actual spider interface
so that configuration of each spider can be given
Expand Down