{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "c1489789",
"metadata": {},
"outputs": [],
"source": [
"import smtplib\n",
"from email.mime.text import MIMEText\n",
"from email.mime.multipart import MIMEMultipart\n",
"from email.mime.application import MIMEApplication\n",
"from email.header import Header"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ad97c7a1",
"metadata": {},
"outputs": [],
"source": [
"from exctractGsheet import getDataFrameFromGsheet\n",
"from prepareData import getSlots, getCalendarObject,getCalendarObjects, getHTMLcontent, getHTMLhome\n",
"from sms import prepare_sms, strip_accents"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "6eb6cb9d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'FR_fr'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import os\n",
"import warnings\n",
"import locale\n",
"import traceback\n",
"import codecs\n",
"import datetime\n",
"import pandas as pd\n",
"from typing import List\n",
"locale.setlocale(locale.LC_ALL, 'FR_fr')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "d3228990",
"metadata": {},
"outputs": [],
"source": [
"OUTPUT_FOLDER = \"output\"\n",
"ALARM_DB = os.path.join(OUTPUT_FOLDER,\"alarms.feather\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "6e70160d",
"metadata": {},
"outputs": [],
"source": [
"doc_uuid = \"1iSA5LsNdarYqrZRxE76lE2VkEsoQksIu6rFG7VAfCNQ\"\n",
"planning_gid = \"1001381542\"\n",
"creneau_gid = \"1884137958\"\n",
"benevole_gid_2021 = \"2065754071\"\n",
"benevole_gid_2022 = \"82247394\"\n",
"\n",
"doc_uuid_2021 = \"1OO8jyb4_MWFgqVPlTIqePcwkA3sC5WqhsddDMkvIczE\" "
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "264152fd",
"metadata": {},
"outputs": [],
"source": [
"def getEmail(name, df_contact):\n",
" idx = df_contact[\"Prénom\"]==name\n",
" if idx.count()==0:\n",
" raise KeyError(\"User \"+ name + \"not found in the contact list\")\n",
" else:\n",
" return df_contact.Mail[idx].item()\n",
" \n",
"def getPhone(name, df_contact):\n",
" idx = df_contact[\"Prénom\"]==name\n",
" if idx.count()==0:\n",
" raise KeyError(\"User \"+ name + \"not found in the contact list\")\n",
" else:\n",
" return df_contact[\"Tél\"][idx].item()\n",
" \n",
"def sendEmailWithAttachment(smtp_server, user:str, to:str, subject:str, body:str, attachement_name:str,attachement_content:str):\n",
" # create message object\n",
" message = MIMEMultipart()\n",
" \n",
" # add in header\n",
" message['From'] = Header(user)\n",
" message['To'] = Header(to)\n",
" message['Subject'] = Header(subject)\n",
" \n",
" # attach message body as MIMEText\n",
" message.attach(MIMEText(body, 'html', 'utf-8'))\n",
" \n",
" def attachContent(content,filename):\n",
" att = MIMEApplication(content, _subtype=\"txt\")\n",
" att.add_header('Content-Disposition', 'attachment', filename=filename)\n",
" message.attach(att)\n",
" \n",
" if isinstance(attachement_content,list):\n",
" for idx, c in enumerate(attachement_content):\n",
" attachContent(c,attachement_name.replace(\".\",f\"{idx:20.0f}.\"))\n",
" else:\n",
" attachContent(attachement_content,attachement_name)\n",
" \n",
" smtp_server.sendmail(user, strip_accents(to), message.as_string())"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "ea2b27e7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading ./data/planning_2022.csv\n",
"Downloading ./data/creneau_2022.csv\n",
"Downloading ./data/benevole_2022.csv\n",
"533 créneaux trouvés\n"
]
}
],
"source": [
"# Gather data\n",
"df_planning, df_creneau,df_contact = getDataFrameFromGsheet(doc_uuid,benevole_id=benevole_gid_2022,suffix=\"_2022\",starting_date=datetime.datetime(2022, 9, 8))\n"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "984a42ef",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(235, b'2.7.0 Authentication successful')"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"# Setup mail service\n",
"username = \"clovis@jaquin.fr\"\n",
"\n",
"smtp_server=smtplib.SMTP(\"smtp.jaquin.fr\",587)\n",
"smtp_server.ehlo() #setting the ESMTP protocol\n",
"smtp_server.starttls() #setting up to TlS connection\n",
"smtp_server.ehlo() #calling the ehlo() again as encryption happens on calling startttls()\n",
"\n",
"smtp_server.login(username,\"2904Pap1961\")"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "ca4d0357",
"metadata": {},
"outputs": [],
"source": [
"reminders_sms = []\n",
"web_pages = []\n",
"if not os.path.exists(OUTPUT_FOLDER):\n",
" os.mkdir(OUTPUT_FOLDER)\n",
" \n",
"WEB_FOLDER = os.path.join(OUTPUT_FOLDER,\"web\")\n",
"if not os.path.exists(WEB_FOLDER):\n",
" os.mkdir(WEB_FOLDER)\n",
"\n",
"for name in [\"Nicolas\"]:\n",
" # if name!=\"Marine\":\n",
" # continue\n",
" try:\n",
" email = getEmail(name,df_contact)\n",
" phone_number = getPhone(name, df_contact)\n",
" fname = email.split(\"@\")[0]+\".html\"\n",
"\n",
" slots = getSlots(name, df_planning, df_contact, df_creneau)\n",
" # Generate SMS alarms to be send to benevole\n",
" for slot in slots:\n",
" SMS_alarm = {\"phone_number\":phone_number,\"time\":slot.alarm_time,\"content\":slot.toReminderText() , 'is_sent':False}\n",
" reminders_sms.append(SMS_alarm)\n",
" new_calendar = getCalendarObjects(slots)\n",
"\n",
" # Create email to communicate slots to benevole\n",
" html_mail = getHTMLcontent(slots, name, True)\n",
" \n",
" # Create attachement and avoid warning for using str(c) instead of Component.serialize()\n",
" with warnings.catch_warnings():\n",
" warnings.simplefilter(\"ignore\")\n",
" attachement = [c.serialize() for c in new_calendar]\n",
" \n",
" # Save email locally for test\n",
" with codecs.open(os.path.join(OUTPUT_FOLDER,fname),\"w\",\"utf-8\") as f:\n",
" f.write(html_mail)\n",
"\n",
" # Send email with ics attachement\n",
" sendEmailWithAttachment(smtp_server,username,email,\"Brass dans la Garonne : tes créneaux !\",html_mail,\"BDLG2022.ics\",attachement)\n",
" \n",
" # Create Web page for display \n",
" html = getHTMLcontent(slots, name, False)\n",
" with codecs.open(os.path.join(WEB_FOLDER,fname),\"w\",\"utf-8\") as f:\n",
" f.write(html)\n",
"\n",
" web_pages.append((name[0].upper()+name[1:].lower(),fname))\n",
" \n",
" except Exception as e:\n",
" raise e\n",
" print(\"Erreur lors du traitement du bénévole \" + name)\n",
" traceback.print_exception(e)\n",
"\n",
"web_pages.sort()\n",
"with codecs.open(os.path.join(WEB_FOLDER,\"index.html\"),\"w\",\"utf-8\") as f:\n",
" f.write(getHTMLhome(web_pages))\n",
" \n",
"df_alarms = pd.DataFrame(reminders_sms)\n",
"df_alarms.to_feather(ALARM_DB)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "2184221a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"533"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(df_alarms)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "f7121f85",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Theo'"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Failedon = \"Theo\""
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "ca2c2ae8",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" ID | \n",
" Prénom | \n",
" Nom | \n",
" Tél | \n",
" Mail | \n",
" Bénévole jeudi ou vendredi | \n",
" Méca des Cuivres | \n",
" Trous Balourds | \n",
" Frères Pouetards | \n",
" Dead Paquito | \n",
" Gimmick 5 Syndicate | \n",
" Team ? | \n",
" Extérieur | \n",
" A un T shirt | \n",
"
\n",
" \n",
" \n",
" \n",
" | 102 | \n",
" 18 | \n",
" Nicolas | \n",
" Damiens | \n",
" 06 88 18 89 44 | \n",
" Nicolas.damiens@orange.fr | \n",
" JVL | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" X | \n",
" Non | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" ID Prénom Nom Tél Mail \\\n",
"102 18 Nicolas Damiens 06 88 18 89 44 Nicolas.damiens@orange.fr \n",
"\n",
" Bénévole jeudi ou vendredi Méca des Cuivres Trous Balourds \\\n",
"102 JVL NaN NaN \n",
"\n",
" Frères Pouetards Dead Paquito Gimmick 5 Syndicate Team ? Extérieur \\\n",
"102 NaN NaN NaN NaN X \n",
"\n",
" A un T shirt \n",
"102 Non "
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_contact[df_contact[\"Prénom\"]==\"Nicolas\"]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "dd55d922",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" phone_number | \n",
" time | \n",
" content | \n",
" is_sent | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0668798673 | \n",
" 2022-09-06 22:27:05.050516 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" False | \n",
"
\n",
" \n",
" | 1 | \n",
" 0668798673 | \n",
" 2022-09-06 22:57:05.050516 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" False | \n",
"
\n",
" \n",
" | 2 | \n",
" 0668798673 | \n",
" 2022-09-06 23:27:05.050516 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" False | \n",
"
\n",
" \n",
" | 3 | \n",
" 0668798673 | \n",
" 2022-09-06 23:57:05.050516 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" False | \n",
"
\n",
" \n",
" | 4 | \n",
" 0668798673 | \n",
" 2022-09-07 00:27:05.050516 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" False | \n",
"
\n",
" \n",
" | 5 | \n",
" 0668798673 | \n",
" 2022-09-07 00:57:05.050516 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" False | \n",
"
\n",
" \n",
" | 6 | \n",
" 0668798673 | \n",
" 2022-09-07 01:27:05.050516 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" False | \n",
"
\n",
" \n",
" | 7 | \n",
" 0668798673 | \n",
" 2022-09-07 01:57:05.050516 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" False | \n",
"
\n",
" \n",
" | 8 | \n",
" 0668798673 | \n",
" 2022-09-07 02:27:05.050516 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" False | \n",
"
\n",
" \n",
" | 9 | \n",
" 0668798673 | \n",
" 2022-09-07 02:57:05.050516 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" False | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" phone_number time \\\n",
"0 0668798673 2022-09-06 22:27:05.050516 \n",
"1 0668798673 2022-09-06 22:57:05.050516 \n",
"2 0668798673 2022-09-06 23:27:05.050516 \n",
"3 0668798673 2022-09-06 23:57:05.050516 \n",
"4 0668798673 2022-09-07 00:27:05.050516 \n",
"5 0668798673 2022-09-07 00:57:05.050516 \n",
"6 0668798673 2022-09-07 01:27:05.050516 \n",
"7 0668798673 2022-09-07 01:57:05.050516 \n",
"8 0668798673 2022-09-07 02:27:05.050516 \n",
"9 0668798673 2022-09-07 02:57:05.050516 \n",
"\n",
" content is_sent \n",
"0 Coucou,\\nton créneau bénévole commence bientôt... False \n",
"1 Coucou,\\nton créneau bénévole commence bientôt... False \n",
"2 Coucou,\\nton créneau bénévole commence bientôt... False \n",
"3 Coucou,\\nton créneau bénévole commence bientôt... False \n",
"4 Coucou,\\nton créneau bénévole commence bientôt... False \n",
"5 Coucou,\\nton créneau bénévole commence bientôt... False \n",
"6 Coucou,\\nton créneau bénévole commence bientôt... False \n",
"7 Coucou,\\nton créneau bénévole commence bientôt... False \n",
"8 Coucou,\\nton créneau bénévole commence bientôt... False \n",
"9 Coucou,\\nton créneau bénévole commence bientôt... False "
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import random\n",
"import datetime\n",
"\n",
"def generateFakeAlarms(phone_numbers:List[str],start_time:datetime.datetime, n:int):\n",
" records = []\n",
" DELTA = datetime.timedelta(minutes=30)\n",
" next_alarm = start_time \n",
" for i in range(n):\n",
" records.append({\n",
" 'phone_number':random.choice(phone_numbers),\n",
" \"time\":next_alarm,\n",
" \"content\":\"Coucou,\\nton créneau bénévole commence bientôt : \" + next_alarm.strftime(\"%Hh%M\"),\n",
" \"is_sent\":False\n",
" })\n",
" next_alarm += DELTA\n",
" return pd.DataFrame.from_dict(records)\n",
"\n",
"df_fake_alarm = generateFakeAlarms([\"0668798673\"],datetime.datetime.now(),10)\n",
"df_fake_alarm.to_feather(ALARM_DB)\n",
"df_fake_alarm\n"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "a4856d97",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" phone_number | \n",
" time | \n",
" content | \n",
" is_sent | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0668798673 | \n",
" 2022-09-05 18:17:32.915774 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" True | \n",
"
\n",
" \n",
" | 1 | \n",
" 0668798673 | \n",
" 2022-09-05 18:47:32.915774 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" True | \n",
"
\n",
" \n",
" | 2 | \n",
" 0668798673 | \n",
" 2022-09-05 19:17:32.915774 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" True | \n",
"
\n",
" \n",
" | 3 | \n",
" 0668798673 | \n",
" 2022-09-05 19:47:32.915774 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" True | \n",
"
\n",
" \n",
" | 4 | \n",
" 0668798673 | \n",
" 2022-09-05 20:17:32.915774 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" True | \n",
"
\n",
" \n",
" | 5 | \n",
" 0668798673 | \n",
" 2022-09-05 20:47:32.915774 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" True | \n",
"
\n",
" \n",
" | 6 | \n",
" 0668798673 | \n",
" 2022-09-05 21:17:32.915774 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" True | \n",
"
\n",
" \n",
" | 7 | \n",
" 0668798673 | \n",
" 2022-09-05 21:47:32.915774 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" True | \n",
"
\n",
" \n",
" | 8 | \n",
" 0668798673 | \n",
" 2022-09-05 22:17:32.915774 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" True | \n",
"
\n",
" \n",
" | 9 | \n",
" 0668798673 | \n",
" 2022-09-05 22:47:32.915774 | \n",
" Coucou,\\nton créneau bénévole commence bientôt... | \n",
" True | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" phone_number time \\\n",
"0 0668798673 2022-09-05 18:17:32.915774 \n",
"1 0668798673 2022-09-05 18:47:32.915774 \n",
"2 0668798673 2022-09-05 19:17:32.915774 \n",
"3 0668798673 2022-09-05 19:47:32.915774 \n",
"4 0668798673 2022-09-05 20:17:32.915774 \n",
"5 0668798673 2022-09-05 20:47:32.915774 \n",
"6 0668798673 2022-09-05 21:17:32.915774 \n",
"7 0668798673 2022-09-05 21:47:32.915774 \n",
"8 0668798673 2022-09-05 22:17:32.915774 \n",
"9 0668798673 2022-09-05 22:47:32.915774 \n",
"\n",
" content is_sent \n",
"0 Coucou,\\nton créneau bénévole commence bientôt... True \n",
"1 Coucou,\\nton créneau bénévole commence bientôt... True \n",
"2 Coucou,\\nton créneau bénévole commence bientôt... True \n",
"3 Coucou,\\nton créneau bénévole commence bientôt... True \n",
"4 Coucou,\\nton créneau bénévole commence bientôt... True \n",
"5 Coucou,\\nton créneau bénévole commence bientôt... True \n",
"6 Coucou,\\nton créneau bénévole commence bientôt... True \n",
"7 Coucou,\\nton créneau bénévole commence bientôt... True \n",
"8 Coucou,\\nton créneau bénévole commence bientôt... True \n",
"9 Coucou,\\nton créneau bénévole commence bientôt... True "
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.read_feather(ALARM_DB)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d55a4c0b",
"metadata": {},
"outputs": [],
"source": [
"# Clear setup\n",
"smtp_server.quit()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "3370c0fa",
"metadata": {},
"outputs": [],
"source": [
"name= \"Clovis\"\n",
"phone_number = getPhone(name,df_contact) \n",
"slots = getSlots(name,df_planning,df_contact,df_creneau)"
]
},
{
"cell_type": "code",
"execution_count": 97,
"id": "32dd9099",
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "module 'pandas' has no attribute 'from_dict'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32mc:\\Users\\Clovis\\Desktop\\code\\python\\bdlg2022\\Untitled.ipynb Cellule 12\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 27\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m\"\u001b[39m\u001b[39mEchec lors de l\u001b[39m\u001b[39m'\u001b[39m\u001b[39menvoie du SMS au \u001b[39m\u001b[39m\"\u001b[39m \u001b[39m+\u001b[39m alarm[\u001b[39m\"\u001b[39m\u001b[39mphone_number\u001b[39m\u001b[39m\"\u001b[39m])\n\u001b[0;32m 28\u001b[0m \u001b[39mbreak\u001b[39;00m\n\u001b[1;32m---> 30\u001b[0m df \u001b[39m=\u001b[39m pd\u001b[39m.\u001b[39;49mfrom_dict(records)\n\u001b[0;32m 32\u001b[0m \u001b[39m# df.to_feather(ALARM_DB) \u001b[39;00m\n\u001b[0;32m 33\u001b[0m \u001b[39mfinally\u001b[39;00m:\n\u001b[0;32m 34\u001b[0m os\u001b[39m.\u001b[39mremove(LOCK_PATH)\n",
"File \u001b[1;32mc:\\Users\\Clovis\\Desktop\\code\\python\\bdlg2022\\venv\\lib\\site-packages\\pandas\\__init__.py:261\u001b[0m, in \u001b[0;36m__getattr__\u001b[1;34m(name)\u001b[0m\n\u001b[0;32m 257\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mpandas\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mcore\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39marrays\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39msparse\u001b[39;00m \u001b[39mimport\u001b[39;00m SparseArray \u001b[39mas\u001b[39;00m _SparseArray\n\u001b[0;32m 259\u001b[0m \u001b[39mreturn\u001b[39;00m _SparseArray\n\u001b[1;32m--> 261\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mAttributeError\u001b[39;00m(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mmodule \u001b[39m\u001b[39m'\u001b[39m\u001b[39mpandas\u001b[39m\u001b[39m'\u001b[39m\u001b[39m has no attribute \u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00mname\u001b[39m}\u001b[39;00m\u001b[39m'\u001b[39m\u001b[39m\"\u001b[39m)\n",
"\u001b[1;31mAttributeError\u001b[0m: module 'pandas' has no attribute 'from_dict'"
]
}
],
"source": [
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "6b67aabe",
"metadata": {},
"outputs": [],
"source": [
"\n",
"from jinja2 import Environment, FileSystemLoader, select_autoescape\n",
"import IPython\n",
"JINJA_ENV = Environment(\n",
" loader=FileSystemLoader(\"templates\"),\n",
" autoescape=select_autoescape()\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "123e8475",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" \n",
" Liste des bénévoles avec toi \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" Lorraine : 06 71 35 76 12\n",
" \n",
" \n",
" Ceux que tu remplace \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" David DP : 06 20 63 29 57\n",
" \n",
" \n",
" \n",
" \n",
" Laure : 06 88 99 25 08\n",
" \n",
" \n",
" \n",
" "
],
"text/plain": [
""
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"template = JINJA_ENV.get_template(\"Creneau.html\")\n",
"IPython.display.HTML(template.render(slot=slots[0]))"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "b2624d88",
"metadata": {},
"outputs": [],
"source": [
"template_planning = JINJA_ENV.get_template(\"Calendar.html\")"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "16119705",
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" Planning\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
"\n",
" \n",
" \n",
" \n",
" Liste des bénévoles avec toi \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" Lorraine : 06 71 35 76 12\n",
" \n",
" \n",
" Ceux que tu remplace \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" David DP : 06 20 63 29 57\n",
" \n",
" \n",
" \n",
" \n",
" Laure : 06 88 99 25 08\n",
" \n",
" \n",
" \n",
" \n",
"\n",
" \n",
" \n",
" \n",
" Liste des bénévoles avec toi \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" Alexis : 06 95 52 90 88\n",
" \n",
" \n",
" \n",
" \n",
" Clovis : 06 68 79 86 73\n",
" \n",
" \n",
" \n",
" \n",
" Gladys : 06 64 79 59 49\n",
" \n",
" \n",
" \n",
" \n",
" Ilyès : 06 76 68 30 66\n",
" \n",
" \n",
" \n",
" \n",
" Laura GPS : 06 79 27 36 04\n",
" \n",
" \n",
" \n",
" \n",
" Laure : 06 88 99 25 08\n",
" \n",
" \n",
" \n",
" \n",
" Lorraine : 06 71 35 76 12\n",
" \n",
" \n",
" \n",
" \n",
" Marine T. : 06 32 99 84 98\n",
" \n",
" \n",
" \n",
" \n",
" Matthias : 06 89 04 53 82\n",
" \n",
" \n",
" \n",
" \n",
" Matthieu VLC : 06 42 44 79 42\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
"\n",
" \n",
" \n",
" \n",
" Liste des bénévoles avec toi \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" Laure : 06 88 99 25 08\n",
" \n",
" \n",
" \n",
" \n",
" Marine T. : 06 32 99 84 98\n",
" \n",
" \n",
" \n",
" \n",
"\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"\n",
" \n",
" \n",
" \n",
" Liste des bénévoles avec toi \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" Antonin : 06 31 74 28 58\n",
" \n",
" \n",
" \n",
" \n",
" Cyril : 06 73 51 44 99\n",
" \n",
" \n",
" \n",
" \n",
" JP : 06 79 83 74 81 \n",
" \n",
" \n",
" \n",
" \n",
" Lorraine : 06 71 35 76 12\n",
" \n",
" \n",
" \n",
" \n",
" Mathieu Split : 06 74 24 06 28\n",
" \n",
" \n",
" \n",
" \n",
" Pompom Aymeric : 06 78 57 28 15\n",
" \n",
" \n",
" \n",
" \n",
" Silvia : 06 79 16 95 23\n",
" \n",
" \n",
" \n",
" \n",
" Victor : 06 85 57 26 79\n",
" \n",
" \n",
" \n",
" \n",
" Vincent T. : 06 89 02 36 67\n",
" \n",
" \n",
" Ceux que tu remplace \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" Cédric : 06 85 75 55 08\n",
" \n",
" \n",
" \n",
" \n",
" Clovis : 06 68 79 86 73\n",
" \n",
" \n",
" \n",
" \n",
" Edouard : 06 98 39 23 73\n",
" \n",
" \n",
" \n",
" \n",
" Etienne : 07 86 25 78 87\n",
" \n",
" \n",
" \n",
" \n",
" Hélène S. : 06 31 33 50 93\n",
" \n",
" \n",
" \n",
" \n",
" Manu DP : 06 12 80 61 34\n",
" \n",
" \n",
" \n",
" \n",
" Marine T. : 06 32 99 84 98\n",
" \n",
" \n",
" \n",
" \n",
" Matthieu S. : 07 60 42 20 44\n",
" \n",
" \n",
" \n",
" \n",
" Paul-Erwan : 07 87 76 64 76\n",
" \n",
" \n",
" \n",
" \n",
" Quang Huy : 06 74 44 36 35\n",
" \n",
" \n",
" Les personnes qui arrivent après toi \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" Antonin : 06 31 74 28 58\n",
" \n",
" \n",
" \n",
" \n",
" Bertrand : 07 88 61 03 28\n",
" \n",
" \n",
" \n",
" \n",
" Christophe : 06 64 35 54 93\n",
" \n",
" \n",
" \n",
" \n",
" Manu DP : 06 12 80 61 34\n",
" \n",
" \n",
" \n",
" \n",
" Mathieu Split : 06 74 24 06 28\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
""
],
"text/plain": [
""
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"html = template_planning.render(slots=slots)\n",
"IPython.display.HTML(html)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d5f17e8a",
"metadata": {},
"outputs": [],
"source": [
"\n",
"def getCalendarObject(name:str,df:pd.DataFrame)->ics.Calendar:\n",
" new_calendar = ics.Calendar(creator=PROGRAM_UID)\n",
" for row, item in df[df.benevole_nom ==name].iterrows():\n",
" starting_with_you = df.benevole_nom[(df.nom==item.nom) & (df.start==item.start) & (df.benevole_nom!=name)]\n",
"\n",
" benevole_you_replace = df.benevole_nom[(df.nom==item.nom) & (df.end==item.start)]\n",
"\n",
" benevole_following_you = df.benevole_nom[(df.nom==item.nom) & (df.start==item.end)]\n",
"\n",
" creneau_detail = df_creneau[df_creneau.nom==item.nom]\n",
" description = \"\"\n",
" location = \"undefined\"\n",
" if len(creneau_detail) >0:\n",
" creneau = creneau.iloc[0]\n",
" description = f\"\"\"{creneau.description} \n",
"\n",
" Responsable à contacter en cas de problème : {creneau.responsable}\"\"\"\n",
" location = creneau.lieu\n",
"\n",
" if len(starting_with_you)>0:\n",
" description+= \"\\n\\nLes bénévoles avec qui tu sera : \"+BENEVOLE_SEPARATOR.join([\"\",*getContactList(starting_with_you, df_contact)])\n",
"\n",
" if len(benevole_you_replace)>0:\n",
" description+= \"\\n\\nLes bénévoles que tu remplaces : \" +BENEVOLE_SEPARATOR.join([\"\",*getContactList(benevole_you_replace, df_contact)])\n",
"\n",
" if len(benevole_following_you)>0:\n",
" description+= \"\\n\\nLes personnes qui arrivent après toi : \"+BENEVOLE_SEPARATOR.join([\"\",*getContactList(benevole_following_you, df_contact)])\n",
"\n",
" alarms = [ics.AudioAlarm(ALARM_DELTA),ics.DisplayAlarm(ALARM_DELTA)]\n",
" event = ics.Event(name=f\"[BDLG] {item.nom}\",begin =item.start,end=item.end,description=description,location = location,\n",
" alarms=alarms)\n",
"\n",
"\n",
" new_calendar.events.add(event)\n",
" return new_calendar"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.6 ('venv': venv)",
"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.10.6"
},
"vscode": {
"interpreter": {
"hash": "5d54e20e9142e4948ac009cbb38e09e6108a7101850b96d8e07c7a01b9742ed5"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|