Last active
August 2, 2017 18:23
-
-
Save lukeorland/ad036a7fd6d293724229eddc301aa0eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import argparse | |
import csv | |
import re | |
fields = ("Start Time", "End Time", "Activity", "Text", "Notes") | |
def parse_arguments(): | |
parser = argparse.ArgumentParser(description='') | |
parser.add_argument('csv_path', ) | |
return parser.parse_args() | |
def strip_date(timestamp): | |
return timestamp.split(' ')[1] | |
def demilitarize(timestamp): | |
hour, minute = timestamp.split(':') | |
pm = False | |
hour = int(hour) | |
if hour > 12: | |
pm = True | |
hour -= 12 | |
return f"{hour}:{minute}{'pm' if pm else 'am'}" | |
def clean_timestamp(timestamp): | |
return demilitarize(strip_date(timestamp)) | |
def clean_text(text): | |
text = re.sub('^Río ', '', text) | |
text = re.sub('^is ', '', text) | |
return text | |
def main(): | |
args = parse_arguments() | |
with open(args.csv_path) as csv_file: | |
reader = csv.DictReader(csv_file) | |
data = [] | |
for row in reader: | |
row_data = { | |
k.lower().replace(' ', '_'): row[k] | |
for k in fields | |
} | |
data.append(row_data) | |
for d in sorted(data, key=lambda x: x['start_time']): | |
line_parts = [ | |
clean_timestamp(d['start_time']), | |
"to " + clean_timestamp(d['end_time']), | |
clean_text(d['text']), | |
d['notes'], | |
] | |
print("\t".join(line_parts)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment