From f0978d26e2c6f7cedcc8966ad8686589cbc9c67c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Sat, 7 Nov 2015 21:11:43 +0100 Subject: [PATCH] Automatic year change detection --- charts.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/charts.py b/charts.py index 60a8d0a..20e8c8a 100644 --- a/charts.py +++ b/charts.py @@ -186,7 +186,6 @@ entry %s' """ Handles the parsing process of ref list """ - # Create Page-Object for Chartslist ref_list_page = pywikibot.Page( self.site, ref_list_link.title ) @@ -194,8 +193,10 @@ entry %s' if( ref_list_page.latest_revision_id == ref_list_revid ): return False - # We need the year related to ref_list_link - year = int(ref_list_page.title()[-5:-1]) + # Try to find list related year + year = datetime.now().year + if str( year ) not in ref_list_page.title(): + year = year - 1 # Parse charts list with mwparser wikicode = mwparser.parse( ref_list_page.text ) @@ -275,7 +276,21 @@ entry %s' """ """ # Get mwparser.wikilink object - return next( entry.get("Liste").value.ifilter_wikilinks() ) + link = next( entry.get("Liste").value.ifilter_wikilinks() ) + + year = datetime.now().year + + old_link_title = link.title + + # If year in link is lower then current year replace it + link.title = str(link.title).replace( str( year-1 ), str( year ) ) + + if ( pywikibot.Page( self.site, link.title).exists() ): + return link + else: + link.title = old_link_title + return link + def calculate_chartein( self, entry, data ): """