#NEWLINE# def parse_entries( input_file ) : #NEWLINE# #INDENT# global all_months , all_entries #NEWLINE# file = codecs . open ( input_file , 'r' , 'utf-8' ) #NEWLINE# try : #NEWLINE# #INDENT# text = file . read ( ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# file . close ( ) #NEWLINE# #UNINDENT# parser = Parser ( ) #NEWLINE# settings = OptionParser ( components = ( Parser , docutils . writers . html4css1 . Writer ) ) . get_default_values ( ) #NEWLINE# docroot = docutils . utils . new_document ( file . name , settings ) #NEWLINE# parser . parse ( entry , docroot ) #NEWLINE# for i in docroot . traverse ( condition = docutils . nodes . section ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# date_string = re . findall ( '(\\d{4}-\\d{1,2}-\\d{1,2})' , str ( i . children [ 0 ] ) ) [ 0 ] #NEWLINE# logging . debug ( ( 'Found entry: %s' % date_string ) ) #NEWLINE# date = datetime . strptime ( date_string , '%Y-%m-%d' ) #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# sys . stderr . write ( ( 'can not parse section : %s\n' % str ( i . children [ 0 ] ) ) ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# translator = HTMLTranslator ( docroot ) #NEWLINE# i . walkabout ( translator ) #NEWLINE# body = '' . join ( translator . body ) #NEWLINE# entry = Entry ( date , body ) #NEWLINE# all_months . add ( entry . month ) #NEWLINE# all_entries [ entry . month ] . append ( entry ) #NEWLINE# #UNINDENT# all_months = sorted ( all_months , reverse = True )