diff --git a/module2/exo4/exercice.ipynb b/module2/exo4/exercice.ipynb index 0bbbe371b01e359e381e43239412d77bf53fb1fb..f84eeaf7d159c443683e11bf6238a549b10534e8 100644 --- a/module2/exo4/exercice.ipynb +++ b/module2/exo4/exercice.ipynb @@ -1,5 +1,51 @@ { - "cells": [], + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Analyse des mots-clés de mon journal" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Mise en forme de mon journal\n", + "Mes paragraphes sont titrés \"Date:JJ/MM/AAAA\".\n", + "\n", + "La première ligne du paragraphe contient [Mots Clés:Xxxx,Yyyy,Zzzz] où Xxxx, Yyyy, Zzzz sont des mots-clés." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Recupération des données" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "NomFichentree = \"work/Journal/Readme_Journal.md\"\n", + "NomFichsortie = \"work/module2/exo4/Info_Journal.csv\"\n", + "\n", + "with open(NomFichsortie, \"w\", encoding='utf-8') as sortie:\n", + " with open(NomFichentree, \"r\", encoding='utf-8') as entree:\n", + " for ligne in entree:\n", + " if \"Date:\" in ligne:\n", + " (rien,date) = ligne.lstrip('## ').strip().split(':')\n", + " if \"Mots Clés\" in ligne:\n", + " (rien,mots) = ligne.strip('Mots Clés').split(':')\n", + " listemots = mots.strip().split(',')\n", + " for mot in listemots:\n", + " sortie.write(f\"{date};{mot}\\n\")" + ] + } + ], "metadata": { "kernelspec": { "display_name": "Python 3", @@ -16,10 +62,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.3" + "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 2 } -