def test_laxparsers(): p1 = datetimeparser('%Y-%m-%dT%H:%M:%S') try: v = p1('2002-12-25 00:00:00') except: pass else: assert False, 'expected exception' p2 = datetimeparser('%Y-%m-%dT%H:%M:%S', strict=False) try: v = p2('2002-12-25 00:00:00') except: assert False, 'did not expect exception' else: eq_('2002-12-25 00:00:00', v)
def _get_tasks(self): date = etl.datetimeparser('%m/%d/%Y %H:%M') return (etl.fromcsv(f'{self._dirc}/all_courses.csv', delimiter=';').convert('course_id', 'id').convert( 'courseName', 'course_title').convert( 'university', 'organization_title').convert( 'creationDate', 'starts_at').convert( 'creationDate', date).createdBy)
def _get_tasks(self): # TODO: should owner_name be the instructor id? # yes it can be date = etl.datetimeparser('%m/%d/%Y %H:%M') return (etl.fromcsv( f'{self._dirc}/all_courses.csv', delimiter=',').rename( 'course_id', 'id').rename('courseName', 'course_title').rename( 'university', 'organization_title').rename( 'creationDate', 'starts_at').convert('starts_at', date).addcolumn( 'app_name', [], missing=self.abbrev).rename( 'createdBy', 'owner_name').cut('id', 'course_title', 'organization_title', 'starts_at', 'app_name', 'owner_name'))
from __future__ import division, print_function, absolute_import # datetimeparser() ################## from petl import datetimeparser isodatetime = datetimeparser('%Y-%m-%dT%H:%M:%S') isodatetime('2002-12-25T00:00:00') try: isodatetime('2002-12-25T00:00:99') except ValueError as e: print(e) # dateparser() ############## from petl import dateparser isodate = dateparser('%Y-%m-%d') isodate('2002-12-25') try: isodate('2002-02-30') except ValueError as e: print(e) # timeparser() ############## from petl import timeparser
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Filename: stcfor Auchor: CJ Lin """ import sys import petl petl.fromcsv(sys.argv[1], delimiter=' ', skipinitialspace=True ).convert('YYYYMMDDHH', petl.datetimeparser('%Y%m%d%H') ).setheader(('time', -1, -5, -10) ).melt(('time') ).rename({'variable': 'depth', 'value': 'temp'} ).tocsv('ocm2_stcfor.csv')