<s> from convoread . convore import Convore <EOL> from convoread . utils import debug , error , get_passwd , synchronized <EOL> class EnhancedConvore ( Convore ) : <EOL> def __init__ ( self ) : <EOL> super ( EnhancedConvore , self ) . __init__ ( ) <EOL> self . topic_lookup = { } <EOL> def get_group_id ( self , group_slug ) : <EOL> for group_id , group_data in self . get_groups ( ) . items ( ) : <EOL> if group_data [ '<STR_LIT>' ] == group_slug . lower ( ) : <EOL> return group_id <EOL> def topics_by_slug ( self , topics ) : <EOL> indexed_topics = { } <EOL> for topic in topics : <EOL> indexed_topics [ topic [ '<STR_LIT>' ] ] = topic <EOL> return indexed_topics <EOL> def topics_by_id ( self , topics ) : <EOL> indexed_topics = { } <EOL> for topic in topics : <EOL> indexed_topics [ topic [ '<STR_LIT:id>' ] ] = topic <EOL> return indexed_topics <EOL> def get_topic_id ( self , topic_url ) : <EOL> group , topic = topic_url . strip ( '<STR_LIT:/>' ) . split ( '<STR_LIT:/>' ) <EOL> group_id = self . get_group_id ( group ) <EOL> if not group in self . topic_lookup : <EOL> last_id , topics = self . get_group_topics_batch ( group_id ) <EOL> topics_slug_indexed = self . topics_by_slug ( topics ) <EOL> topics_id_indexed = self . topics_by_id ( topics ) <EOL> self . topic_lookup [ group ] = { '<STR_LIT>' : last_id , '<STR_LIT>' : topics_slug_indexed } <EOL> self . topic_lookup [ group ] [ '<STR_LIT>' ] = topics_id_indexed <EOL> found = False <EOL> while not found : <EOL> if topic in self . topic_lookup [ group ] [ '<STR_LIT>' ] : <EOL> return self . topic_lookup [ group ] [ '<STR_LIT>' ] [ topic ] [ '<STR_LIT:id>' ] <EOL> elif self . topic_lookup [ group ] [ '<STR_LIT>' ] : <EOL> last_id , topics = self . get_group_topics_batch ( group_id , self . topic_lookup [ group ] [ '<STR_LIT>' ] ) <EOL> topics_slug_indexed = self . topics_by_slug ( topics ) <EOL> topics_id_indexed = self . topics_by_id ( topics ) <EOL> self . topic_lookup [ group ] [ '<STR_LIT>' ] = last_id <EOL> self . topic_lookup [ group ] [ '<STR_LIT>' ] . update ( topics_slug_indexed ) <EOL> self . topic_lookup [ group ] [ '<STR_LIT>' ] . update ( topics_id_indexed ) <EOL> else : <EOL> return False <EOL> def get_topic_name ( self , topic_id ) : <EOL> for group in self . topic_lookup : <EOL> if topic_id in self . topic_lookup [ group ] [ '<STR_LIT>' ] : <EOL> return self . topic_lookup [ group ] [ '<STR_LIT>' ] [ topic_id ] [ '<STR_LIT:name>' ] <EOL> topic = self . get_topic ( topic_id ) <EOL> return topic . get ( '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> @ synchronized <EOL> def get_topic ( self , topic_id ) : <EOL> url = '<STR_LIT>' . format ( topic_id ) <EOL> topic = self . _connection . request ( '<STR_LIT:GET>' , url ) . get ( '<STR_LIT>' , { } ) <EOL> return topic <EOL> @ synchronized <EOL> def get_group_topics_batch ( self , group_id , until_id = None ) : <EOL> result = { } <EOL> url = '<STR_LIT>' . format ( group_id ) <EOL> if until_id : <EOL> url += ( '<STR_LIT>' + until_id ) <EOL> response = self . _connection . request ( '<STR_LIT:GET>' , url ) <EOL> result = response . get ( '<STR_LIT>' , [ ] ) <EOL> return ( response . get ( '<STR_LIT>' ) , result ) </s>
