Ejemplo n.º 1
0
 def test_send_mod_mail_valid_subreddit(self):
     message_mock = Mock(return_value=None)
     subreddit_mock = Mock(message=message_mock)
     get_subreddit = Mock(return_value=subreddit_mock)
     reddit_mock = Mock(subreddit=get_subreddit)
     response_handler = ResponseHandler(reddit_mock, Mock(), Mock(), Mock())
     response_handler._save_private_message = Mock(return_value=None)
     response_handler.send_mod_mail('test subreddit', 'test subject',
                                    'test body')
     get_subreddit.assert_called_with('test subreddit')
     message_mock.assert_called_with('test subject', 'test body')
     response_handler._save_private_message.assert_called()
 def __init__(self):
     self.config = Config()
     self.redlock = get_redlock_factory(self.config)
     self.reddit = get_reddit_instance(self.config)
     self.reddit_manager = RedditManager(self.reddit)
     self.uowm = SqlAlchemyUnitOfWorkManager(get_db_engine(self.config))
     self.event_logger = EventLogging(config=self.config)
     notification_svc = NotificationService(self.config)
     self.response_handler = ResponseHandler(
         self.reddit_manager,
         self.uowm,
         self.event_logger,
         source='summons',
         live_response=self.config.live_responses,
         notification_svc=notification_svc)
     dup_image_svc = DuplicateImageService(self.uowm,
                                           self.event_logger,
                                           self.reddit,
                                           config=self.config)
     response_builder = ResponseBuilder(self.uowm)
     self.summons_handler = SummonsHandler(
         self.uowm,
         dup_image_svc,
         self.reddit_manager,
         response_builder,
         self.response_handler,
         event_logger=self.event_logger,
         summons_disabled=False,
         notification_svc=notification_svc)
Ejemplo n.º 3
0
def repost_watch_notify(watches: List[Dict[SearchMatch, RepostWatch]],
                        reddit: RedditManager,
                        response_handler: ResponseHandler, repost: Post):
    for watch in watches:
        # TODO - What happens if we don't get redditor back?
        redditor = reddit.redditor(watch['watch'].user)
        msg = WATCH_NOTIFY_OF_MATCH.format(
            watch_shortlink=f"https://redd.it/{watch['watch'].post_id}",
            repost_shortlink=f"https://redd.it/{repost.post_id}",
            percent_match=watch['match'].hamming_match_percent)
        log.info('Sending repost watch PM to %s', redditor.name)
        response_handler.send_private_message(
            redditor,
            msg,
            subject='A post you are watching has been reposted',
            source='watch',
            post_id=watch['watch'].post_id)
Ejemplo n.º 4
0
 def __init__(self):
     self.config = Config()
     self.reddit = RedditManager(get_reddit_instance(self.config))
     self.uowm = SqlAlchemyUnitOfWorkManager(get_db_engine(self.config))
     self.event_logger = EventLogging(config=self.config)
     self.response_handler = ResponseHandler(
         self.reddit,
         self.uowm,
         self.event_logger,
         live_response=self.config.live_responses)
Ejemplo n.º 5
0
 def __init__(self):
     self.config = Config()
     self.reddit = RedditManager(get_reddit_instance(self.config))
     self.uowm = SqlAlchemyUnitOfWorkManager(get_db_engine(self.config))
     self.event_logger = EventLogging(config=self.config)
     self.response_handler = ResponseHandler(
         self.reddit,
         self.uowm,
         self.event_logger,
         live_response=self.config.live_responses)
     self.notification_svc = NotificationService(self.config)
     self.config_updater = SubredditConfigUpdater(
         self.uowm,
         self.reddit.reddit,
         self.response_handler,
         self.config,
         notification_svc=self.notification_svc)
 def __init__(self):
     self.config = Config()
     self.reddit = get_reddit_instance(self.config)
     self.reddit_manager = RedditManager(self.reddit)
     self.uowm = SqlAlchemyUnitOfWorkManager(get_db_engine(self.config))
     event_logger = EventLogging(config=self.config)
     response_handler = ResponseHandler(
         self.reddit_manager,
         self.uowm,
         event_logger,
         source='submonitor',
         live_response=self.config.live_responses)
     dup_image_svc = DuplicateImageService(self.uowm,
                                           event_logger,
                                           self.reddit,
                                           config=self.config)
     response_builder = ResponseBuilder(self.uowm)
     self.sub_monitor = SubMonitor(dup_image_svc,
                                   self.uowm,
                                   self.reddit_manager,
                                   response_builder,
                                   response_handler,
                                   event_logger=event_logger,
                                   config=self.config)
Ejemplo n.º 7
0
if __name__ == '__main__':
    config = Config()
    event_logger = EventLogging(config=config)
    uowm = SqlAlchemyUnitOfWorkManager(get_db_engine(config))
    response_builder = ResponseBuilder(uowm)
    reddit = get_reddit_instance(config)
    reddit_manager = RedditManager(reddit)
    dup = DuplicateImageService(uowm, event_logger, reddit, config=config)
    monitor = SubMonitor(dup,
                         uowm,
                         reddit_manager,
                         response_builder,
                         ResponseHandler(reddit_manager,
                                         uowm,
                                         event_logger,
                                         source='submonitor',
                                         live_response=config.live_responses),
                         event_logger=event_logger,
                         config=config)
    redis = get_redis_client(config)
    while True:
        while True:
            queued_items = redis.lrange('submonitor', 0, 20000)
            if len(queued_items) == 0:
                log.info('Sub monitor queue empty.  Starting over')
                break
            log.info('Sub monitor queue still has %s tasks', len(queued_items))
            time.sleep(60)
        with uowm.start() as uow:
            monitored_subs = uow.monitored_sub.get_all()
                                 comment_body=comment.body,
                                 perma_link=comment.permalink,
                                 source='toppost',
                                 comment_id=comment.id,
                                 subreddit=post.subreddit)
        with self.uowm.start() as uow:
            uow.bot_comment.add(bot_comment)
            try:
                uow.commit()
            except Exception as e:
                log.exception('Failed to save bot comment', exc_info=True)


if __name__ == '__main__':
    config = Config()
    uowm = SqlAlchemyUnitOfWorkManager(get_db_engine(config))
    event_logger = EventLogging(config=config)
    dup = DuplicateImageService(uowm, event_logger, config=config)
    response_builder = ResponseBuilder(uowm)
    reddit_manager = RedditManager(get_reddit_instance(config))
    top = TopPostMonitor(reddit_manager,
                         uowm,
                         dup,
                         response_builder,
                         ResponseHandler(reddit_manager,
                                         uowm,
                                         event_logger,
                                         source='toppost',
                                         live_response=config.live_responses),
                         config=config)
    top.monitor()
Ejemplo n.º 9
0
from redditrepostsleuth.repostsleuthsiteapi.endpoints.image_search import ImageSearch
from redditrepostsleuth.repostsleuthsiteapi.endpoints.image_search_history import ImageSearchHistory
from redditrepostsleuth.repostsleuthsiteapi.endpoints.meme_template import MemeTemplateEndpoint
from redditrepostsleuth.repostsleuthsiteapi.endpoints.monitored_sub import MonitoredSub
from redditrepostsleuth.repostsleuthsiteapi.endpoints.post_watch import PostWatch
from redditrepostsleuth.repostsleuthsiteapi.endpoints.posts import PostsEndpoint
from redditrepostsleuth.repostsleuthsiteapi.endpoints.repost_history import RepostHistoryEndpoint

config = Config()
event_logger = EventLogging(config=config)
uowm = SqlAlchemyUnitOfWorkManager(get_db_engine(config))
reddit = get_reddit_instance(config)
reddit_manager = RedditManager(reddit)
dup = DuplicateImageService(uowm, event_logger, reddit, config=config)
response_handler = ResponseHandler(reddit,
                                   uowm,
                                   event_logger,
                                   live_response=config.live_responses)
notification_svc = NotificationService(config)
config_updater = SubredditConfigUpdater(uowm,
                                        reddit,
                                        response_handler,
                                        config,
                                        notification_svc=notification_svc)

cors = CORS(allow_origins_list=[
    'http://localhost:8080', 'https://repostsleuth.com',
    'https://www.repostsleuth.com'
],
            allow_all_methods=True,
            allow_all_headers=True,
            log_level='DEBUG')
