diff --git a/lib/redfam.py b/lib/redfam.py index 30dd22d..07d0820 100644 --- a/lib/redfam.py +++ b/lib/redfam.py @@ -57,6 +57,9 @@ class RedFam: @param heading str Original heading of RedFam (Link) """ + # Database interface + self._mysql = MysqlRedFam( fam_hash ) + # Initial attribute values self._articlesList = articlesList self._beginning = beginning @@ -108,6 +111,28 @@ class RedFam: else: self._fam_hash = h.hexdigest() + def changed( self ): + """ + Checks wether anything has changed and maybe triggers db update + """ + + # On archived red_fams do not delete possibly existing ending + if( not self._ending and self._status > 1 + and self._mysql.data[ 'ending' ] ): + + self._ending = self._mysql.data[ 'ending' ] + + # Since status change means something has changed, update database + if( self._status != self._mysql.data[ 'status' ] or + self._beginning != self._mysql.data[ 'beginning' ] or + self._ending != self._mysql.data[ 'ending' ] or + self._red_page_id != self._mysql.data[ 'red_page_id' ] or + self._heading != self._mysql.data[ 'heading' ]): + + self._mysql.update_fam( self._red_page_id, self._heading, + self._beginning, self._ending, + self._status ) + @classmethod def flush_db_cache( cls ): """ @@ -194,13 +219,13 @@ class RedFamParser( RedFam ): """ # We need a connection to our mysqldb - self.__mysql = MysqlRedFam( ) - self.__mysql.get_fam( self._fam_hash ) + self._mysql = MysqlRedFam( ) + self._mysql.get_fam( self._fam_hash ) - if not self.__mysql.data: - self.__mysql.add_fam( self._articlesList, self._heading, - self._red_page_id, self._beginning, - self._ending ) + if not self._mysql.data: + self._mysql.add_fam( self._articlesList, self._heading, + self._red_page_id, self._beginning, + self._ending ) def heading_parser( self, heading ): """ @@ -226,6 +251,7 @@ class RedFamParser( RedFam ): if len( self._articlesList ) > 8: # For repression in output we need to know the fam hash self.calc_fam_hash() + jogobot.output( ( "\03{{lightred}}" + "Maximum number of articles in red_fam exceeded, " + @@ -289,7 +315,7 @@ class RedFamParser( RedFam ): """ # Do not change stati set by worker script etc. - if not self.__mysql.data['status'] > 2: + if not self._mysql.data['status'] > 2: # No ending, discussion is running: # Sometimes archived discussions also have no detectable ending @@ -301,29 +327,8 @@ class RedFamParser( RedFam ): else: self._status = 2 else: - self._status = self.__mysql.data[ 'status' ] - def changed( self ): - """ - Checks wether anything has changed and maybe triggers db update - """ - - # On archived red_fams do not delete possibly existing ending - if( not self._ending and self._status > 1 and - self.__mysql.data[ 'ending' ] ): - - self._ending = self.__mysql.data[ 'ending' ] - - # Since status change means something has changed, update database - if( self._status != self.__mysql.data[ 'status' ] or - self._beginning != self.__mysql.data[ 'beginning' ] or - self._ending != self.__mysql.data[ 'ending' ] or - self._red_page_id != self.__mysql.data[ 'red_page_id' ] or - self._heading != self.__mysql.data[ 'heading' ]): - - self.__mysql.update_fam( self._red_page_id, self._heading, - self._beginning, self._ending, - self._status ) + self._status = self._mysql.data[ 'status' ] @classmethod def is_section_redfam_cb( cls, heading ):