Merge branch 'pep8-compat'

This commit is contained in:
2015-11-23 19:15:37 +01:00
3 changed files with 41 additions and 37 deletions
-2
View File
@@ -39,8 +39,6 @@ import locale
import pywikibot import pywikibot
from pywikibot import pagegenerators from pywikibot import pagegenerators
from pywikibot.bot import Bot
import mwparserfromhell as mwparser
from summarypage import SummaryPage from summarypage import SummaryPage
+13 -12
View File
@@ -103,7 +103,7 @@ class CountryList():
self.year -= 1 self.year -= 1
# If last year does not match, raise YearError # If last year does not match, raise YearError
if str( self.year ) not in self.page.title(): if str( self.year ) not in self.page.title():
raise CountryListYearError raise CountryListError( "CountryList year is errorneous!" )
def parse( self ): def parse( self ):
""" """
@@ -126,11 +126,11 @@ class CountryList():
Detect wether current entry is on of the belgian (Belgien/Wallonien) Detect wether current entry is on of the belgian (Belgien/Wallonien)
""" """
# Check if begian province name is in link text or title # Check if begian province name is in link text or title
if "Wallonien" in str( self.wikilink.text ) \ if( "Wallonien" in str( self.wikilink.text ) or
or "Wallonien" in str( self.wikilink.title): "Wallonien" in str( self.wikilink.title) ):
return "Wallonie" return "Wallonie"
elif "Flandern" in str( self.wikilink.text ) \ elif( "Flandern" in str( self.wikilink.text ) or
or "Flandern" in str( self.wikilink.title): "Flandern" in str( self.wikilink.title) ):
return "Flandern" return "Flandern"
else: else:
return None return None
@@ -155,21 +155,21 @@ class CountryList():
singles_section = self.wikicode.get_sections( singles_section = self.wikicode.get_sections(
matches=belgian )[0].get_sections( matches="Singles" )[0] matches=belgian )[0].get_sections( matches="Singles" )[0]
else: else:
singles_section = self.wikicode.get_sections( matches="Singles" )[0] singles_section = self.wikicode.get_sections(matches="Singles")[0]
# Since we have multiple categories in some countrys we need # Since we have multiple categories in some countrys we need
# to select the first wrapping template # to select the first wrapping template
try: try:
wrapping_template = next( singles_section.ifilter_templates( wrapping = next( singles_section.ifilter_templates(
matches="Nummer-eins-Hits" ) ) matches="Nummer-eins-Hits" ) )
except StopIteration: except StopIteration:
raise CountryListError( "Wrapping template is missing!") raise CountryListError( "Wrapping template is missing!")
# Select the last occurence of template "Nummer-eins-Hits Zeile" in # Select the last occurence of template "Nummer-eins-Hits Zeile" in
# Wrapper-template # Wrapper-template
for self.entry in wrapping_template.get("Inhalt").value.ifilter_templates( for self.entry in wrapping.get("Inhalt").value.ifilter_templates(
matches="Nummer-eins-Hits Zeile" ): matches="Nummer-eins-Hits Zeile" ):
pass pass
# Check if we have found something # Check if we have found something
if not self.entry: if not self.entry:
@@ -303,8 +303,8 @@ missing!" )
for index in indexes: for index in indexes:
# Check wether wikilink matches # Check wether wikilink matches
if parts[index] == wikilink.text \ if( parts[index] == wikilink.text or
or parts[index] == wikilink.title: parts[index] == wikilink.title ):
# Overwrite name with complete wikilink # Overwrite name with complete wikilink
parts[index] = str( wikilink ) parts[index] = str( wikilink )
@@ -345,6 +345,7 @@ class CountryListError( Exception ):
""" """
pass pass
class CountryListEntryError( CountryListError ): class CountryListEntryError( CountryListError ):
""" """
Handles errors occuring in class CountryList related to entrys Handles errors occuring in class CountryList related to entrys
+28 -23
View File
@@ -25,14 +25,14 @@
Provides classes for handling Charts summary page Provides classes for handling Charts summary page
""" """
import locale
from datetime import datetime, timedelta from datetime import datetime, timedelta
import pywikibot # import pywikibot
import mwparserfromhell as mwparser import mwparserfromhell as mwparser
from countrylist import CountryList, CountryListError from countrylist import CountryList, CountryListError
class SummaryPage(): class SummaryPage():
""" """
Handles summary page related actions Handles summary page related actions
@@ -52,7 +52,7 @@ class SummaryPage():
""" """
# Get mwparser.template objects for Template "/Eintrag" # Get mwparser.template objects for Template "/Eintrag"
for entry in self.wikicode.filter_templates( matches="/Eintrag" ) : for entry in self.wikicode.filter_templates( matches="/Eintrag" ):
# Instantiate SummaryPageEntry-object # Instantiate SummaryPageEntry-object
summarypageentry = SummaryPageEntry( entry ) summarypageentry = SummaryPageEntry( entry )
@@ -62,7 +62,7 @@ class SummaryPage():
# Get result # Get result
# We need to replace origninal entry since objectid changes due to # We need to replace origninal entry since objectid changes due to
# recreation of template object and reassignment won't be reflected # recreation of template object and reassignment won't be reflected
self.wikicode.replace( entry, summarypageentry.get_entry().template ) self.wikicode.replace(entry, summarypageentry.get_entry().template)
def get_new_text( self ): def get_new_text( self ):
""" """
@@ -119,22 +119,22 @@ class SummaryPageEntry():
# Get saved revision of related countrylist # Get saved revision of related countrylist
self.get_countrylist_saved_revid() self.get_countrylist_saved_revid()
# Get current year # Get current year
current_year = datetime.now().year; current_year = datetime.now().year
# Store old link.title # Store old link.title
link_title = self.countrylist_wikilink.title link_title = self.countrylist_wikilink.title
# If list is from last year, replace year # If list is from last year, replace year
if (current_year - 1) in link_title: if (current_year - 1) in link_title:
self.countrylist_wikilink.title.replace( (current_year - 1), current_year ) self.countrylist_wikilink.title.replace( (current_year - 1),
current_year )
# Try to get current years list # Try to get current years list
try: try:
self.countrylist = CountryList( self.countrylist_wikilink ) self.countrylist = CountryList( self.countrylist_wikilink )
if( self.countrylist and \ if( self.countrylist and
self.countrylist.is_parsing_needed( self.countrylist_revid )): self.countrylist.is_parsing_needed( self.countrylist_revid )):
self.countrylist.parse() self.countrylist.parse()
@@ -144,7 +144,7 @@ class SummaryPageEntry():
self.countrylist_wikilink.title = link_title self.countrylist_wikilink.title = link_title
self.countrylist = CountryList( self.countrylist_wikilink ) self.countrylist = CountryList( self.countrylist_wikilink )
if( self.countrylist and \ if( self.countrylist and
self.countrylist.is_parsing_needed( self.countrylist_revid )): self.countrylist.is_parsing_needed( self.countrylist_revid )):
self.countrylist.parse() self.countrylist.parse()
@@ -157,9 +157,11 @@ class SummaryPageEntry():
""" """
if self.old_entry.Liste: if self.old_entry.Liste:
try: try:
self.countrylist_wikilink = next( self.old_entry.Liste.ifilter_wikilinks() ) self.countrylist_wikilink = next(
self.old_entry.Liste.ifilter_wikilinks() )
except StopIteration: except StopIteration:
raise SummaryPageEntryError( "Parameter Liste does not contain valid wikilink!") raise SummaryPageEntryError(
"Parameter Liste does not contain valid wikilink!" )
else: else:
raise SummaryPageEntryError( "Parameter Liste is not present!") raise SummaryPageEntryError( "Parameter Liste is not present!")
@@ -168,7 +170,7 @@ class SummaryPageEntry():
Load saved revid of related countrylist if Param is present Load saved revid of related countrylist if Param is present
""" """
if self.old_entry.Liste_Revision: if self.old_entry.Liste_Revision:
self.countrylist_revid = int( self.old_entry.Liste_Revision.strip()) self.countrylist_revid = int(self.old_entry.Liste_Revision.strip())
else: else:
self.countrylist_revid = 0 self.countrylist_revid = 0
@@ -178,7 +180,8 @@ class SummaryPageEntry():
""" """
self.new_entry.Liste = self.countrylist_wikilink self.new_entry.Liste = self.countrylist_wikilink
self.new_entry.Liste_Revision = self.countrylist.page.latest_revision_id self.new_entry.Liste_Revision = \
self.countrylist.page.latest_revision_id
self.new_entry.Interpret = self.countrylist.interpret self.new_entry.Interpret = self.countrylist.interpret
self.new_entry.Titel = self.countrylist.titel self.new_entry.Titel = self.countrylist.titel
self.new_entry.Chartein = self._corrected_chartein self.new_entry.Chartein = self._corrected_chartein
@@ -217,7 +220,7 @@ class SummaryPageEntry():
Detects wether writing of entry is needed and stores information in Detects wether writing of entry is needed and stores information in
Class-Attribute Class-Attribute
""" """
type( self ).write_needed = ( ( self.old_entry != self.new_entry ) or \ type( self ).write_needed = ( ( self.old_entry != self.new_entry ) or
type( self ).write_needed ) type( self ).write_needed )
def get_entry( self ): def get_entry( self ):
@@ -257,25 +260,25 @@ class SummaryPageEntryTemplate():
if isinstance( template_obj, if isinstance( template_obj,
mwparser.nodes.template.Template ): mwparser.nodes.template.Template ):
self.template = template_obj; self.template = template_obj
self.__initial = False; self.__initial = False
# Otherwise raise error # Otherwise raise error
else: else:
raise SummaryPageEntryTemplateError( "Wrong type given" ); raise SummaryPageEntryTemplateError( "Wrong type given" )
# Otherwise initialise template # Otherwise initialise template
else: else:
self.__initial_template() self.__initial_template()
self.__initial = True; self.__initial = True
def __initial_template( self ): def __initial_template( self ):
""" """
Builds the initial template Builds the initial template
""" """
self.template = next( mwparser.parse( self.template = next( mwparser.parse( "{{Portal:Charts und Popmusik/\
"{{Portal:Charts und Popmusik/Aktuelle Nummer-eins-Hits/Eintrag|Liste=|Liste_Revision=|Interpret=|Titel=NN\ Aktuelle Nummer-eins-Hits/Eintrag|Liste=|Liste_Revision=|Interpret=|Titel=NN\
|Chartein=|Korrektur=|Hervor=}}" ).ifilter_templates() ) |Chartein=|Korrektur=|Hervor=}}" ).ifilter_templates() )
def __getattr__( self, name ): def __getattr__( self, name ):
@@ -319,7 +322,7 @@ class SummaryPageEntryTemplate():
cmpto = self cmpto = self
else: else:
raise SummaryPageEntryTemplateError( raise SummaryPageEntryTemplateError(
"One of the compared instances must have been initial!" ) "One of the compared instances must have been initial!" )
# Iterate over each param # Iterate over each param
for param in initial.template.params: for param in initial.template.params:
@@ -336,8 +339,8 @@ class SummaryPageEntryTemplate():
continue continue
# Compare other param values, if one unequal write is needed # Compare other param values, if one unequal write is needed
if initial.template.get( param ).value.strip() != \ if( initial.template.get( param ).value.strip() !=
cmpto.template.get( param ).value.strip(): cmpto.template.get( param ).value.strip() ):
return True return True
# If not returned True until now # If not returned True until now
@@ -350,12 +353,14 @@ class SummaryPageError( Exception ):
""" """
pass pass
class SummaryPageEntryError( SummaryPageError ): class SummaryPageEntryError( SummaryPageError ):
""" """
Handles errors occuring in class SummaryPageEntry Handles errors occuring in class SummaryPageEntry
""" """
pass pass
class SummaryPageEntryTemplateError( SummaryPageError ): class SummaryPageEntryTemplateError( SummaryPageError ):
""" """
Handles errors occuring in class SummaryPageEntryTemplate Handles errors occuring in class SummaryPageEntryTemplate