|
|
|
@@ -74,6 +74,7 @@ class PostManager:
|
|
|
|
|
api_request_handler (ApiRequestHandler): Handles the API requests for interacting with post data.
|
|
|
|
|
log_manager (LoggingManager): Manages logging for operations performed by PostManager.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, api_request_handler: ApiRequestHandler):
|
|
|
|
|
"""
|
|
|
|
|
Initializes the PostManager with an API request handler for making API calls and a logging manager for logging.
|
|
|
|
@@ -166,6 +167,7 @@ class PostAnalyticsManager:
|
|
|
|
|
post_manager (PostManager): Manages post retrieval and existence checks.
|
|
|
|
|
log_manager (LoggingManager): Manages logging for analytics operations.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
|
self, api_request_handler: ApiRequestHandler, post_manager: PostManager
|
|
|
|
|
):
|
|
|
|
@@ -202,8 +204,8 @@ class PostAnalyticsManager:
|
|
|
|
|
now = datetime.now(timezone)
|
|
|
|
|
|
|
|
|
|
# Format datetime objects for the API request
|
|
|
|
|
time_begin_str = time_start.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z'
|
|
|
|
|
time_end_str = now.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z'
|
|
|
|
|
time_begin_str = time_start.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
|
|
|
|
|
time_end_str = now.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
|
|
|
|
|
|
|
|
|
|
post_id = self.post_manager.get_post_by_reddit_id(reddit_id)
|
|
|
|
|
post_id = post_id[0]["id"]
|
|
|
|
@@ -259,6 +261,7 @@ class RedditMonitor:
|
|
|
|
|
subreddit (praw.models.Subreddit): The subreddit object for the specified subreddit.
|
|
|
|
|
log_manager (LoggingManager): Manages logging for Reddit monitoring operations.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
|
self, client_id, client_secret, user_agent, username, password, subreddit_name
|
|
|
|
|
):
|
|
|
|
@@ -325,6 +328,7 @@ class SubmissionManager:
|
|
|
|
|
webhook_notifier (WebhookNotifier): Handles notifications for new or updated posts.
|
|
|
|
|
log_manager (LoggingManager): Manages logging for submission processing operations.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
reddit_monitor: RedditMonitor,
|
|
|
|
@@ -386,7 +390,9 @@ class SubmissionManager:
|
|
|
|
|
if self.post_manager.post_exists(submission.id):
|
|
|
|
|
self.log_manager.log("Post exists")
|
|
|
|
|
self.log_manager.log(f"post id: {submission.id}")
|
|
|
|
|
if self.post_analytics_manager.check_update_requirements(submission.id, update_frequency):
|
|
|
|
|
if self.post_analytics_manager.check_update_requirements(
|
|
|
|
|
submission.id, update_frequency
|
|
|
|
|
):
|
|
|
|
|
self.log_manager.log("Update requirements met")
|
|
|
|
|
post = self.convert_submission_to_post(submission)
|
|
|
|
|
self.post_analytics_manager.update_post_analytics(post)
|
|
|
|
@@ -415,6 +421,7 @@ class Application:
|
|
|
|
|
thread_manager: Manages threading for asynchronous operations.
|
|
|
|
|
update_frequency (int): The frequency, in seconds, at which post analytics should be updated.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
reddit_monitor,
|
|
|
|
@@ -423,7 +430,7 @@ class Application:
|
|
|
|
|
post_manager,
|
|
|
|
|
post_analytics_manager,
|
|
|
|
|
submission_manager,
|
|
|
|
|
update_frequency
|
|
|
|
|
update_frequency,
|
|
|
|
|
):
|
|
|
|
|
"""
|
|
|
|
|
Initializes the application with all necessary components.
|
|
|
|
@@ -465,7 +472,9 @@ class Application:
|
|
|
|
|
"""
|
|
|
|
|
Initializes and runs the scheduler for periodic updates.
|
|
|
|
|
"""
|
|
|
|
|
self.scheduler = Scheduler(self.update_frequency, lambda: self.periodic_update(self.update_frequency))
|
|
|
|
|
self.scheduler = Scheduler(
|
|
|
|
|
self.update_frequency, lambda: self.periodic_update(self.update_frequency)
|
|
|
|
|
)
|
|
|
|
|
self.scheduler.run()
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
@@ -474,9 +483,7 @@ class Application:
|
|
|
|
|
and processing submissions.
|
|
|
|
|
"""
|
|
|
|
|
self.log_manager.info("Application started")
|
|
|
|
|
self.thread_manager = ThreadManager(
|
|
|
|
|
target=self.run_periodic_update, args=()
|
|
|
|
|
)
|
|
|
|
|
self.thread_manager = ThreadManager(target=self.run_periodic_update, args=())
|
|
|
|
|
self.thread_manager.run()
|
|
|
|
|
submissions = self.reddit_monitor.stream_submissions()
|
|
|
|
|
self.submission_manager.process_submissions(submissions, self.update_frequency)
|
|
|
|
|