diff --git a/red_fam.py b/red_fam.py index b054d1f..dec14eb 100644 --- a/red_fam.py +++ b/red_fam.py @@ -3,6 +3,7 @@ import hashlib import re +import locale from datetime import datetime from mysql_red import MYSQL_RED_FAM @@ -57,7 +58,16 @@ class RED_FAM_PARSER( RED_FAM ): """ # Define the timestamp format - __timestamp_format = "%H:%M, %d. %b. %Y (%Z)" + __timestamp_format = "%H:%M, %d. %b. %Y (%Z)" + + # Define section heading re.pattern + __sectionhead_pat = re.compile( r"={3,4}[^=]*={3,4}" ) + + # 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\)" ) + + # Textpattern for recognisation of done-notices + __done_notice = ":Archivierung dieses Abschnittes wurde gewünscht von:" def __init__( self, red_fam_heading, red_page_id, red_page_archive, beginning, ending=None ): """ @@ -164,6 +174,7 @@ class RED_FAM_PARSER( RED_FAM ): @returns datetime Datetime object """ + locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8') if( isinstance( timestamp, datetime ) ): return timestamp @@ -194,6 +205,51 @@ class RED_FAM_PARSER( RED_FAM ): # Since status change means something has changed, update database if( self._status != self.__mysql.data[ 'status' ] or self._beginning != self.__mysql.data[ 'beginning' ] or self._ending != self.__mysql.data[ 'ending' ] or self._red_page_id != self.__mysql.data[ 'red_page_id' ] ): self.__mysql.update_fam( self._red_page_id, self._beginning, self._ending, self._status ) + + @classmethod + def is_sectionheading( cls, line ): + """ + Checks wether given line is a red_fam section heading + + @param line string String to check + + @returns bool Returns True if it is a section heading, otherwise false + """ + + if cls.__sectionhead_pat.search( line ): + return True + else: + return False + + @classmethod + def is_beginning( cls, line ): + """ + Returns the first timestamp found in line, otherwise None + + @param str line String to search in + + @returns str Timestamp, otherwise None + """ + + result = cls.__timestamp_pat.search( line ) + if result: + return result.group() + else: + return None + + @classmethod + def is_ending( cls, line ): + """ + Returns the timestamp of done notice ( if one ), otherwise None + @param str line String to search in + + @returns str Timestamp, otherwise None + """ + if cls.__done_notice in line: + result = cls.__timestamp_pat.search( line ) + if result: + return result.group() + return None class RED_FAM_WORKER( RED_FAM ): """