Prepare exception handling
This commit is contained in:
54
charts.py
54
charts.py
@@ -163,10 +163,14 @@ entry %s'
|
|||||||
|
|
||||||
# Select the last occurence of template "Nummer-eins-Hits Zeile" in
|
# Select the last occurence of template "Nummer-eins-Hits Zeile" in
|
||||||
# "Singles"-section
|
# "Singles"-section
|
||||||
last_entry = singles_section.ifilter_templates(
|
entries = singles_section.filter_templates(
|
||||||
matches="Nummer-eins-Hits Zeile" )
|
matches="Nummer-eins-Hits Zeile" )
|
||||||
for last in last_entry:
|
|
||||||
pass
|
# Check, wether we found some entries
|
||||||
|
if not entries:
|
||||||
|
raise ChartsListError( page.title() )
|
||||||
|
else:
|
||||||
|
last = entries[-1]
|
||||||
|
|
||||||
# Detect weather we have a date or a weeknumber for Template Param
|
# Detect weather we have a date or a weeknumber for Template Param
|
||||||
# "Chartein"
|
# "Chartein"
|
||||||
@@ -252,14 +256,11 @@ entry %s'
|
|||||||
# For some countries we have weeknumbers instead of dates
|
# For some countries we have weeknumbers instead of dates
|
||||||
if( isinstance( data[0], str ) ):
|
if( isinstance( data[0], str ) ):
|
||||||
|
|
||||||
# Slice year out of link destination
|
|
||||||
year = int( list_page.title()[-5:-1] )
|
|
||||||
|
|
||||||
# Calculate date of monday in given week and add number of
|
# Calculate date of monday in given week and add number of
|
||||||
# days given in Template parameter "Wochentag" with monday
|
# days given in Template parameter "Korrektur" with monday
|
||||||
# as day (zero)
|
# as day (zero)
|
||||||
# We need double conversion since wikicode could not be casted
|
|
||||||
# as int directly
|
|
||||||
date = ( Week( year, int( data[0] ) ).monday() +
|
date = ( Week( year, int( data[0] ) ).monday() +
|
||||||
timedelta( days=days ) )
|
timedelta( days=days ) )
|
||||||
|
|
||||||
@@ -270,7 +271,7 @@ entry %s'
|
|||||||
# Check if param "Chartein" is present
|
# Check if param "Chartein" is present
|
||||||
if not country.has( "Chartein" ):
|
if not country.has( "Chartein" ):
|
||||||
try:
|
try:
|
||||||
country.add( "Chartein", "", before="Wochentag" )
|
country.add( "Chartein", "", before="Korrektur" )
|
||||||
except ValueError:
|
except ValueError:
|
||||||
country.add( "Chartein", "" )
|
country.add( "Chartein", "" )
|
||||||
|
|
||||||
@@ -300,6 +301,41 @@ entry %s'
|
|||||||
self.changed = True
|
self.changed = True
|
||||||
|
|
||||||
|
|
||||||
|
class ChartsError( Exception ):
|
||||||
|
"""
|
||||||
|
Base class for all Errors of Charts-Module
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__( self, message=None ):
|
||||||
|
"""
|
||||||
|
Handles Instantiation of ChartsError's
|
||||||
|
"""
|
||||||
|
if not message:
|
||||||
|
self.message = "An Error occured while executing a Charts action"
|
||||||
|
else:
|
||||||
|
self.message = message
|
||||||
|
|
||||||
|
def __str__( self ):
|
||||||
|
"""
|
||||||
|
Output of error message
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self.message
|
||||||
|
|
||||||
|
|
||||||
|
class ChartsListError( ChartsError ):
|
||||||
|
"""
|
||||||
|
Raised when given ChartsListPage does not contain valid entrys
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__( self, givenPage ):
|
||||||
|
|
||||||
|
message = "Given CharstListPage ('{given}') does not contain \
|
||||||
|
valid entries".format( given=givenPage )
|
||||||
|
|
||||||
|
super().__init__( message )
|
||||||
|
|
||||||
|
|
||||||
def main(*args):
|
def main(*args):
|
||||||
"""
|
"""
|
||||||
Process command line arguments and invoke bot.
|
Process command line arguments and invoke bot.
|
||||||
|
|||||||
Reference in New Issue
Block a user