def tf_from_s(s): """ Return a time float from a date string. Try every format we know. """ from feed.date.rfc3339 import tf_from_timestamp as tf_from_rfc3339 from feed.date.rfc822 import tf_from_timestamp as tf_from_rfc822 tf = tf_from_rfc3339(s) if tf is not None: return tf tf = tf_from_rfc822(s) if tf is not None: return tf return None
val = val[f] # Special cases # Only want id part of issue_url if fields[0] == 'issue_url': val = val.split('/')[-1] # Separate dates and times for STATA if fields[-1][-3:] == '_at': # Handle null values if not val: fields_read.append(val) break # Timestamps are ISO 8601 but this works tf = tf_from_rfc3339(val) dt = datetime.datetime.utcfromtimestamp(tf) # Append the time to fields_read fields_read.append(dt.strftime("%H:%M:%S")) # Date is stored in val val = dt.strftime("%d%b%Y") # Handle unicode values if type(val) == unicode: val = val.encode('utf-8') fields_read.append(val) # Write fields from the current item to a csv row