Browse Source

Merge branch 'test-v5'

develop
Jonathan Golder 8 years ago
parent
commit
9fe1c36482
  1. 11
      chartsbot.py
  2. 48
      countrylist.py
  3. 11
      summarypage.py

11
chartsbot.py

@ -94,6 +94,14 @@ class ChartsBot( ):
# Set locale to 'de_DE.UTF-8' # Set locale to 'de_DE.UTF-8'
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8') locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
# provisional-onwiki-activation
page_active = pywikibot.Page( self.site, "Benutzer:JogoBot/active" )
text_active = page_active.get()
if "true" not in text_active.lower():
pywikibot.output( "Bot ist deaktiviert!" )
return False
def run(self): def run(self):
"""Process each page from the generator.""" """Process each page from the generator."""
for page in self.generator: for page in self.generator:
@ -215,7 +223,8 @@ def main(*args):
# pages from the wiki simultaneously. # pages from the wiki simultaneously.
gen = pagegenerators.PreloadingGenerator(gen) gen = pagegenerators.PreloadingGenerator(gen)
bot = ChartsBot(gen, always, force_reload) bot = ChartsBot(gen, always, force_reload)
bot.run() if bot:
bot.run()
else: else:
pywikibot.showHelp() pywikibot.showHelp()

48
countrylist.py

@ -66,7 +66,8 @@ class CountryList():
# Check if page exits # Check if page exits
if not self.page.exists(): if not self.page.exists():
return False raise CountryListError( "CountryList " +
str(wikilink.title) + " does not exists!" )
# Initialise attributes # Initialise attributes
__attr = ( "wikicode", "entry", "chartein", "_chartein_raw", __attr = ( "wikicode", "entry", "chartein", "_chartein_raw",
@ -156,11 +157,18 @@ class CountryList():
# For belgian list we need to select subsection of country # For belgian list we need to select subsection of country
belgian = self.detect_belgian() belgian = self.detect_belgian()
if belgian: # Select Singles-Section
singles_section = self.wikicode.get_sections( # Catch Error if we have none
matches=belgian )[0].get_sections( matches="Singles" )[0] try:
else: if belgian:
singles_section = self.wikicode.get_sections(matches="Singles")[0] singles_section = self.wikicode.get_sections(
matches=belgian )[0].get_sections( matches="Singles" )[0]
else:
singles_section = self.wikicode.get_sections(
matches="Singles" )[0]
except IndexError:
raise CountryListError( "No Singles-Section found!")
# 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
@ -230,7 +238,15 @@ class CountryList():
If param is not present raise Error If param is not present raise Error
""" """
if self.entry.has( "Chartein" ): if self.entry.has( "Chartein" ):
self._chartein_raw = self.entry.get("Chartein").value.strip() self._chartein_raw = self.entry.get("Chartein").value
# Remove possible ref-tags
for ref in self._chartein_raw.ifilter_tags(matches="ref"):
self._chartein_raw.remove( ref )
# Remove whitespace
self._chartein_raw = str(self._chartein_raw).strip()
else: else:
raise CountryListEntryError( "Template Parameter 'Chartein' is \ raise CountryListEntryError( "Template Parameter 'Chartein' is \
missing!" ) missing!" )
@ -256,7 +272,14 @@ missing!" )
If param is not present raise Error If param is not present raise Error
""" """
if self.entry.has( "Titel" ): if self.entry.has( "Titel" ):
self._titel_raw = self.entry.get("Titel").value.strip() self._titel_raw = self.entry.get("Titel").value
# Remove possible ref-tags
for ref in self._titel_raw.ifilter_tags(matches="ref"):
self._titel_raw.remove( ref )
# Remove whitespace
self._titel_raw = str(self._titel_raw).strip()
else: else:
raise CountryListEntryError( "Template Parameter 'Titel' is \ raise CountryListEntryError( "Template Parameter 'Titel' is \
missing!" ) missing!" )
@ -321,7 +344,14 @@ missing!" )
If param is not present raise Error If param is not present raise Error
""" """
if self.entry.has( "Interpret" ): if self.entry.has( "Interpret" ):
self._interpret_raw = self.entry.get("Interpret").value.strip() self._interpret_raw = self.entry.get("Interpret").value
# Remove possible ref-tags
for ref in self._interpret_raw.ifilter_tags(matches="ref"):
self._interpret_raw.remove( ref )
# Remove whitespace
self._interpret_raw = str(self._interpret_raw).strip()
else: else:
raise CountryListEntryError( "Template Parameter 'Interpret' is \ raise CountryListEntryError( "Template Parameter 'Interpret' is \
missing!" ) missing!" )

11
summarypage.py

@ -143,11 +143,8 @@ class SummaryPageEntry():
# Get current year # Get current year
current_year = datetime.now().year current_year = datetime.now().year
# Store old link.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 self.countrylist_wikilink.title:
self.countrylist_wikilink.title.replace( (current_year - 1), self.countrylist_wikilink.title.replace( (current_year - 1),
current_year ) current_year )
@ -160,7 +157,11 @@ class SummaryPageEntry():
# Maybe fallback to last years list # Maybe fallback to last years list
except CountryListError: except CountryListError:
self.countrylist_wikilink.title = link_title # If list is from last year, replace year
if (current_year ) in self.countrylist_wikilink.title:
self.countrylist_wikilink.title.replace( current_year,
(current_year - 1) )
self.countrylist = CountryList( self.countrylist_wikilink ) self.countrylist = CountryList( self.countrylist_wikilink )
self.maybe_parse_countrylist() self.maybe_parse_countrylist()

Loading…
Cancel
Save