From 4a790912fc1ad6a1194c4f24f7605c0d199f25c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Mon, 9 Nov 2015 20:01:55 +0100 Subject: [PATCH] CountryList-Module: Implement method for detecting year related to list --- countrylist.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/countrylist.py b/countrylist.py index 0aa7bbd..b5169fc 100644 --- a/countrylist.py +++ b/countrylist.py @@ -74,6 +74,9 @@ class CountryList(): for attr in __attr: setattr( self, attr, None ) + # Try to find year + self.find_year() + def parsing_needed( self, revid ): """ Check if current revid of CountryList differs from given one @@ -88,3 +91,16 @@ class CountryList(): return True else: return False + + def find_year( self ): + """ + Try to find the year related to CountryList + """ + self.year = datetime.now().year + + # Check if year is in page.title, if not try last year + if str( self.year ) not in self.page.title(): + self.year -= 1 + # If last year does not match, raise YearError + if str( self.year ) not in self.page.title(): + raise CountryListYearError