{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# A notebook that gives stats on the notes taken so far\n", "\n", "## Useful functions\n", "\n", "First, let's define a function that counts how many sections there is in a *log file* : " ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "def count_sections(log_file):\n", " with open(log_file, 'r') as fil: lines = fil.readlines()\n", " s = 0\n", " for line in lines : \n", " if line[:2]=='# ': s += 1\n", " return s" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Maybe I will add some other useful function later.\n", "\n", "Let's list all the *log files* :" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There is 1 log file :\n", "\tmodule_1.md; contains 3 sections.\n" ] } ], "source": [ "import os\n", "\n", "log_dir = '../../journal/'\n", "ignored_files = ['Readme.md']\n", "log_files = [fil for fil in os.listdir(log_dir) if fil not in ignored_files]\n", "\n", "if len(log_files)<2 : print(\"There is {:d} log file :\".format(len(log_files)))\n", "else: print(\"There are {:d} log files :\".format(len(log_files)))\n", " \n", "for fil in log_files: \n", " n_sec = count_sections(log_dir + fil)\n", " if n_sec <2 : print(\"\\t{:}; contains {:d} section.\".format(fil, n_sec))\n", " else: print(\"\\t{:}; contains {:d} sections.\".format(fil, n_sec))\n", " " ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.9" } }, "nbformat": 4, "nbformat_minor": 2 }