def _parse_save_time(x, funnel_dict): x = _unicode_dict(x) the_str = x.get(u'時間戳記', '') #cfg.logger.debug('the_date_time: %s', the_str) the_list = the_str.split(' ') the_date = the_list[0] the_time = the_list[2] am_pm = the_list[1] the_time_list = the_time.split(':') the_hr = util._int(the_time_list[0]) if the_hr == 12 and am_pm == u'上午': the_time_list[0] = '0' the_time = ':'.join(the_time_list) if am_pm == u'下午' and the_hr != 12: the_time_list[0] = str(util._int(the_time[0]) + 12) the_time = ':'.join(the_time_list) cfg.logger.debug('the_date: %s the_time: %s', the_date, the_time) the_datetime_str = the_date + ' ' + the_time the_datetime = datetime.strptime(the_datetime_str, '%Y/%m/%d %H:%M:%S') the_timestamp = util.datetime_to_timestamp(the_datetime) return the_timestamp
def _parse_date(the_date): the_date_list = the_date.split('/') if len(the_date_list) != 3: return 0 the_year = util._int(the_date_list[0]) the_month = util._int(the_date_list[1]) the_day = util._int(the_date_list[2]) cfg.logger.debug('the_date: %s the_year: %s the_month: %s the_day: %s', the_date, the_year, the_month, the_day) the_datetime = datetime(the_year, the_month, the_day) the_timestamp = util.datetime_to_timestamp(the_datetime) return the_timestamp
def _parse_timestamp(year, month, day, funnel_dict, x): if not year or not month or not day: return 0 try: the_datetime = datetime(year, month, day, tzinfo=timezone("Asia/Taipei")) the_timestamp = util.datetime_to_timestamp(the_datetime) #cfg.logger.debug('year: %s month: %s day: %s the_timestamp: %s', year, month, day, the_timestamp) except Exception as e: cfg.logger.error('unable to parse deliver time: year: %s month: %s day: %s e: %s', year, month, day, e) _add_funnel(funnel_dict, x, 'parse_deliver_time: year: %s month: %s day: %s e: %s' % (year, month, day, e)) the_timestamp = 0 return the_timestamp