示例#1
0
文件: Bot.py 项目: 4pr0n/spambot
	def handle_url(url, pages=1):
		children = []
		for child in Bot.get_content(url, pages=pages):
			if Filter.handle_child(child, Bot.db, Bot.log):
				# Filter removed the child for spam
				continue
			# Retry images if necessary
			Rarchives.rescrape(child, Bot.db, Bot.log)
			if Bot.db.count('checked_posts', 'postid = ?', [child.id]) == 0:
				# Has not been checked yet
				if not AmArch.handle_child(child, Bot.db, Bot.log):
					children.append(child)
				Bot.db.insert('checked_posts', (child.id, ))
				Bot.db.commit()
		return children
示例#2
0
文件: Bot.py 项目: 4pr0n/spambot
	def execute():
		'''
			Do one atomic operation.
			Looks for spam posts/comments.
			Might do other functions as well (depending on iteration #)
			such as check for messages, update moderated subs, etc
		'''
		Bot.iterations += 1
		it = Bot.iterations

		# Set update time
		Bot.update_time()

		pages = 1
		if it == 1: pages = PAGES_TO_REITERATE # look back on first load

		if it % 2 == 1:
			#Bot.log('Bot.execute: Checking messages...')
			if Bot.check_messages():
				# Got a PM to add/remove filter, need to look back further
				pages = PAGES_TO_REITERATE 
			Bot.update_time()

		# Check posts and comments
		# Removes spam and enforces AmateurArchives rules
		Bot.handle_url('/r/%s/comments' % MOD_SUB, pages=pages)
		Bot.update_time()
		children = Bot.handle_url('/r/%s/new' % MOD_SUB, pages=pages)
		Bot.update_time()

		# 'children' contains all 'unchecked' posts
		for child in children:
			# Check for sources
			Rarchives.handle_child(child, Bot.db, Bot.log)
		del children

		if it % 60 == 58:
			#Bot.log('Bot.execute: Updating moderated subreddits...')
			Bot.update_modded_subreddits()
			Bot.update_time()

		if it % 60 == 59:
			#Bot.log('Bot.execute: Updating AmateurArchives...')
			AmArch.execute(Bot.db, Bot.log)
			Bot.update_time()