Skip to content

Instantly share code, notes, and snippets.

@pvarsh
Created February 20, 2015 19:15
Show Gist options
  • Save pvarsh/359728f74bb8235e5b79 to your computer and use it in GitHub Desktop.
Save pvarsh/359728f74bb8235e5b79 to your computer and use it in GitHub Desktop.
from datetime import datetime
import parsekit
class FilterRows(parsekit.Step):
start_row = parsekit.Argument(
"The row to start emitting from.",
required=True,
type=int)
skip_empty_row = parsekit.Argument(
"Skip empty row.",
type=bool)
skip_day_start = parsekit.Argument(
"Skip row starting with day.",
type=bool)
def configure(self, options):
self.row_counter = 0
def run(self, record, metadata):
self.row_counter += 1
if self.row_counter >= self.options.start_row:
if self.options.skip_empty_row:
if any(record):
if self.options.skip_day_start:
first_val = record[0].split(',')[0]
try:
datetime.strptime(first_val, '%A')
except:
return record, metadata
else:
return record, metadata
else:
if self.options.skip_day_start:
first_val = record[0].split(',')[0]
try:
datetime.strptime(first_val, '%A')
except:
return record, metadata
else:
return record, metadata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment