#NEWLINE# def ical2text( ical_string ) : #NEWLINE# #INDENT# import vobject #NEWLINE# result = [ ] #NEWLINE# if isinstance ( ical_string , str ) : #NEWLINE# #INDENT# parsedCal = vobject . readOne ( ical_string ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# parsedCal = vobject . readOne ( ical_string ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# parsedCal = vobject . readOne ( ical_string . decode ( 'utf-8' , 'ignore' ) ) #NEWLINE# #UNINDENT# #UNINDENT# for event in parsedCal . getChildren ( ) : #NEWLINE# #INDENT# if ( event . name == 'VEVENT' ) : #NEWLINE# #INDENT# if hasattr ( event , 'dtstart' ) : #NEWLINE# #INDENT# start = event . dtstart . value . strftime ( '%F %H:%M' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# start = 'unknown start date' #NEWLINE# #UNINDENT# if hasattr ( event , 'dtend' ) : #NEWLINE# #INDENT# end = event . dtend . value . strftime ( '%F %H:%M' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# end = start #NEWLINE# #UNINDENT# if ( start == end ) : #NEWLINE# #INDENT# date_str = start #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# date_str = ( '%s -- %s' % ( start , end ) ) #NEWLINE# #UNINDENT# result . append ( ( '%s: %s' % ( parsedCal , event . summary . value ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# return '\n' . join ( result )