def add_comments_to_submission(submission, sticky): """Method that adds the bot replies to the comments in the given submission.""" if submission == sticky: return heroes_dict = parser.dictionary_from_file(properties.HEROES_FILENAME) shitty_wizard_dict = parser.dictionary_from_file(properties.SHITTY_WIZARD_FILENAME) add_comments(submission, heroes_dict, shitty_wizard_dict)
def add_comments_to_submission(submission, sticky): """Method that adds the bot replies to the comments in the given submission.""" if submission == sticky: return heroes_dict = parser.dictionary_from_file(properties.HEROES_FILENAME) shitty_wizard_dict = parser.dictionary_from_file( properties.SHITTY_WIZARD_FILENAME) add_comments(submission, heroes_dict, shitty_wizard_dict)
def add_comments_to_submission(submission, sticky): """Method that adds the bot replies to the comments in given submission.""" if submission == sticky: return responses_dict = parser.dictionary_from_file(properties.RESPONSES_FILENAME) heroes_dict = parser.dictionary_from_file(properties.HEROES_FILENAME) already_done_comments = load_already_done_comments() add_comments(submission, already_done_comments, responses_dict, heroes_dict)
def add_hero_ids_to_general_responses(): """Method that adds hero ids to responses not assigned to specific heroes based on short hero name taken from the response link and heroes dictionary.""" conn = sqlite3.connect('responses.db') c = conn.cursor() heroes_dict = parser.dictionary_from_file(properties.HEROES_FILENAME) c.execute("SELECT link FROM responses WHERE hero IS NULL AND hero_id IS NULL") links = c.fetchall() for link_tuple in links: short_hero_name = parser.short_hero_name_from_url(link_tuple[0]) try: hero_name = heroes_dict[short_hero_name] except: continue c.execute("SELECT id FROM heroes WHERE name=?", [hero_name]) id = c.fetchone() if id is None: continue hero_id = id[0] c.execute("UPDATE responses SET hero_id=? WHERE link=?;", [hero_id, link_tuple[0]]); conn.commit() c.close()
def execute(): r = account.get_account() responses_dict = parser.dictionary_from_file("dota_responses_1.2.txt") already_done_comments = load_already_done_comments() for submission in r.get_subreddit(properties.SUBREDDIT).get_new(limit=100): add_comments(submission, already_done_comments, responses_dict) for submission in r.get_subreddit(properties.SUBREDDIT).get_hot(limit=25): add_comments(submission, already_done_comments, responses_dict)
def test_create_reply(self): """Method that tests the create_reply method from dotaresponses module. It checks whether the returned value is the same as the expected string. """ responses_dict = parser.dictionary_from_file('test_responses_dict.txt') heroes_dict = parser.dictionary_from_file('test_heroes_dict.txt') expected_output = ("[{}]({}) (sound warning: {}){}" .format('abc', 'http://def.gh/Abad_a_.mp3', 'Abaddon', properties.COMMENT_ENDING) ) self.assertEqual(dotaresponses.create_reply(responses_dict, heroes_dict, 'abc', 'abc'), expected_output) expected_output = ("[{}]({}) (sound warning: {}){}" .format('123', 'http://456.78/Noba_a_.mp3', 'Techies', properties.COMMENT_ENDING) ) self.assertEqual(dotaresponses.create_reply(responses_dict, heroes_dict, '123', '123'), expected_output)
def test_create_reply(self): """Method that tests the create_reply method from dotaresponses module. It checks whether the returned value is the same as the expected string. """ responses_dict = parser.dictionary_from_file('test_responses_dict.txt') heroes_dict = parser.dictionary_from_file('test_heroes_dict.txt') expected_output = ("[{}]({}) (sound warning: {}){}".format( 'abc', 'http://def.gh/Abad_a_.mp3', 'Abaddon', properties.COMMENT_ENDING)) self.assertEqual( dotaresponses.create_reply(responses_dict, heroes_dict, 'abc', 'abc'), expected_output) expected_output = ("[{}]({}) (sound warning: {}){}".format( '123', 'http://456.78/Noba_a_.mp3', 'Techies', properties.COMMENT_ENDING)) self.assertEqual( dotaresponses.create_reply(responses_dict, heroes_dict, '123', '123'), expected_output)
def update_responses_database(): """Method that updates an SQLite database with pairs response-link based on the JSON file with such pairs which was used before.""" responses_dictionary = parser.dictionary_from_file(properties.RESPONSES_FILENAME) conn = sqlite3.connect('responses.db') c = conn.cursor() for response, link in responses_dictionary.items(): c.execute("UPDATE responses SET link = ? WHERE response = ? AND link != ?", (link, response, link)) c.execute("INSERT INTO responses(response, link) SELECT ?, ? WHERE NOT EXISTS (SELECT 1 FROM responses WHERE response = ?)", (response, link, response)) conn.commit() c.close()
def create_responses_database(): """Method that creates an SQLite database with pairs response-link based on the JSON file with such pairs which was used before.""" responses_dictionary = parser.dictionary_from_file(properties.RESPONSES_FILENAME) conn = sqlite3.connect('responses.db') c = conn.cursor() c.execute('CREATE TABLE IF NOT EXISTS responses (response text, link text, hero text, hero_id integer)') for response, link in responses_dictionary.items(): c.execute("INSERT INTO responses(response, link) VALUES (?, ?)", (response, link)) conn.commit() c.close()
def create_responses_database(): """Method that creates an SQLite database with pairs response-link based on the JSON file with such pairs which was used before.""" responses_dictionary = parser.dictionary_from_file(properties.RESPONSES_FILENAME) conn = sqlite3.connect('responses.db') c = conn.cursor() c.execute('CREATE TABLE IF NOT EXISTS responses (response text, link text, hero text, hero_id integer)') for key, value in responses_dictionary.items(): c.execute("INSERT INTO responses(response, text) VALUES (?, ?)", (key, value)) conn.commit() c.close()