def test_short_hero_name_from_url(self):
     """Method testing short_hero_name_from_url method from dota_wiki_parser module."""
     self.assertEqual(parser.short_hero_name_from_url('/Test_asdf.mp3'),
                      'Test')
     self.assertEqual(parser.short_hero_name_from_url('/Dlc_Test_asdf.mp3'),
                      'Dlc_Test')
     self.assertEqual(
         parser.short_hero_name_from_url('/Dlc_tech_ann_asdf.mp3'),
         'Dlc_tech_ann')
def create_reply_invoker_ending(response_url, heroes_dict, img_dir):
    short_hero_name = parser.short_hero_name_from_url(response_url)
    hero_name = heroes_dict[short_hero_name]

    return ("[]({}): [{}]({}) (sound warning: {})\n\n{}{}".format(
        img_dir, properties.INVOKER_RESPONSE, response_url, hero_name,
        properties.INVOKER_ENDING, properties.COMMENT_ENDING))
Beispiel #3
0
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 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 create_reply_invoker_ending(response_url, heroes_dict):
    short_hero_name = parser.short_hero_name_from_url(response_url)
    hero_name = heroes_dict[short_hero_name]
    
    return (
        "[{}]({}) (sound warning: {})\n\n{}{}"
        .format(properties.INVOKER_RESPONSE, response_url, hero_name, properties.INVOKER_ENDING, properties.COMMENT_ENDING)
        )
def create_reply(response_url, heroes_dict, orignal_text):
    """Method that creates a reply in reddit-post format.

    The message consists of a link the the response, the response itself, a warning about the sound
    and an ending added from the properties file (post footer).
    """
    short_hero_name = parser.short_hero_name_from_url(response_url)
    hero_name = heroes_dict[short_hero_name]

    return ("[{}]({}) (sound warning: {}){}".format(orignal_text, response_url,
                                                    hero_name,
                                                    properties.COMMENT_ENDING))
def create_reply(response_url, heroes_dict, orignal_text):
    """Method that creates a reply in reddit-post format.

    The message consists of a link the the response, the response itself, a warning about the sound
    and an ending added from the properties file (post footer).
    """
    short_hero_name = parser.short_hero_name_from_url(response_url)
    hero_name = heroes_dict[short_hero_name]

    return (
        "[{}]({}) (sound warning: {}){}"
        .format(orignal_text, response_url, hero_name, properties.COMMENT_ENDING)
        )
def create_reply(response_url, heroes_dict, orignal_text, img=None):
    """Method that creates a reply in reddit-post format.

    The message consists of a link the the response, the response itself, a warning about the sound
    and an ending added from the properties file (post footer).
    """
    short_hero_name = parser.short_hero_name_from_url(response_url)
    log('DEBUG: ' + str(response_url) + ' : ' + str(short_hero_name))
    hero_name = heroes_dict[short_hero_name]

    #if img:
    #    return (
    #        "[]({}): [{}]({}) (sound warning: {}){}"
    #        .format(img, orignal_text, response_url, hero_name, properties.COMMENT_ENDING)
    #        )
    #else:
    return ("[{}]({}) (sound warning: {}){}".format(orignal_text, response_url,
                                                    hero_name,
                                                    properties.COMMENT_ENDING))