Skip to content

Instantly share code, notes, and snippets.

@nelisjunior
Last active November 18, 2024 12:04
Show Gist options
  • Save nelisjunior/94b62a14cfe0389fb83596bf28df7e19 to your computer and use it in GitHub Desktop.
Save nelisjunior/94b62a14cfe0389fb83596bf28df7e19 to your computer and use it in GitHub Desktop.
Gerador de Agendas.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyPSibyTLyLfgCdTp5w+72Ye",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/nelisjunior/94b62a14cfe0389fb83596bf28df7e19/gerador-de-agendas.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"# Dados dos eventos no formato ajustado\n",
"eventos = {\n",
" \"cronograma\": [\n",
" {\n",
" \"evento\": \"Solicitação de matrícula no SIGAA para o período letivo 2024.2\",\n",
" \"data_inicio\": \"04/09/2024\",\n",
" \"data_fim\": \"09/09/2024\"\n",
" },\n",
" {\n",
" \"evento\": \"Processamento da matrícula para o período letivo 2024.2\",\n",
" \"data_inicio\": \"12/09/2024\"\n",
" },\n",
" {\n",
" \"evento\": \"INÍCIO DO PERÍODO LETIVO 2024.2\",\n",
" \"data\": \"16/09/2024\"\n",
" },\n",
" {\n",
" \"evento\": \"Solicitação de rematrícula no SIGAA para o período letivo 2024.2\",\n",
" \"data_inicio\": \"17/09/2024\",\n",
" \"data_fim\": \"18/09/2024\"\n",
" },\n",
" {\n",
" \"evento\": \"Processamento da rematrícula para o período letivo 2024.2\",\n",
" \"data_inicio\": \"20/09/2024\",\n",
" \"data_fim\": \"13/09/2024\"\n",
" },\n",
" {\n",
" \"evento\": \"Matrícula extraordinária para o período letivo 2024.2\",\n",
" \"data_inicio\": \"23/09/2024\",\n",
" \"data_fim\": \"11/10/2024\"\n",
" },\n",
" {\n",
" \"evento\": \"Suspensão das atividades acadêmicas para o período letivo 2024.2\",\n",
" \"data_inicio\": \"23/12/2024\",\n",
" \"data_fim\": \"03/01/2025\"\n",
" },\n",
" {\n",
" \"evento\": \"Retorno das atividades acadêmicas para o período letivo 2024.2\",\n",
" \"data\": \"06/01/2025\"\n",
" },\n",
" {\n",
" \"evento\": \"Último dia para depósito do Trabalho de Conclusão de Curso finalizado em 2024.2, pelos discentes, no Repositório Institucional\",\n",
" \"data\": \"22/01/2025\"\n",
" },\n",
" {\n",
" \"evento\": \"Término do período letivo 2024.2\",\n",
" \"data\": \"01/02/2025\"\n",
" },\n",
" {\n",
" \"evento\": \"Último dia para consolidação final, pelos docentes, das turmas de componentes curriculares do período letivo 2024.2.\",\n",
" \"data\": \"02/02/2025\"\n",
" }\n",
" ]\n",
"}"
],
"metadata": {
"id": "xSEzHssFQzfQ"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "C6UU-p1KQrUF",
"outputId": "eeb4c21e-d24a-49f6-a2f0-a91ef67f588c"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Arquivo .ics criado!\n"
]
}
],
"source": [
"from datetime import datetime\n",
"\n",
"\n",
"# Função para formatar datas no padrão iCalendar\n",
"def formatar_data(data):\n",
" return datetime.strptime(data, \"%d/%m/%Y\").strftime(\"%Y%m%dT%H%M%S\")\n",
"\n",
"# Criação do conteúdo iCalendar\n",
"ics_content = \"BEGIN:VCALENDAR\\nVERSION:2.0\\nPRODID:-//Your Organization//Your Product//EN\\n\"\n",
"\n",
"for evento in eventos[\"cronograma\"]:\n",
" data_inicio = formatar_data(evento[\"data_inicio\"]) if \"data_inicio\" in evento else formatar_data(evento[\"data\"])\n",
" data_fim = formatar_data(evento[\"data_fim\"]) if \"data_fim\" in evento else formatar_data(evento[\"data\"])\n",
"\n",
" ics_content += (\n",
" \"BEGIN:VEVENT\\n\"\n",
" f\"SUMMARY:{evento['evento']}\\n\"\n",
" f\"DTSTART;TZID=America/Sao_Paulo:{data_inicio}\\n\"\n",
" f\"DTEND;TZID=America/Sao_Paulo:{data_fim}\\n\"\n",
" \"END:VEVENT\\n\"\n",
" )\n",
"\n",
"ics_content += \"END:VCALENDAR\"\n",
"\n",
"# Salva o arquivo .ics\n",
"with open(\"/content/eventos.ics\", \"w\") as f:\n",
" f.write(ics_content)\n",
"\n",
"print(\"Arquivo .ics criado!\")\n"
]
},
{
"cell_type": "code",
"source": [
"from google.colab import files\n",
"files.download(\"/content/eventos.ics\")\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 17
},
"id": "u0r8l7zvQv9Z",
"outputId": "22339c4d-c9e0-4c40-b3d7-4ee8af82380d"
},
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.Javascript object>"
],
"application/javascript": [
"\n",
" async function download(id, filename, size) {\n",
" if (!google.colab.kernel.accessAllowed) {\n",
" return;\n",
" }\n",
" const div = document.createElement('div');\n",
" const label = document.createElement('label');\n",
" label.textContent = `Downloading \"${filename}\": `;\n",
" div.appendChild(label);\n",
" const progress = document.createElement('progress');\n",
" progress.max = size;\n",
" div.appendChild(progress);\n",
" document.body.appendChild(div);\n",
"\n",
" const buffers = [];\n",
" let downloaded = 0;\n",
"\n",
" const channel = await google.colab.kernel.comms.open(id);\n",
" // Send a message to notify the kernel that we're ready.\n",
" channel.send({})\n",
"\n",
" for await (const message of channel.messages) {\n",
" // Send a message to notify the kernel that we're ready.\n",
" channel.send({})\n",
" if (message.buffers) {\n",
" for (const buffer of message.buffers) {\n",
" buffers.push(buffer);\n",
" downloaded += buffer.byteLength;\n",
" progress.value = downloaded;\n",
" }\n",
" }\n",
" }\n",
" const blob = new Blob(buffers, {type: 'application/binary'});\n",
" const a = document.createElement('a');\n",
" a.href = window.URL.createObjectURL(blob);\n",
" a.download = filename;\n",
" div.appendChild(a);\n",
" a.click();\n",
" div.remove();\n",
" }\n",
" "
]
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.Javascript object>"
],
"application/javascript": [
"download(\"download_20939dd8-7e40-4200-a351-99f48e4c07e7\", \"eventos.ics\", 2216)"
]
},
"metadata": {}
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment