188 lines
7.4 KiB
Text
188 lines
7.4 KiB
Text
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 2,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"from ics import Calendar, Event\n",
|
||
"from ics.grammar.parse import ContentLine\n",
|
||
"import datetime\n",
|
||
"import os"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 36,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"275 entries loaded.\n",
|
||
"169 with email.\n",
|
||
"89 with VT.\n",
|
||
"73 without duplicates.\n",
|
||
"info@psychotherapie-eitel.de, psychotherapie-spindler@web.de, praxis-v-kollenbaum@gmx.de, mail@praxis-sentuerk.de, info@praxis-kusche-mall.de, moers@psychotherapie-halbeis.de, praxis.stracke@tuta.com, praxis@schimanski-psychotherapie.de, praxisdoerner@gmx.de, buergerpraxiska@online.de, info@mrl-praxis.de, psychotherapie-koeck@posteo.de, psychotherapie.haeusser@gmx.com, praxis@psychotherapie-dölker.de, j.schmidt@praxis-p3.de, info@praxislott.de, hafferisabel@aol.com, praxis@psychotherapiewissen.de, praxis@psychotherapielutz.de, shrink1@web.de, praxis.klene-gaspard@t-online.de, kvt.diez@gmail.com, mail@gertrud-fahnenbruck.de, praxis.reventlow@gmx.de, noreen.weiler@protonmail.com, praxis@michael-schwehn.de, answer@stahl-eversberg.de, praxis@psychiatricum-ka.de, praxis.urban@outlook.com, praxis@brening-becker.de, praxis@drdamian.de, info@ptvo.de, praxis@wieske.de, hansbiewer@web.de, info@psychotherapiepraxis-borovac.de, praxis.friedebach@web.de, praxis@julia-luecke.de, kontakt@psychotherapie-heuser.de, info@praxis-seekircher.de, mail@psychotherapie-klingel.de, praxis@helma-blaurock.de, praxis@psychotherapie-okello.de, psychotherapie@bianca-maria-ehbauer.de, therapeut.schorn@web.de, praxis-burkart@t-online.de, mail@psychotherapie-schauer.de, praxis@erb-bies.de, praxis@psychotherapie-senger.de, kontakt@hm-psychotherapie.de, bikai@t-online.de, info@psychotherapie-merkens.de, claudia-lehner@t-online.de, praxis.reinartz@t-online.de, praxis@neurologie-psychiatrie-karlsruhe.de, mueller-aunda@web.de, wolf-vtp@web.de, praxis.leufke@gmail.com, kontakt@zeneka.de, mail@rieger-psychotherapie.de, info@praxis-sentuerk.de, goeke.g@web.de, martina.eckrich@web.de, mail@praxis-katja-beck.de, praxis-vollmann@posteo.de, psychotherapie-barton@web.de, baschnagel@psychotherapie-halbeis.de, psychotherapie-neumann@gmx.de, info@praxis-heckenlaible.de, praxis.kugele@gmail.com, hagenpraxiska@online.de, pt-juergens@web.de, kontakt@psychotherapie-neureut.de, gia.nakat@gmail.com\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"with open('./data/therapists.json', 'r') as infile:\n",
|
||
" loaded = json.load(infile)\n",
|
||
"\n",
|
||
"print(f'{len(loaded)} entries loaded.')\n",
|
||
"\n",
|
||
"with_mail = list(filter(lambda entry: 'mails' in entry, loaded))\n",
|
||
"print(f'{len(with_mail)} with email.')\n",
|
||
"\n",
|
||
"with_vt = list(filter(lambda entry: 'Verhaltenstherapeutische Einzeltherapie – Erwachsene' in entry['therapy_types'], with_mail))\n",
|
||
"print(f'{len(with_vt)} with VT.')\n",
|
||
"\n",
|
||
"allmails = []\n",
|
||
"\n",
|
||
"for entry in with_vt:\n",
|
||
" allmails += list(map(lambda mail: mail.lower(), entry['mails']))\n",
|
||
"\n",
|
||
"allmails = list(set(allmails))\n",
|
||
"\n",
|
||
"print(f'{len(allmails)} without duplicates.')\n",
|
||
"\n",
|
||
"print(\", \".join(allmails))"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 40,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"def mapday(day):\n",
|
||
" return day.replace(' ', '').replace(':', '').lower()"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 41,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"def create_event(weekday, timeframe):\n",
|
||
" appointment = Event()\n",
|
||
"\n",
|
||
" times = timeframe.split(' - ')\n",
|
||
" begin = times[0].split(':')\n",
|
||
" end = times[1].split(':')\n",
|
||
" \n",
|
||
"\n",
|
||
" # All days have been validated to be one of [\"Mo :\", \"Di :\", \"Mi :\", \"Do :\", \"Fr :\"]\n",
|
||
" # We just use the week this was developed at. Events recur weekly anyways…\n",
|
||
" if weekday == 'Mo :':\n",
|
||
" day = 7\n",
|
||
" elif weekday == 'Di :':\n",
|
||
" day = 8\n",
|
||
" elif weekday == 'Mi :':\n",
|
||
" day = 9\n",
|
||
" elif weekday == 'Do :':\n",
|
||
" day = 10\n",
|
||
" elif weekday == 'Fr :':\n",
|
||
" day = 11\n",
|
||
"\n",
|
||
" appointment.begin = datetime.datetime(2025, 4, day, int(begin[0]), int(begin[1]), 0)\n",
|
||
" appointment.end = datetime.datetime(2025, 4, day, int(end[0]), int(end[1]), 0)\n",
|
||
"\n",
|
||
" appointment.extra.append(ContentLine(name=\"RRULE\", value=f\"FREQ=WEEKLY;INTERVAL=1;WKST=MO\"))\n",
|
||
" return appointment\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 46,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"def create_ics_files(therapists, path):\n",
|
||
" # create a calendar for each therapist\n",
|
||
" for therapist in therapists:\n",
|
||
" # one .ics file per therapist\n",
|
||
" therapist_calendar = Calendar()\n",
|
||
" # extract all days\n",
|
||
" for day in therapist['phone_appointments']:\n",
|
||
" # create an event for each phone timeframe\n",
|
||
" for i, phone_time in enumerate(therapist['phone_appointments'][day]):\n",
|
||
" # non parsable times\n",
|
||
" if len(phone_time.split(\" - \")) != 2:\n",
|
||
" print(therapist['name'])\n",
|
||
"\n",
|
||
" appointment = create_event(day, phone_time)\n",
|
||
" appointment.name = therapist['name']\n",
|
||
"\n",
|
||
" # save appointment\n",
|
||
" outpath = os.path.join(path, f'{therapist['name'].replace(' ', '_').replace('/', '&')}_{mapday(day)}_{str(i)}.ics')\n",
|
||
" with open(outpath, \"w+\", newline='') as outfile:\n",
|
||
" outfile.write(appointment.serialize()) "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 49,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"215 of 275 therapists callable.\n",
|
||
"113 of 215 therapists offer VT.\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"with open('./data/therapists.json', 'r') as infile:\n",
|
||
" loaded = json.load(infile)\n",
|
||
"\n",
|
||
"# only want the ones we can actually call\n",
|
||
"therapists = list(filter(lambda t: 'phone_appointments' in t and 'phone' in t, loaded))\n",
|
||
"\n",
|
||
"print(f'{len(therapists)} of {len(loaded)} therapists callable.')\n",
|
||
"\n",
|
||
"# filter for VT\n",
|
||
"with_vt = list(filter(lambda entry: 'Verhaltenstherapeutische Einzeltherapie – Erwachsene' in entry['therapy_types'], therapists))\n",
|
||
"print(f'{len(with_vt)} of {len(therapists)} therapists offer VT.')\n",
|
||
"\n",
|
||
"create_ics_files(with_vt, os.path.join('data', 'icsfiles', 'with_vt'))\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": []
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "python-minimal kernel",
|
||
"language": "python",
|
||
"name": "python-minimal"
|
||
},
|
||
"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.12.7"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 2
|
||
}
|