def main(): log.debug('main() hearthscan-bot starting') # load constant values constants = Constants() # init answered comments sqlite DB answeredDB = commentDB.DB() # load card DB url = 'https://raw.githubusercontent.com/d-schmidt/hearthscan-bot/master/data/tempinfo.json' cardDB = CardDB(constants=constants, tempJSONUrl=url) # init hs helper for hearthstone stuff helper = HSHelper(cardDB, constants) # pm spam filter cache pmUserCache = {} def submissionListener(r, submission): answerSubmission(submission, helper) def commentListener(r, comment): answerComment(r, comment, answeredDB, helper) def mentionListener(r, comment): answerMention(r, comment, answeredDB, helper) def pmListener(r, message): answerPM(r, message, pmUserCache, helper) def postAction(): cleanPMUserCache(pmUserCache) cardDB.refreshTemp() try: RedditBot(subreddits=credentials.subreddits, newLimit=250, connectAttempts=5, userBlacklist=set(credentials.userBlacklist)) \ .withSubmissionListener(submissionListener) \ .withCommentListener(commentListener) \ .withMentionListener(mentionListener) \ .withPMListener(pmListener) \ .run(postAction) except: log.exception('main() RedditBot failed unexpectedly') finally: log.warning('main() leaving hearthscan-bot') answeredDB.close()
def test_CreateFindFailParent(self): removeFile(self.testDBName) db = commentDB.DB(self.testDBName) self.assertFalse(db.exists("abc", ["a card"])) # inserted on exists self.assertTrue(db.exists("abc", ["a card"])) self.assertFalse(db.exists("abc", ["b card"])) self.assertTrue(db.exists("abc", ["a card", "b card"])) self.assertFalse(db.exists("abc", ["a card", "b card", "c card"])) self.assertFalse(db.exists("123", ["a card"])) db.close() removeFile(self.testDBName)