Skip to content

Commit

Permalink
Update docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTyton committed Jul 28, 2024
1 parent 21074d1 commit 3abb7dd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
17 changes: 12 additions & 5 deletions root/app/fanficdownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def create_processes(
`email_watcher` and `waiting_watcher` processes, ready to be started.
"""
email_watcher = mp.Process(
target=url_ingester.email_watcher, args=(email_info, notification_info, queues)
target=url_ingester.email_watcher,
args=(email_info, notification_info, queues),
)
waiting_watcher = mp.Process(
target=ff_waiter.wait_processor, args=(queues, waiting_queue)
Expand Down Expand Up @@ -152,16 +153,22 @@ def main():

# Initialize configurations for email, pushbullet notifications, and calibre database
email_info = url_ingester.EmailInfo(args.config)


# Create the Notification Wrapper. All notifications are sent through this object,
# and the individual initializations of each class must be added to this object.
notification_info = notification_wrapper.NotificationWrapper()

# Create the Pushbullet Notifier
pushbullet_info = pushbullet_notification.PushbulletNotification(args.config)
pushbullet_info = pushbullet_notification.PushbulletNotification(
args.config
)
notification_info.add_notification_worker(pushbullet_info)

with mp.Manager() as manager:
# Create queues for each site and a waiting queue for delayed processing
queues = {site: manager.Queue() for site in regex_parsing.url_parsers.keys()}
queues = {
site: manager.Queue() for site in regex_parsing.url_parsers.keys()
}
waiting_queue = manager.Queue()
cdb_info = calibre_info.CalibreInfo(args.config, manager)
cdb_info.check_installed()
Expand Down
24 changes: 23 additions & 1 deletion root/app/notification_base.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
"""
Base class for implementing Notifications.
This module contains the base class for implementing notifications. The class defines the
`send_notification` function, which sends a notification with a title, body, and site. This
function must be implemented by the derived classes.
It also provides a helper function that can be applied to the `send_notification` function,
as a decorator, to retry it up to 3 times with 10, 20, and 30-second delays between attempts.
The derived classes must mark themselves as `enabled` if they are able to send notifications,
by setting `self.enabled` to True.
The derived classes are responsible for extracting their configuration information from the
TOML file that has been loaded into `self.config`.
"""

import time
import tomllib
from typing import Callable, Any


class NotificationBase:
def __init__(self):
def __init__(self, toml_path: str):
"""
Initializes the NotificationBase class.
"""
self.enabled = False

# Load the configuration from the TOML file
with open(toml_path, "rb") as file:
self.config = tomllib.load(file)

def send_notification(self, title: str, body: str, site: str) -> bool:
"""
Sends a notification. This method must be implemented in derived classes.
Expand Down
8 changes: 2 additions & 6 deletions root/app/pushbullet_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@

import ff_logging
import notification_base
import tomllib


class PushbulletNotification(notification_base.NotificationBase):
# Initialization Function
def __init__(self, toml_path: str):
super().__init__()
# Load the configuration from the TOML file
with open(toml_path, "rb") as file:
config = tomllib.load(file)
super().__init__(toml_path)
# Extract the Pushbullet configuration
pushbullet_config = config.get("pushbullet", None)
pushbullet_config = self.config.get("pushbullet", None)
if pushbullet_config is None:
return

Expand Down

0 comments on commit 3abb7dd

Please sign in to comment.