Created
February 8, 2019 15:51
-
-
Save M-D-M/e559265227d4c5b8bb2d69cd39062e42 to your computer and use it in GitHub Desktop.
Converts Google Ical Format to CSV, with local timezones
This file contains 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
#!/usr/bin/env python3 | |
from datetime import datetime | |
from pytz import timezone | |
from csv_ical import Convert | |
import sys | |
import csv | |
LOCAL_TZ = timezone('US/Eastern') | |
convert = Convert() | |
convert.SAVE_LOCATION = sys.argv[1] | |
convert.CSV_FILE_LOCATION = '{0}.csv'.format(convert.SAVE_LOCATION) | |
print('Converting ical into csv...') | |
convert.read_ical(convert.SAVE_LOCATION) | |
convert.make_csv() | |
convert.save_csv(convert.CSV_FILE_LOCATION) | |
def asLocalTime(utcTime): | |
return datetime.fromisoformat(utcTime).astimezone(LOCAL_TZ) | |
outFmt = '%Y-%m-%d %H:%M' | |
new_csv_file_loc = '{0}.time_converted.csv'.format(convert.SAVE_LOCATION) | |
print('Converting times in csv to eastern time...') | |
with open(convert.CSV_FILE_LOCATION,'r',newline='') as old_csv, open(new_csv_file_loc,'w',newline='') as new_csv: | |
oldCsvReader = csv.reader(old_csv) | |
newCsvWriter = csv.writer(new_csv) | |
for row in oldCsvReader: | |
startTime = asLocalTime(row[1]).strftime(outFmt) | |
endTime = asLocalTime(row[2]).strftime(outFmt) | |
newCsvWriter.writerow([row[0],startTime,endTime,row[3]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment