Esempio n. 1
0
"""This module will stream Reddit posts and notify the recipient if a match is found
"""

import logging
from string import Template

from prowl.notify.message import get_template
from prowl.reddit.subreddit import get_subreddit
from .reddit.reddit import stream
from .keyword.keyword import contains_keywords, get_keywords
from .notify.notify import notify

LOG_FORMAT = "%(asctime)s::%(levelname)s::%(name)s::%(filename)s::%(lineno)d::%(message)s"
logging.basicConfig(level='INFO', format=LOG_FORMAT)

SUBREDDIT: str = get_subreddit('prowl/reddit/subreddits.txt')
KEYWORD: list = get_keywords('prowl/keyword/keywords.txt')
TEMPLATE: Template = get_template('prowl/notify/template.txt')


def watch() -> None:
    """Stream reddit posts from a specified subreddit
    :return: None
    """

    logging.info('Starting PrOwl...')
    for submission in stream(SUBREDDIT):
        handle_submission(submission)


def handle_submission(submission) -> None:
Esempio n. 2
0
def test_return_one_subreddit():
    expected: str = "test"
    received: str = get_subreddit('test/reddit/one_subreddit.txt')

    assert expected == received
Esempio n. 3
0
def test_return_three_subreddits():
    expected: str = 'test1+test2+test3'
    received: str = get_subreddit('test/reddit/three_subreddit.txt')

    assert expected == received
Esempio n. 4
0
def test_return_four_subreddits():
    expected: str = 'test1+test2+test3+test4'
    received: str = get_subreddit('test/reddit/four_subreddits.txt')

    assert expected == received
Esempio n. 5
0
def test_return_two_subreddits():
    expected: str = "test1+test2"
    received: str = get_subreddit('test/reddit/two_subreddit.txt')

    assert expected == received