Skip to content

Commit

Permalink
Remove blank rows
Browse files Browse the repository at this point in the history
  • Loading branch information
invisibleroads committed May 21, 2024
1 parent 2652b8f commit 26ed17c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions linters/autoformat-csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
def main():
for path in FOLDER.glob('*.csv'):
with path.open(mode='rt') as f:
reader = DictReader(f, dialect='unix')
rows = list(reader)

rows = list(DictReader(f, dialect='unix'))
rows.sort(key=lambda row: (
row['Start Date'], row['End Date'], row['Subject']))

new_rows = []
for row in rows:
for key, value in row.items():
row[key] = value.strip()

if not row['Subject']:
continue
new_rows.append(row)
with path.open(mode='wt') as f:
writer = DictWriter(
f, fieldnames=rows[0].keys(), dialect='unix',
f, fieldnames=new_rows[0].keys(), dialect='unix',
quoting=QUOTE_MINIMAL)
writer.writeheader()
writer.writerows(rows)
writer.writerows(new_rows)


if __name__ == '__main__':
Expand Down

0 comments on commit 26ed17c

Please sign in to comment.