New method dates_extract which finds begining and ending at once
This commit is contained in:
44
redfam.py
44
redfam.py
@@ -30,7 +30,9 @@ import locale
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
||||
import mwparserfromhell as mwparser # noqa
|
||||
import pywikibot
|
||||
from pywikibot.tools import deprecated # noqa
|
||||
|
||||
import jogobot
|
||||
from mysqlred import MysqlRedFam
|
||||
@@ -337,6 +339,48 @@ Maximum number of articles in red_fam exceeded, maximum number is 8, \
|
||||
else:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def extract_dates( cls, text, isarchive=False ):
|
||||
"""
|
||||
Returns tuple of the first and maybe last timestamp of a section.
|
||||
Last timestamp is only returned if there is a done notice or param
|
||||
*isarchiv* is set to 'True'
|
||||
|
||||
@param text Text to search in
|
||||
@type line Any Type castable to str
|
||||
@param isarchive If true skip searching done notice (on archivepages)
|
||||
@type isarchive bool
|
||||
|
||||
@returns Timestamps, otherwise None
|
||||
@returntype tuple of strs
|
||||
"""
|
||||
|
||||
# Match all timestamps
|
||||
matches = cls.__timestamp_pat.findall( str( text ) )
|
||||
if matches:
|
||||
|
||||
# First one is beginning
|
||||
# Since some timestamps are broken we need to reconstruct them
|
||||
# by regex match groups
|
||||
beginning = ( matches[0][0] + ", " + matches[0][1] + ". " +
|
||||
matches[0][2] + ". " + matches[0][3] )
|
||||
|
||||
# Last one maybe is ending
|
||||
# Done notice format 1
|
||||
# Done notice format 2
|
||||
# Or on archivepages
|
||||
if ( cls.__done_notice in text or
|
||||
cls.__done_notice2 in text or
|
||||
isarchive ):
|
||||
|
||||
ending = ( matches[-1][0] + ", " + matches[-1][1] + ". " +
|
||||
matches[-1][2] + ". " + matches[-1][3] )
|
||||
|
||||
else:
|
||||
ending = None
|
||||
|
||||
return (beginning, ending)
|
||||
|
||||
@classmethod
|
||||
def is_beginning( cls, line ):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user