#NEWLINE# def run( args = None ) : #NEWLINE# #INDENT# args = parse_args ( args ) #NEWLINE# locale . setlocale ( locale . LC_ALL , args . locale ) #NEWLINE# if ( args . format is None ) : #NEWLINE# #INDENT# args . format = ( os . path . splitext ( args . output ) [ 1 ] [ 1 : ] if args . output else 'html' ) #NEWLINE# #UNINDENT# if ( args . format . lower ( ) in [ 'md' , 'markdown' , 'mdown' , 'mkdn' ] ) : #NEWLINE# #INDENT# args . format = 'md' #NEWLINE# #UNINDENT# args . journal = os . path . expanduser ( args . journal ) #NEWLINE# if ( not os . path . exists ( args . journal ) ) : #NEWLINE# #INDENT# return ( 'File not found: ' + args . journal ) #NEWLINE# #UNINDENT# if ( not os . path . exists ( os . path . join ( args . journal , 'entries' ) ) ) : #NEWLINE# #INDENT# return ( 'Not a valid Day One package: ' + args . journal ) #NEWLINE# #UNINDENT# tags = args . tags #NEWLINE# if ( tags is not None ) : #NEWLINE# #INDENT# if ( tags != 'any' ) : #NEWLINE# #INDENT# tags = [ tag . strip ( ) for tag in tags . split ( ',' ) ] #NEWLINE# #UNINDENT# #UNINDENT# excluded_tags = args . exclude #NEWLINE# if ( excluded_tags is not None ) : #NEWLINE# #INDENT# excluded_tags = [ tag . strip ( ) for tag in excluded_tags . split ( ',' ) ] #NEWLINE# #UNINDENT# dates = [ args . before , args . after ] #NEWLINE# for ( i , date ) in enumerate ( dates ) : #NEWLINE# #INDENT# if date : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# dates [ i ] = dateutil . parser . parse ( date ) #NEWLINE# #UNINDENT# except ( ValueError , OverflowError ) : #NEWLINE# #INDENT# return "Unable to parse date '{0}'" . format ( date ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# ( before , after ) = dates #NEWLINE# generator = dayone_export ( args . journal , template = args . template , reverse = args . reverse , tags = tags , exclude = excluded_tags , before = before , after = after , format = args . format , template_dir = args . template_dir , autobold = after . autobold , nl2br = args . nl2br , filename_template = args . output ) #NEWLINE# try : #NEWLINE# #INDENT# for ( filename , output ) in generator : #NEWLINE# #INDENT# if args . output : #NEWLINE# #INDENT# with codecs . open ( filename , 'w' , encoding = 'utf-8' ) as f : #NEWLINE# #INDENT# f . write ( output ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# compat . print_bytes ( output . encode ( 'utf-8' ) ) #NEWLINE# compat . print_bytes ( '\n' . encode ( 'utf-8' ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except jinja2 . TemplateNotFound as err : #NEWLINE# #INDENT# return template_not_found_message ( err ) #NEWLINE# #UNINDENT# except PlistError as err : #NEWLINE# #INDENT# return str ( err )