Browse Source

CountryList-module: Search current year via regex to also make parsing older lists possible

develop
Jonathan Golder 9 years ago
parent
commit
a250074caa
  1. 15
      countrylist.py

15
countrylist.py

@ -25,6 +25,7 @@
Provides a class for handling charts list per country and year Provides a class for handling charts list per country and year
""" """
import re
import locale import locale
from datetime import datetime from datetime import datetime
@ -96,15 +97,15 @@ class CountryList():
def find_year( self ): def find_year( self ):
""" """
Try to find the year related to CountryList Try to find the year related to CountryList using regex
""" """
self.year = datetime.now().year match = re.search( r"^.+\((\d{4})\)", self.page.title() )
# Check if year is in page.title, if not try last year # We matched something
if str( self.year ) not in self.page.title(): if match:
self.year -= 1 self.year = match.group()
# If last year does not match, raise YearError
if str( self.year ) not in self.page.title(): else:
raise CountryListError( "CountryList year is errorneous!" ) raise CountryListError( "CountryList year is errorneous!" )
def parse( self ): def parse( self ):

Loading…
Cancel
Save