Browse Source

Working RedFamWorker query

Modify RedfamWorker class to work with new DB API
develop
Jonathan Golder 7 years ago
parent
commit
43e31c108a
  1. 10
      lib/mysqlred.py
  2. 90
      lib/redfam.py

10
lib/mysqlred.py

@ -227,7 +227,7 @@ class MysqlRedFam( Mysql, Base ):
Integer, ForeignKey( "dewpbeta_redpages.pageid" ), nullable=False )
beginning = Column( DateTime, nullable=False )
ending = Column( DateTime, nullable=True )
__status = Column( 'status', MutableSet.as_mutable(Status(255)), nullable=True )
_status = Column( 'status', MutableSet.as_mutable(Status(255)), nullable=True )
__article0_status = Column(
'article0_status', MutableSet.as_mutable(Status(64)), nullable=True )
@ -250,7 +250,7 @@ class MysqlRedFam( Mysql, Base ):
__article3_status, __article4_status, __article5_status,
__article6_status, __article7_status )
redpage = relationship( "RedPage", back_populates="redfams" )
redpage = relationship( "MysqlRedPage", back_populates="redfams" )
@property
def articlesList(self):
@ -271,14 +271,14 @@ class MysqlRedFam( Mysql, Base ):
"""
Current fam status
"""
return self.__status
return self._status
@status.setter
def status( self, status ):
if status:
self.__status = MutableSet( status )
self._status = MutableSet( status )
else:
self.__status = MutableSet()
self._status = MutableSet()
@property
def articlesStatus(self):

90
lib/redfam.py

@ -121,10 +121,10 @@ class RedFam( MysqlRedFam ):
@type title str
"""
if title and not index:
index = self._articlesList.index( title )
index = self.articlesList.index( title )
if isinstance( index, int ) and index < len(self._articlesList):
self._article_status[index].add(status)
if isinstance( index, int ) and index < len(self.articlesList):
self.articlesStatus[index].add(status)
else:
raise IndexError( "No index given or wrong format!")
@ -145,13 +145,13 @@ class RedFam( MysqlRedFam ):
@type bool
"""
if title and not index:
index = self._articlesList.index( title )
index = self.articlesList.index( title )
if isinstance( index, int ) and index < len(self._articlesList):
if isinstance( index, int ) and index < len(self.articlesList):
if weak:
self._article_status[index].discard(status)
self.articlesStatus[index].discard(status)
else:
self._article_status[index].remove(status)
self.articlesStatus[index].remove(status)
else:
raise IndexError( "No index given or wrong format!")
@ -168,10 +168,10 @@ class RedFam( MysqlRedFam ):
@type title str
"""
if title and not index:
index = self._articlesList.index( title )
index = self.articlesList.index( title )
if isinstance( index, int ) and index < len(self._articlesList):
if status in self._article_status[index]:
if isinstance( index, int ) and index < len(self.articlesList):
if status in self.articlesStatus[index]:
return True
else:
return False
@ -458,19 +458,20 @@ class RedFamWorker( RedFam ):
"""
def __init__( self, mysql_data ):
articlesList = []
#~ articlesList = []
for key in sorted( mysql_data.keys() ):
if 'article' in key and 'status' not in key and mysql_data[ key ]:
articlesList.append( mysql_data[ key ] )
#~ for key in sorted( mysql_data.keys() ):
#~ if 'article' in key and 'status' not in key and mysql_data[ key ]:
#~ articlesList.append( mysql_data[ key ] )
# Preset article status list with empty sets for existing articles
self._article_status = [set() for x in range(0, len(articlesList))]
#~ # Preset article status list with empty sets for existing articles
#~ self._article_status = [set() for x in range(0, len(articlesList))]
super().__init__( articlesList, mysql_data[ 'beginning' ],
mysql_data[ 'ending' ], mysql_data[ 'redpageid' ],
mysql_data[ 'status' ], mysql_data[ 'famhash' ],
mysql_data[ 'heading' ] )
#~ super().__init__( articlesList, mysql_data[ 'beginning' ],
#~ mysql_data[ 'ending' ], mysql_data[ 'redpageid' ],
#~ mysql_data[ 'status' ], mysql_data[ 'famhash' ],
#~ mysql_data[ 'heading' ] )
super().__init__()
# #~ self._mysql.data = mysql_data
@ -510,8 +511,12 @@ class RedFamWorker( RedFam ):
"""
# Iterate over articles in redfam
for article in self._articlesList:
page = pywikibot.Page(pywikibot.Link(article), self.site)
for article in self.articlesList:
# Not all list elements contain articles
if not article:
break
page = pywikibot.Page(pywikibot.Link(article), pywikibot.Site())
# Exclude by article status
for status in exclude_article_status:
@ -544,7 +549,10 @@ class RedFamWorker( RedFam ):
"""
Sets status to 3 when worked on
"""
for article in self._articlesList:
for article in self.articlesList:
if not article:
break
if self.article_has_status( "note_rej", title=article ):
self.status.add( "note_rej" )
if self.article_has_status( "sav_err", title=article ):
@ -554,13 +562,6 @@ class RedFamWorker( RedFam ):
not self.status.has( "note_rej" ):
self.status.add( "marked" )
self._mysql.data[ 'status' ] = self._raw_status()
index = 0
for article in self._articlesList:
self._mysql.data[ "article" + str(index) + 'status' ] = \
self._article_raw_status( index=index )
index += 1
def get_disc_link( self ):
"""
Constructs and returns the link to Redundancy discussion
@ -570,7 +571,7 @@ class RedFamWorker( RedFam ):
"""
# We need to Replace Links with their linktext
anchor_code = mwparser.parse( self._mysql.data[ 'heading' ].strip() )
anchor_code = mwparser.parse( self.heading.strip() )
for link in anchor_code.ifilter_wikilinks():
if link.text:
text = link.text
@ -583,7 +584,7 @@ class RedFamWorker( RedFam ):
anchor_code.replace( " ", "_" )
# We try it with out any more parsing as mw will do while parsing page
return ( self.redpagetitle + "#" +
return ( self.redpage.pagetitle + "#" +
str(anchor_code).strip() )
def generate_disc_notice_template( self ):
@ -603,7 +604,9 @@ class RedFamWorker( RedFam ):
param_cnt = 3
# Iterate over articles in redfam
for article in self._articlesList:
for article in self.articlesList:
if not article:
break
# Make sure to only use 8 articles (max. param 10)
if param_cnt > 10:
break
@ -614,11 +617,11 @@ class RedFamWorker( RedFam ):
param_cnt += 1
# Add begin
begin = self._mysql.data[ 'beginning' ].strftime( "%B %Y" )
begin = self.beginning.strftime( "%B %Y" )
template.add( "Beginn", begin, True )
# Add end (if not same as begin)
end = self._mysql.data[ 'ending' ].strftime( "%B %Y" )
end = self.ending.strftime( "%B %Y" )
if not end == begin:
template.add( "Ende", end, True )
@ -650,13 +653,16 @@ class RedFamWorker( RedFam ):
Yield red_fams stored in db by given status which have an ending after
given one
"""
mysql = MysqlRedFam()
for fam in mysql.get_by_status_and_ending( status, ending ):
try:
yield cls( fam )
except RedFamHashError:
print(fam)
raise
from sqlalchemy import text
for redfam in RedFamWorker.session.query(RedFamWorker).filter(
#~ RedFamWorker._status.like('archived'),
#RedFamWorker._status.like("%{0:s}%".format(status)),
text("status LIKE '%archived%'"),
RedFamWorker.ending >= ending
):
yield redfam
class RedFamError( Exception ):

Loading…
Cancel
Save