|
|
@ -35,7 +35,7 @@ import pywikibot # noqa |
|
|
|
from pywikibot.tools import deprecated # noqa |
|
|
|
|
|
|
|
import jogobot |
|
|
|
from lib.mysqlred import MysqlRedFam |
|
|
|
from lib.mysqlred import MysqlRedFam, text |
|
|
|
|
|
|
|
|
|
|
|
class RedFam( MysqlRedFam ): |
|
|
@ -60,8 +60,16 @@ class RedFam( MysqlRedFam ): |
|
|
|
# Having pywikibot.Site() is a good idea most of the time |
|
|
|
self.site = pywikibot.Site() |
|
|
|
|
|
|
|
super().__init__( articlesList=articlesList, beginning=beginning, ending=ending, redpageid=redpageid, |
|
|
|
famhash=famhash, heading=heading, status=status, articlesStatus=None ) |
|
|
|
super().__init__( |
|
|
|
articlesList=articlesList, |
|
|
|
beginning=beginning, |
|
|
|
ending=ending, |
|
|
|
redpageid=redpageid, |
|
|
|
famhash=famhash, |
|
|
|
heading=heading, |
|
|
|
status=status, |
|
|
|
articlesStatus=None |
|
|
|
) |
|
|
|
|
|
|
|
def __repr__( self ): |
|
|
|
""" |
|
|
@ -228,23 +236,25 @@ class RedFamParser( RedFam ): |
|
|
|
if ending: |
|
|
|
ending = self.__datetime(ending) |
|
|
|
|
|
|
|
|
|
|
|
super().__init__( articlesList, beginning, ending=ending, redpageid=redpage.page._pageid, |
|
|
|
famhash=famhash, heading=heading ) |
|
|
|
super().__init__( articlesList, |
|
|
|
beginning, |
|
|
|
ending=ending, |
|
|
|
redpageid=redpage.page._pageid, |
|
|
|
famhash=famhash, |
|
|
|
heading=heading ) |
|
|
|
|
|
|
|
# Check status changes |
|
|
|
self.check_status() |
|
|
|
|
|
|
|
self.session.add(self) |
|
|
|
|
|
|
|
|
|
|
|
def update( self, articlesList, heading, redpage, redpagearchive, |
|
|
|
beginning, ending=None): |
|
|
|
beginning, ending=None ): |
|
|
|
|
|
|
|
self.articlesList = articlesList; |
|
|
|
self.heading = heading; |
|
|
|
self.redpage = redpage; |
|
|
|
self.redpageid = redpage.pageid; |
|
|
|
self.articlesList = articlesList |
|
|
|
self.heading = heading |
|
|
|
self.redpage = redpage |
|
|
|
self.redpageid = redpage.pageid |
|
|
|
|
|
|
|
self.add_beginning( beginning ) |
|
|
|
|
|
|
@ -271,8 +281,7 @@ class RedFamParser( RedFam ): |
|
|
|
heading = mwparser.parse( str( heading ) ) |
|
|
|
|
|
|
|
# Save destinations of wikilinks in headings |
|
|
|
return [ str( link.title ) for link |
|
|
|
in heading.ifilter_wikilinks() ] |
|
|
|
return [ str( link.title ) for link in heading.ifilter_wikilinks() ] |
|
|
|
|
|
|
|
def add_beginning( self, beginning ): |
|
|
|
""" |
|
|
@ -398,11 +407,13 @@ class RedFamParser( RedFam ): |
|
|
|
|
|
|
|
if redfam: |
|
|
|
# Existing redfams need to be updated |
|
|
|
redfam.update( articlesList, str(heading), redpage, isarchive, beginning, ending ) |
|
|
|
redfam.update( articlesList, str(heading), redpage, isarchive, |
|
|
|
beginning, ending ) |
|
|
|
|
|
|
|
else: |
|
|
|
# Create the RedFam object |
|
|
|
redfam = RedFamParser( articlesList, str(heading), redpage, isarchive, beginning, ending ) |
|
|
|
redfam = RedFamParser( articlesList, str(heading), |
|
|
|
redpage, isarchive, beginning, ending ) |
|
|
|
return redfam |
|
|
|
|
|
|
|
@classmethod |
|
|
@ -465,7 +476,8 @@ class RedFamWorker( RedFam ): |
|
|
|
# with wrong month abreviations in strptime |
|
|
|
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8') |
|
|
|
|
|
|
|
def article_generator(self, filter_existing=None, filter_redirects=None, |
|
|
|
def article_generator(self, # noqa |
|
|
|
filter_existing=None, filter_redirects=None, |
|
|
|
exclude_article_status=[], |
|
|
|
onlyinclude_article_status=[] ): |
|
|
|
""" |
|
|
@ -602,7 +614,7 @@ class RedFamWorker( RedFam ): |
|
|
|
template.add( "Beginn", begin, True ) |
|
|
|
|
|
|
|
# Add end (if not same as begin) |
|
|
|
end = self.ending.strftime( "%B %Y" ) |
|
|
|
end = self.ending.strftime( "%B %Y" ) |
|
|
|
if not end == begin: |
|
|
|
template.add( "Ende", end, True ) |
|
|
|
|
|
|
@ -634,14 +646,12 @@ class RedFamWorker( RedFam ): |
|
|
|
Yield red_fams stored in db by given status which have an ending after |
|
|
|
given one |
|
|
|
""" |
|
|
|
from sqlalchemy import text |
|
|
|
|
|
|
|
for redfam in RedFamWorker.session.query(RedFamWorker).filter( |
|
|
|
#~ RedFamWorker._status.like('archived'), |
|
|
|
#RedFamWorker._status.like("%{0:s}%".format(status)), |
|
|
|
# NOT WORKING WITH OBJECT NOTATION |
|
|
|
# RedFamWorker._status.like('archived'), |
|
|
|
# RedFamWorker._status.like("%{0:s}%".format(status)), |
|
|
|
text("status LIKE '%archived%'"), |
|
|
|
RedFamWorker.ending >= ending |
|
|
|
): |
|
|
|
RedFamWorker.ending >= ending ): |
|
|
|
|
|
|
|
yield redfam |
|
|
|
|
|
|
|