-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23f23f4
commit 303848b
Showing
8 changed files
with
58 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from abc import ABC, abstractmethod | ||
from collections.abc import Iterable | ||
from typing import Optional | ||
|
||
|
||
class DataReader(ABC): | ||
@abstractmethod | ||
def read(self, num: Optional[int] = None) -> Iterable: | ||
pass | ||
|
||
|
||
class DataWriter(ABC): | ||
@abstractmethod | ||
def write(self, data: Iterable): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
"""Write and read intermediate data to/from a local database.""" | ||
|
||
from sync_crawler.store.lmdb_store import LmdbStore | ||
from .base_store import BaseStore as BaseStore | ||
from .lmdb_store import LmdbStore | ||
|
||
__all__ = ["LmdbStore"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,31 @@ | ||
import abc | ||
from abc import ABC, abstractmethod | ||
from collections.abc import Iterable | ||
from typing import Optional, override | ||
|
||
from sync_crawler.handlers import DataReader, DataWriter | ||
from sync_crawler.models import News | ||
|
||
|
||
class BaseStore(abc.ABC): | ||
"""Base class for store implementation.""" | ||
|
||
@abc.abstractmethod | ||
def put(self, news: Iterable[News]): | ||
"""Store data to storage. | ||
class BaseStore(DataReader, DataWriter, ABC): | ||
@override | ||
@abstractmethod | ||
def read(self, num: Optional[int] = None) -> Iterable[News]: | ||
"""Read data from store. | ||
Args: | ||
news: News to be stored. | ||
num: Number of data to read. Defaults to None, read all data. | ||
Returns: | ||
Iterable of News. | ||
""" | ||
raise NotImplementedError | ||
pass | ||
|
||
@abc.abstractmethod | ||
def pop(self, nums=1) -> Iterable[News]: | ||
"""Fetch data from store then delete them. | ||
@override | ||
@abstractmethod | ||
def write(self, news: Iterable[News]): | ||
"""Write data to store. | ||
Args: | ||
nums: Number of data to be popped. If the remaining data is less than `nums`, all | ||
remaining data will be popped. | ||
Returns: | ||
List of popped data. | ||
news: Iterable of News to be written. | ||
""" | ||
raise NotImplementedError | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
"""Store data to a host database.""" | ||
|
||
from sync_crawler.writer.chromadb_writer import ChromaDBWriter | ||
from sync_crawler.writer.mongodb_writer import MongoDBWriter | ||
from .base_writer import BaseWriter as BaseWriter | ||
from .chromadb_writer import ChromaDBWriter | ||
from .mongodb_writer import MongoDBWriter | ||
|
||
__all__ = ["ChromaDBWriter", "MongoDBWriter"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
import abc | ||
from abc import ABC, abstractmethod | ||
from collections.abc import Iterable | ||
from typing import Protocol | ||
from typing import Protocol, override | ||
|
||
from sync_crawler.handlers import DataWriter | ||
from sync_crawler.models import News | ||
|
||
|
||
class SupportsStr(Protocol): | ||
def __str__(self) -> str: ... | ||
|
||
|
||
class BaseWriter(abc.ABC): | ||
"""Base class for writer implementation.""" | ||
|
||
@abc.abstractmethod | ||
def put( | ||
class BaseWriter(DataWriter, ABC): | ||
@override | ||
@abstractmethod | ||
def write( | ||
self, | ||
ids: Iterable[SupportsStr], | ||
news: Iterable[News], | ||
news_with_id: Iterable[tuple[SupportsStr, News]], | ||
): | ||
"""Store data to storage. | ||
Args: | ||
ids: Object IDs of each news. | ||
news: News to be stored. | ||
news_with_id: Iterable of tuple of id and News. | ||
""" | ||
raise NotImplementedError | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters