def update_ban_list(uowm: UnitOfWorkManager, reddit: Reddit, notification_svc: NotificationService = None) -> NoReturn: """ Go through banned subs and see if we're still banned :rtype: NoReturn :param uowm: UnitOfWorkManager :param reddit: Reddit """ log.info('Starting Job: Update Subreddit Bans') with uowm.start() as uow: bans = uow.banned_subreddit.get_all() for ban in bans: last_checked_delta = (datetime.utcnow() - ban.last_checked).days if last_checked_delta < 1: log.debug('Banned sub %s last checked %s days ago. Skipping', ban.subreddit, last_checked_delta) continue if is_bot_banned(ban.subreddit, reddit): log.info('[Subreddit Ban Check] Still banned on %s', ban.subreddit) ban.last_checked = func.utc_timestamp() else: log.info('[Subreddit Ban Check] No longer banned on %s', ban.subreddit) uow.banned_subreddit.remove(ban) if notification_svc: notification_svc.send_notification( f'Removed {ban.subreddit} from ban list', subject='Subreddit Removed From Ban List!') uow.commit()
def remove_expired_bans(uowm: UnitOfWorkManager, notification_svc: NotificationService = None) -> NoReturn: print('[Scheduled Job] Removed Expired Bans Start') with uowm.start() as uow: bans = uow.banned_user.get_expired_bans() for ban in bans: if notification_svc: notification_svc.send( f'Removing expired ban for user {ban.name}', subject='**Expired Ban Removed**' ) log.info('[Ban Remover] Removing %s from ban list', ban.name) uow.banned_user.remove(ban) uow.commit()
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)
def __init__(self): self.config = Config() from redditrepostsleuth.core.services.duplicateimageservice import DuplicateImageService self.uowm = SqlAlchemyUnitOfWorkManager(get_db_engine(self.config)) self.notification_svc = NotificationService(self.config) self.event_logger = EventLogging() self.reddit = get_reddit_instance(self.config) self.dup_service = DuplicateImageService(self.uowm, self.event_logger, self.reddit)
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.notification_svc = NotificationService(self.config) self.response_handler = ResponseHandler( self.reddit, self.uowm, self.event_logger, live_response=self.config.live_responses)
else: continue uow.commit() def queue_config_updates(uowm: UnitOfWorkManager, config: Config) -> NoReturn: print('[Scheduled Job] Queue config update check') redis = get_redis_client(config) if len(redis.lrange('config_update_check', 0, 20000)) > 0: log.info( 'Config update queue still has pending jobs. Skipping update queueing ' ) return with uowm.start() as uow: monitored_subs = uow.monitored_sub.get_all() for monitored_sub in monitored_subs: check_for_subreddit_config_update_task.apply_async( (monitored_sub, )) print('[Scheduled Job Complete] Queue config update check') if __name__ == '__main__': config = Config( r'/home/barry/PycharmProjects/RedditRepostSleuth/sleuth_config.json') notification_svc = NotificationService(config) reddit = get_reddit_instance(config) uowm = SqlAlchemyUnitOfWorkManager(get_db_engine(config)) queue_config_updates(uowm, config)
def __init__(self): super().__init__() self.notification_svc = NotificationService(self.config) self.link_blacklist = [ ] # Temp fix. People were spamming onlyfans links 10s of thousands of times self.reddit = get_reddit_instance(self.config)