You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.6 KiB
77 lines
1.6 KiB
from mysql_red import MYSQL_RED_PAGE
|
|
|
|
class RED_PAGE:
|
|
"""Class for handling redundance discussion pages and archives"""
|
|
|
|
def __init__( self, page ):
|
|
"""
|
|
Generate a new RED_PAGE object based on the given pywikibot page object
|
|
|
|
@param page page
|
|
"""
|
|
|
|
# Safe the pywikibot page object
|
|
self.page = page
|
|
|
|
self.__handle_db( )
|
|
|
|
self.is_page_changed()
|
|
|
|
self.__parsed = None
|
|
if( self.__changed or self.__mysql.data[ 'status' ] == 0 ):
|
|
self.parse()
|
|
|
|
self.__update_db()
|
|
|
|
# else:
|
|
# self.__mysql.add_page()
|
|
|
|
def __handle_db( self ):
|
|
"""
|
|
Handles opening of db connection
|
|
"""
|
|
# We need a connection to our mysqldb
|
|
self.__mysql = MYSQL_RED_PAGE( self.page._pageid )
|
|
|
|
if not self.__mysql.data:
|
|
self.__mysql.add_page( self.page.title, self.page._revid )
|
|
|
|
def is_page_changed( self ):
|
|
"""
|
|
Check wether the page was changed since last run
|
|
"""
|
|
|
|
if( self.__mysql.data != { 'page_id': self.page._pageid, 'rev_id': self.page._revid, 'page_title': self.page.title, 'status': self.__mysql.data[ 'status' ] } ):
|
|
self.__changed = True
|
|
else:
|
|
self.__changed = False
|
|
|
|
def is_archive( self ):
|
|
"""
|
|
Detects wether current page is an archive of discussions
|
|
"""
|
|
if u"/Archiv" in self.page.title:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def parse( self ):
|
|
"""
|
|
Handles the parsing process
|
|
"""
|
|
pass
|
|
|
|
def __update_db( self ):
|
|
"""
|
|
Updates the page meta data in mysql db
|
|
"""
|
|
if( self.__parsed ):
|
|
status = 1
|
|
|
|
if( self.is_archive() ):
|
|
status = 2
|
|
else:
|
|
status = 0
|
|
|
|
self.__mysql.update_page( self.page._revid, self.page.title, status )
|
|
|
|
|