Ejemplo n.º 10
0
if __name__ == '__main__':
    config = Config()
    uowm = SqlAlchemyUnitOfWorkManager(get_db_engine(config))
    reddit = get_reddit_instance(config)
    reddit_manager = RedditManager(reddit)
    notification_svc = NotificationService(config)
    comment_monitor = BotCommentMonitor(reddit_manager,
                                        uowm,
                                        config,
                                        notification_svc=notification_svc)
    stats_updater = StatsUpdater()
    activation_monitor = NewActivationMonitor(
        uowm, get_reddit_instance(config), notification_svc=notification_svc)
    event_logger = EventLogging(config=config)
    response_handler = ResponseHandler(reddit_manager, uowm, event_logger)
    inbox_monitor = InboxMonitor(uowm, reddit_manager.reddit, response_handler)

    #config_updater.update_configs()

    scheduler = BackgroundScheduler()
    scheduler.add_listener(event_callback, EVENT_JOB_ERROR)
    scheduler.add_job(func=activation_monitor.check_for_new_invites,
                      trigger='interval',
                      minutes=1,
                      name='activation_checker',
                      max_instances=1)
    scheduler.add_job(func=stats_updater.run_update,
                      trigger='interval',
                      minutes=15,
                      name='stats_update',
from redditrepostsleuth.core.services.eventlogging import EventLogging
from redditrepostsleuth.core.services.reddit_manager import RedditManager
from redditrepostsleuth.core.services.response_handler import ResponseHandler
from redditrepostsleuth.core.services.responsebuilder import ResponseBuilder
from redditrepostsleuth.core.util.imagehashing import get_image_hashes
from redditrepostsleuth.core.util.reddithelpers import get_reddit_instance
from redditrepostsleuth.submonitorsvc.submonitor import SubMonitor

config = Config(
    r'/home/barry/PycharmProjects/RedditRepostSleuth/sleuth_config.json')
reddit = get_reddit_instance(config)
uowm = SqlAlchemyUnitOfWorkManager(get_db_engine(config))
reddit_manager = RedditManager(reddit)
event_logger = EventLogging(config=config)
response_handler = ResponseHandler(reddit_manager,
                                   uowm,
                                   event_logger,
                                   source='submonitor')
dup_image_svc = DuplicateImageService(uowm, event_logger, config=config)
response_builder = ResponseBuilder(uowm)
sub_monitor = SubMonitor(dup_image_svc,
                         uowm,
                         reddit_manager,
                         response_builder,
                         response_handler,
                         event_logger=event_logger,
                         config=config)

with uowm.start() as uow:
    post = uow.posts.get_by_post_id('iirpkm')
    target_hashes = get_image_hashes(post.searched_url, hash_size=32)
Ejemplo n.º 12
0
    config = Config()
    event_logger = EventLogging(config=config)
    uowm = SqlAlchemyUnitOfWorkManager(get_db_engine(config))

    response_builder = ResponseBuilder(uowm)
    reddit = get_reddit_instance(config)
    reddit_manager = RedditManager(reddit)
    dup = DuplicateImageService(uowm, event_logger, reddit, config=config)
    summons = SummonsHandler(uowm,
                             dup,
                             reddit_manager,
                             response_builder,
                             ResponseHandler(
                                 reddit_manager,
                                 uowm,
                                 event_logger,
                                 live_response=config.live_responses,
                                 source='summons',
                             ),
                             event_logger=event_logger,
                             summons_disabled=False)
    redis_client = redis.Redis(host=config.redis_host,
                               port=config.redis_port,
                               db=0,
                               password=config.redis_password)
    while True:
        try:
            with uowm.start() as uow:
                summons = uow.summons.get_unreplied(limit=20)

                for s in summons:
Ejemplo n.º 13
0
 def test_send_mod_mail_invalid_subreddit(self):
     subreddit_mock = Mock(return_value=None)
     reddit_mock = Mock(subreddit=subreddit_mock)
     response_handler = ResponseHandler(reddit_mock, Mock(), Mock(), Mock())
     response_handler.send_mod_mail('test', 'test', 'test')
     subreddit_mock.assert_called()