Add methods for MySQL actions while parsing RED_FAMs

This commit is contained in:
2015-09-10 11:20:20 +02:00
parent 45df354315
commit 6d1ed33699

View File

@@ -116,11 +116,70 @@ class MYSQL_RED_PAGE( MYSQL_RED ):
class MYSQL_RED_FAM( MYSQL_RED ):
def __init__( self ):
def __init__( self, fam_hash ):
"""
Creates a new instance, runs __init__ of parent class
"""
super().__init__( )
self.__fam_hash = fam_hash
self.data = self.get_fam()
def __del__( self ):
pass
def get_fam( self ):
"""
Retrieves a red family row from MySQL-Database for given fam_hash
@returns dict Dictionairy with data for given fam hash otherwise if none found
bool FALSE
"""
cursor = type( self ).connection.cursor(mysqldb.DictCursor)
cursor.execute( 'SELECT * FROM `red_families` WHERE `fam_hash` = ?;', ( self.__fam_hash, ) )
res = cursor.fetchone()
if res:
return res
else:
return False
def add_fam( self, articlesList, red_page_id, beginning, ending=None, status=0 ):
cursor = type( self ).connection.cursor()
query = 'INSERT INTO `red_families` ( fam_hash, red_page_id, beginning, ending, status, article0, article1, article2, article3, article4, article5, article6, article7 ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );'
data = [ str( self.__fam_hash ), red_page_id, beginning, ending, status ]
for article in articlesList:
data.append( str( article ) )
while len( data ) < 13:
data.append( None )
data = tuple( data )
cursor.execute( query, data)
type( self ).connection.commit()
def update_fam( self, red_page_id, beginning, ending, status ):
"""
Updates the red fam row in MySQL-Database for given fam_hash
@param int red_page_id MediaWiki page_id which contains red_fam
@param datetime beginning Timestamp of beginning of redundance discussion
qparam datetime ending Timestamp of ending of redundance discussion
@param int status red_fam status (0 - discussion is running; 1 - discussion over; 2 - discussion archived)
"""
cursor = type( self ).connection.cursor()
query = 'UPDATE `red_families` SET `red_page_id` = ?, `beginning` = ?, `ending` = ?, `status`= ? WHERE `fam_hash` = ?;'
data = ( int(red_page_id ), beginning, ending, int( status ), self.__fam_hash )
cursor.execute( query, data)
type( self ).connection.commit()