From b5fb2a6027d9563eed8a19c1256d3a807d6a607f Mon Sep 17 00:00:00 2001 From: a6a8e0f601822270ca754f29f77749b6 Date: Wed, 23 Sep 2020 14:11:21 +0000 Subject: [PATCH] =?UTF-8?q?Premi=C3=A8re=20partie=20de=20l'exercice.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module2/exo4/exercice.ipynb | 51 ++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/module2/exo4/exercice.ipynb b/module2/exo4/exercice.ipynb index 0bbbe37..f84eeaf 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 } - -- 2.18.1