Since some timestamps are broken we need to reconstruct them by regex match groups
Prevents ValueErrors of datetime.strptime in most cases
This commit is contained in:
31
red_fam.py
31
red_fam.py
@@ -59,13 +59,12 @@ class RED_FAM_PARSER( RED_FAM ):
|
|||||||
|
|
||||||
# Define the timestamp format
|
# Define the timestamp format
|
||||||
__timestamp_format = "%H:%M, %d. %b. %Y (%Z)"
|
__timestamp_format = "%H:%M, %d. %b. %Y (%Z)"
|
||||||
__timestamp_format2 = "%H:%M, %d. %b %Y (%Z)" # Catch missing point after month abreviation
|
|
||||||
|
|
||||||
# Define section heading re.pattern
|
# Define section heading re.pattern
|
||||||
__sectionhead_pat = re.compile( r"^=+.*\[\[.+\]\].*\[\[.+\]\].*=+" )
|
__sectionhead_pat = re.compile( r"^=+.*\[\[.+\]\].*\[\[.+\]\].*=+" )
|
||||||
|
|
||||||
# Define timestamp re.pattern
|
# Define timestamp re.pattern
|
||||||
__timestamp_pat = re.compile( r"(\d{2}:\d{2}, \d{1,2}. (Jan|Feb|Mär|Apr|Mai|Jun|Jul|Aug|Sep|Okt|Nov|Dez).? \d{4} \(CES?T\))" )
|
__timestamp_pat = re.compile( r"(\d{2}:\d{2}), (\d{1,2}). (Jan|Feb|Mär|Apr|Mai|Jun|Jul|Aug|Sep|Okt|Nov|Dez).? (\d{4}) (\(CES?T\))" )
|
||||||
|
|
||||||
# Textpattern for recognisation of done-notices
|
# Textpattern for recognisation of done-notices
|
||||||
__done_notice = ":<small>Archivierung dieses Abschnittes wurde gewünscht von:"
|
__done_notice = ":<small>Archivierung dieses Abschnittes wurde gewünscht von:"
|
||||||
@@ -178,11 +177,7 @@ class RED_FAM_PARSER( RED_FAM ):
|
|||||||
if( isinstance( timestamp, datetime ) ):
|
if( isinstance( timestamp, datetime ) ):
|
||||||
return timestamp
|
return timestamp
|
||||||
else:
|
else:
|
||||||
# Catch missing point after month abreviation
|
|
||||||
try:
|
|
||||||
result = datetime.strptime( timestamp, type( self ).__timestamp_format )
|
result = datetime.strptime( timestamp, type( self ).__timestamp_format )
|
||||||
except ValueError:
|
|
||||||
result = datetime.strptime( timestamp, type( self ).__timestamp_format2 )
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def status( self ):
|
def status( self ):
|
||||||
@@ -251,9 +246,11 @@ class RED_FAM_PARSER( RED_FAM ):
|
|||||||
@returns str Timestamp, otherwise None
|
@returns str Timestamp, otherwise None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
result = cls.__timestamp_pat.search( line )
|
match = cls.__timestamp_pat.search( line )
|
||||||
if result:
|
if match:
|
||||||
return result.group()
|
# Since some timestamps are broken we need to reconstruct them by regex match groups
|
||||||
|
result = match.group(1) + ", " + match.group(2) + ". " + match.group(3) + ". " + match.group(4) + " " + match.group(5)
|
||||||
|
return result
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -266,9 +263,11 @@ class RED_FAM_PARSER( RED_FAM ):
|
|||||||
@returns str Timestamp, otherwise None
|
@returns str Timestamp, otherwise None
|
||||||
"""
|
"""
|
||||||
if ( cls.__done_notice in line ) or ( cls.__done_notice2 in line ):
|
if ( cls.__done_notice in line ) or ( cls.__done_notice2 in line ):
|
||||||
result = cls.__timestamp_pat.search( line )
|
match = cls.__timestamp_pat.search( line )
|
||||||
if result:
|
if match:
|
||||||
return result.group()
|
# Since some timestamps are broken we need to reconstruct them by regex match groups
|
||||||
|
result = match.group(1) + ", " + match.group(2) + ". " + match.group(3) + ". " + match.group(4) + " " + match.group(5)
|
||||||
|
return result
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -279,9 +278,11 @@ class RED_FAM_PARSER( RED_FAM ):
|
|||||||
|
|
||||||
@returns str Timestamp, otherwise None
|
@returns str Timestamp, otherwise None
|
||||||
"""
|
"""
|
||||||
result = cls.__timestamp_pat.findall( line )
|
matches = cls.__timestamp_pat.findall( line )
|
||||||
if result:
|
if matches:
|
||||||
return result[-1][0]
|
# Since some timestamps are broken we need to reconstruct them by regex match groups
|
||||||
|
result = matches[-1][0] + ", " + matches[-1][1] + ". " + matches[-1][2] + ". " + matches[-1][3] + " " + matches[-1][4]
|
||||||
|
return result
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user