parsing date
This commit is contained in:
parent
7be296856a
commit
4d26da8768
1 changed files with 23 additions and 3 deletions
|
@ -1,4 +1,6 @@
|
|||
import os
|
||||
from datetime import datetime, date, timedelta
|
||||
import logging
|
||||
|
||||
from splinter import Browser
|
||||
|
||||
|
@ -73,14 +75,32 @@ class Messagenet(object):
|
|||
ok = r.has_class('statusOK')
|
||||
cells = r.find_by_tag('td')
|
||||
call_type_desc = cells[0].value
|
||||
date = cells[1].value
|
||||
# avanzato: prendi la data {{{2
|
||||
human_date = cells[1].value
|
||||
# avanzato: parsa la data {{{2
|
||||
try:
|
||||
parsed_date = datetime.strptime(human_date, '%Y-%m-%d, %H.%M.%S')
|
||||
except ValueError as exc:
|
||||
print 'parsing date', exc
|
||||
if human_date.startswith('Oggi, '):
|
||||
d = date.today()
|
||||
t = datetime.strptime(human_date.split(',', 1)[1].strip(),
|
||||
'%H.%M.%S').time()
|
||||
parsed_date = datetime.combine(d, t)
|
||||
elif human_date.startswith('Ieri, '):
|
||||
d = date.today() - timedelta(days=1)
|
||||
t = datetime.strptime(human_date.split(',', 1)[1].strip(),
|
||||
'%H.%M.%S').time()
|
||||
parsed_date = datetime.combine(d, t)
|
||||
else:
|
||||
logging.error("Could not parse date '%s'" % human_date)
|
||||
parsed_date = None
|
||||
# }}}
|
||||
call_from = cells[2].value
|
||||
deviata = bool(cells[3].value)
|
||||
call_to = cells[4].value
|
||||
duration = cells[5].value
|
||||
yield {'status': (ok, call_type_desc), 'date': date,
|
||||
yield {'status': (ok, call_type_desc),
|
||||
'date': human_date, 'datetime': parsed_date,
|
||||
'deviata': deviata,
|
||||
'from': call_from, 'to': call_to, 'duration': duration}
|
||||
|
||||
|
|
Loading…
Reference in a new issue