Change behavior of MysqlRedFam to be able to get instance without knowen fam_hash

This commit is contained in:
2015-09-19 19:49:20 +02:00
parent b5ca69077c
commit 8059bb9992
2 changed files with 7 additions and 14 deletions

View File

@@ -203,38 +203,30 @@ SET `red_page_id` = ?, `heading` = ?, `beginning` = ?, `ending` = ?, \
article0, article1, article2, article3, article4, article5, article6, \ article0, article1, article2, article3, article4, article5, article6, \
article7 ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );' article7 ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );'
def __init__( self, fam_hash ): def __init__( self ):
""" """
Creates a new instance, runs __init__ of parent class Creates a new instance, runs __init__ of parent class
""" """
super().__init__( ) super().__init__( )
self.__fam_hash = fam_hash
self.data = self.get_fam()
def __del__( self ): def __del__( self ):
pass pass
def get_fam( self ): def get_fam( self, fam_hash ):
""" """
Retrieves a red family row from MySQL-Database for given fam_hash Retrieves a red family row from MySQL-Database for given fam_hash
@returns dict Dictionairy with data for given fam hash @returns dict Dictionairy with data for given fam hash
False if none found False if none found
""" """
self.__fam_hash = fam_hash
cursor = type( self ).connection.cursor( mysqldb.DictCursor ) cursor = type( self ).connection.cursor( mysqldb.DictCursor )
cursor.execute( 'SELECT * FROM `red_families` WHERE `fam_hash` = ?;', cursor.execute( 'SELECT * FROM `red_families` WHERE `fam_hash` = ?;',
( self.__fam_hash, ) ) ( fam_hash, ) )
res = cursor.fetchone() self.data = cursor.fetchone()
if res:
return res
else:
return False
def add_fam( self, articlesList, heading, red_page_id, def add_fam( self, articlesList, heading, red_page_id,
beginning, ending=None, status=0 ): beginning, ending=None, status=0 ):

View File

@@ -191,7 +191,8 @@ class RedFamParser( RedFam ):
""" """
# We need a connection to our mysqldb # We need a connection to our mysqldb
self.__mysql = MysqlRedFam( self._fam_hash ) self.__mysql = MysqlRedFam( )
self.__mysql.get_fam( self._fam_hash )
if not self.__mysql.data: if not self.__mysql.data:
self.__mysql.add_fam( self._articlesList, self._heading, self.__mysql.add_fam( self._articlesList, self._heading,