|
@ -298,9 +298,54 @@ missing!" ) |
|
|
parts.append( word ) |
|
|
parts.append( word ) |
|
|
parts.append( " " ) |
|
|
parts.append( " " ) |
|
|
|
|
|
|
|
|
# If we have indexes with out links, search for links |
|
|
# If we have indexes without links, search for links |
|
|
if indexes: |
|
|
if indexes: |
|
|
|
|
|
|
|
|
|
|
|
parts = self._search_links( parts, indexes ) |
|
|
|
|
|
|
|
|
|
|
|
# Join the collected links |
|
|
|
|
|
sep = " " |
|
|
|
|
|
self.interpret = sep.join( parts ) |
|
|
|
|
|
|
|
|
|
|
|
# Nothing to do, just use raw |
|
|
|
|
|
else: |
|
|
|
|
|
self.interpret = self._interpret_raw |
|
|
|
|
|
|
|
|
|
|
|
def get_interpret_value( self ): |
|
|
|
|
|
""" |
|
|
|
|
|
Reads value of Interpret parameter |
|
|
|
|
|
If param is not present raise Error |
|
|
|
|
|
""" |
|
|
|
|
|
if self.entry.has( "Interpret" ): |
|
|
|
|
|
self._interpret_raw = self.entry.get("Interpret").value.strip() |
|
|
|
|
|
else: |
|
|
|
|
|
raise CountryListEntryError( "Template Parameter 'Interpret' is \ |
|
|
|
|
|
missing!" ) |
|
|
|
|
|
|
|
|
|
|
|
def _search_links( self, keywords, indexes=None ): |
|
|
|
|
|
""" |
|
|
|
|
|
Search matching wikilinks for keyword(s) in CountryList's wikicode |
|
|
|
|
|
|
|
|
|
|
|
@param keywords: One or more keywords to search for |
|
|
|
|
|
@type keywords: str, list |
|
|
|
|
|
@param indexes: List with numeric indexes for items of keywords to work |
|
|
|
|
|
on only |
|
|
|
|
|
@type indexes: list of ints |
|
|
|
|
|
@return: List or String with replaced keywords |
|
|
|
|
|
@return type: str, list |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
# Maybe convert keywords string to list |
|
|
|
|
|
if( isinstance( keywords, str ) ): |
|
|
|
|
|
keywords = [ keywords, ] |
|
|
|
|
|
string = True |
|
|
|
|
|
else: |
|
|
|
|
|
string = False |
|
|
|
|
|
|
|
|
|
|
|
# If indexes worklist was not provided, work on all elements |
|
|
|
|
|
if not indexes: |
|
|
|
|
|
indexes = range( len( keywords ) - 1 ) |
|
|
|
|
|
|
|
|
# Iterate over wikilinks of refpage and try to find related links |
|
|
# Iterate over wikilinks of refpage and try to find related links |
|
|
for wikilink in self.wikicode.ifilter_wikilinks(): |
|
|
for wikilink in self.wikicode.ifilter_wikilinks(): |
|
|
|
|
|
|
|
@ -308,11 +353,11 @@ missing!" ) |
|
|
for index in indexes: |
|
|
for index in indexes: |
|
|
|
|
|
|
|
|
# Check wether wikilink matches |
|
|
# Check wether wikilink matches |
|
|
if( parts[index] == wikilink.text or |
|
|
if( keywords[index] == wikilink.text or |
|
|
parts[index] == wikilink.title ): |
|
|
keywords[index] == wikilink.title ): |
|
|
|
|
|
|
|
|
# Overwrite name with complete wikilink |
|
|
# Overwrite name with complete wikilink |
|
|
parts[index] = str( wikilink ) |
|
|
keywords[index] = str( wikilink ) |
|
|
|
|
|
|
|
|
# Remove index from worklist |
|
|
# Remove index from worklist |
|
|
indexes.remove( index ) |
|
|
indexes.remove( index ) |
|
@ -324,24 +369,11 @@ missing!" ) |
|
|
if not indexes: |
|
|
if not indexes: |
|
|
break |
|
|
break |
|
|
|
|
|
|
|
|
# Join the collected links |
|
|
# Choose wether return list or string based on input type |
|
|
sep = " " |
|
|
if not string: |
|
|
self.interpret = sep.join( parts ) |
|
|
return keywords |
|
|
|
|
|
|
|
|
# Nothing to do, just use raw |
|
|
|
|
|
else: |
|
|
|
|
|
self.interpret = self._interpret_raw |
|
|
|
|
|
|
|
|
|
|
|
def get_interpret_value( self ): |
|
|
|
|
|
""" |
|
|
|
|
|
Reads value of Interpret parameter |
|
|
|
|
|
If param is not present raise Error |
|
|
|
|
|
""" |
|
|
|
|
|
if self.entry.has( "Interpret" ): |
|
|
|
|
|
self._interpret_raw = self.entry.get("Interpret").value.strip() |
|
|
|
|
|
else: |
|
|
else: |
|
|
raise CountryListEntryError( "Template Parameter 'Interpret' is \ |
|
|
return keywords[0] |
|
|
missing!" ) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CountryListError( Exception ): |
|
|
class CountryListError( Exception ): |
|
|