Skip to content

Instantly share code, notes, and snippets.

@paulgessinger
Last active June 23, 2018 12:24
Show Gist options
  • Save paulgessinger/472e31507f9d69ef4f30b4de70c18e94 to your computer and use it in GitHub Desktop.
Save paulgessinger/472e31507f9d69ef4f30b4de70c18e94 to your computer and use it in GitHub Desktop.
ACR shifts to ICS
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import csv\n",
"from datetime import datetime, timedelta\n",
"from ics import Calendar, Event\n",
"import dateutil.tz\n",
"import arrow"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"f = open(\"/Users/Paul/Downloads/shifts.csv\")\n",
"rd = list(csv.DictReader(f, delimiter=\",\"))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"c = Calendar()\n",
"for row in rd:\n",
" task = row[\"Task\"]\n",
" start = int(row[\"HOUR_FROM\"])\n",
" end = int(row[\"HOUR_TO\"])\n",
" monday = arrow.get(row[\"Date\"], \"DD MMM YYYY\", tzinfo=\"Europe/Berlin\")\n",
"\n",
" shifts = []\n",
" days = (\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\")\n",
" for i, d in enumerate(days):\n",
" val = row[d]\n",
" if \"\" == val.strip(): continue\n",
" \n",
" shift_start = monday.shift(days=i, hours=start)\n",
" shift_end = monday.shift(days=i, hours=end)\n",
" \n",
" e = Event()\n",
" e.begin = shift_start\n",
" e.end = shift_end\n",
" e.name = task\n",
" c.events.add(e)\n",
" \n",
"with open(\"/Users/Paul/Downloads/shifts.ics\", \"w\") as f:\n",
" f.writelines(c)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment