Skip to content

Commit

Permalink
reuse function parse_timestamp in script
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosp420 committed May 5, 2015
1 parent 0eb31bc commit c6f2cdd
Showing 1 changed file with 5 additions and 51 deletions.
56 changes: 5 additions & 51 deletions voseq/public_interface/management/commands/_migrate_db.py
Expand Up @@ -293,37 +293,8 @@ def import_table_sequences(self):
item['gene_code'] = item['geneCode']
del item['geneCode']

try:
date_obj = datetime.datetime.strptime(item['time_created'], '%Y-%m-%d').replace(tzinfo=TZINFO)
except ValueError as e:
date_obj = None
if self.verbosity != 0:
print(e)
print("WARNING:: Could not parse dateCreation properly.")
print("WARNING:: Using empty date for `time_created` for code %s and gene_code %s." % (item['code_id'], item['gene_code']))
except TypeError as e:
date_obj = None
if self.verbosity != 0:
print(e)
print("WARNING:: Could not parse dateCreation properly.")
print("WARNING:: Using empty date for `time_created` for code %s and gene_code %s." % (item['code_id'], item['gene_code']))

item['time_created'] = date_obj

try:
date_obj = datetime.datetime.strptime(item['time_edited'], '%Y-%m-%d').replace(tzinfo=TZINFO)
except ValueError:
date_obj = None
if self.verbosity != 0:
print("WARNING:: Could not parse dateModification properly.")
print("WARNING:: Using empty date for `time_edited` for code %s." % item['code_id'])
except TypeError:
date_obj = None
if self.verbosity != 0:
print("WARNING:: Could not parse dateCreation properly.")
print("WARNING:: Using empty as date for `time_edited` for code %s." % item['code_id'])

item['time_edited'] = date_obj
item['time_created'] = self.parse_timestamp(item['time_created'])
item['time_edited'] = self.parse_timestamp(item['time_edited'])

if item['sequences'] is not None:
ambiguous_chars = item['sequences'].count('?') + item['sequences'].count('-')
Expand Down Expand Up @@ -509,26 +480,9 @@ def import_table_vouchers(self):
if item['longitude'] is not None:
item['longitude'] = float(item['longitude'])

if item['dateCollection'] is not None:
try:
date_obj = datetime.datetime.strptime(item['dateCollection'], '%Y-%m-%d').date()
except ValueError:
date_obj = None
item['dateCollection'] = date_obj

if item['dateExtraction'] is not None:
try:
date_obj = datetime.datetime.strptime(item['dateExtraction'], '%Y-%m-%d').date()
except ValueError:
date_obj = None
item['dateExtraction'] = date_obj

if item['timestamp'] is not None:
try:
date_obj = datetime.datetime.strptime(item['timestamp'], '%Y-%m-%d %H:%M:%S').replace(tzinfo=TZINFO)
except ValueError:
date_obj = None
item['timestamp'] = date_obj
item['dateCollection'] = self.parse_timestamp(item['dateCollection'])
item['dateExtraction'] = self.parse_timestamp(item['dateExtraction'])
item['timestamp'] = self.parse_timestamp(item['timestamp'])

# Deal with flickr images
if item['voucherImage'] == '':
Expand Down

0 comments on commit c6f2cdd

Please sign in to comment.