Skip to content

Commit

Permalink
decouple check connection from initialization method in reddit
Browse files Browse the repository at this point in the history
  • Loading branch information
rbiseck3 committed Nov 3, 2023
1 parent 92a6e85 commit 56d11e1
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions unstructured/ingest/connector/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from unstructured.ingest.logger import logger
from unstructured.utils import requires_dependencies

if t.TYPE_CHECKING:
from praw import Reddit


@dataclass
class SimpleRedditConfig(BaseConnectorConfig):
Expand Down Expand Up @@ -110,16 +113,23 @@ def version(self) -> t.Optional[str]:
@dataclass
class RedditSourceConnector(SourceConnectorCleanupMixin, BaseSourceConnector):
connector_config: SimpleRedditConfig
_reddit: t.Optional["Reddit"] = field(init=False, default=None)

@requires_dependencies(["praw"], extras="reddit")
def initialize(self):
@property
def reddit(self) -> "Reddit":
from praw import Reddit

self.reddit = Reddit(
client_id=self.connector_config.client_id,
client_secret=self.connector_config.client_secret,
user_agent=self.connector_config.user_agent,
)
if self._reddit is None:
self._reddit = Reddit(
client_id=self.connector_config.client_id,
client_secret=self.connector_config.client_secret,
user_agent=self.connector_config.user_agent,
)
return self._reddit

@requires_dependencies(["praw"], extras="reddit")
def initialize(self):
_ = self.reddit

def check_connection(self):
from praw.endpoints import API_PATH
Expand Down

0 comments on commit 56d11e1

Please sign in to comment.