Here is one approach.
I noticed that there is no separator between the lines. To clear the input, I make a few assumptions:
- "" - "" ,
- (: no
"") - (..:
"") "
:
>>> response = '"Subject";"Start Date";"Start Time";"End Date";"End Time";"All day event";"Description""Play football";"16/11/2009";"10:00 PM";"16/11/2009";"11:00 PM";"false";"""Watch 2012";"20/11/2009";"07:00 PM";"";"08:00 PM";"false";"""";"17/11/2009";"9:00 AM";"17/11/2009";"10:00 AM";"false";""'
,
" ", .
" (|) ", :
>>> response.replace('""', '|').replace('"', '')
'Subject;Start Date;Start Time;End Date;End Time;All day event;Description|Play football;16/11/2009;10:00 PM;16/11/2009;11:00 PM;false;|Watch 2012;20/11/2009;07:00 PM;|;08:00 PM;false;||;17/11/2009;9:00 AM;17/11/2009;10:00 AM;false;|'
(: Watch 2012 End Date), : ;|; - :
>>> response.replace('""', '|').replace('"', '').replace(';|;', ';;')
'Subject;Start Date;Start Time;End Date;End Time;All day event;Description|Play football;16/11/2009;10:00 PM;16/11/2009;11:00 PM;false;|Watch 2012;20/11/2009;07:00 PM;;08:00 PM;false;||;17/11/2009;9:00 AM;17/11/2009;10:00 AM;false;|'
| . , |?
>>> response.replace('""', '|').replace('"', '').replace(';|;', ';;').split('|')
['Subject;Start Date;Start Time;End Date;End Time;All day event;Description',
'Play football;16/11/2009;10:00 PM;16/11/2009;11:00 PM;false;',
'Watch 2012;20/11/2009;07:00 PM;;08:00 PM;false;',
'',
';17/11/2009;9:00 AM;17/11/2009;10:00 AM;false;',
'']
, - . ; , ''. , | , :
>>> "a|b||c".split('|')
['a', 'b', '', 'c']
:
>>> "a||b|c|".split('|')
['a', '', 'b', 'c', '']
, :
>>> rows = [row for row in response.replace('""', '|').replace('"', '').replace(';|;', ';;').split('|') if row]
>>> rows
['Subject;Start Date;Start Time;End Date;End Time;All day event;Description',
'Play football;16/11/2009;10:00 PM;16/11/2009;11:00 PM;false;',
'Watch 2012;20/11/2009;07:00 PM;;08:00 PM;false;',
';17/11/2009;9:00 AM;17/11/2009;10:00 AM;false;']
; . -, :
>>> dict_keys = rows[0].split(';')
>>> dict_keys
['Subject',
'Start Date',
'Start Time',
'End Date',
'End Time',
'All day event',
'Description']
, :
>>> import itertools
>>> events = []
>>> for row in rows[1:]:
... d = {}
... for k, v in itertools.izip(dict_keys, row.split(';')):
... d[k] = v
... events.append(d)
...
>>> events
[{'All day event': 'false',
'Description': '',
'End Date': '16/11/2009',
'End Time': '11:00 PM',
'Start Date': '16/11/2009',
'Start Time': '10:00 PM',
'Subject': 'Play football'},
{'All day event': 'false',
'Description': '',
'End Date': '',
'End Time': '08:00 PM',
'Start Date': '20/11/2009',
'Start Time': '07:00 PM',
'Subject': 'Watch 2012'},
{'All day event': 'false',
'Description': '',
'End Date': '17/11/2009',
'End Time': '10:00 AM',
'Start Date': '17/11/2009',
'Start Time': '9:00 AM',
'Subject': ''}]
, !
:
- ,
| , ; . - (: "": "" 2012 ")
- " " boolean : D