From 3c9a67d41bce3f5851e246a0b1626b1446dde83e Mon Sep 17 00:00:00 2001 From: Sergiusz Warga Date: Mon, 23 Nov 2020 01:15:19 +0100 Subject: [PATCH] Introduced text2pensum.py, html templates for pensa, .env to initialize environmental variables while using pipenv and many more --- .env | 4 +++ README.md | 20 ++++++++++++++- app/routes.py | 9 ++++++- app/templates/LLPSI/LLPSI.html | 11 ++++++++ .../Pensum_A.html => Pensum_cloze.html} | 3 ++- .../Pensa/01_Imperium_Romanum_Pensum_A | 1 + .../Pensa/01_Imperium_Romanum_Pensum_A.html | 1 + text2pensum.py | 25 +++++++++++++++++++ 8 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 .env create mode 100644 app/templates/LLPSI/LLPSI.html rename app/templates/LLPSI/{01_Imperium_Romanum/Pensum_A.html => Pensum_cloze.html} (89%) create mode 100644 app/templates/Pensa/01_Imperium_Romanum_Pensum_A create mode 100644 app/templates/Pensa/01_Imperium_Romanum_Pensum_A.html create mode 100755 text2pensum.py diff --git a/.env b/.env new file mode 100644 index 0000000..28e04da --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +FLASK_APP=main.py +FLASK_ENV=development +FLASK_RUN_PORT=8080 +FLASK_RUN_HOST=0.0.0.0 \ No newline at end of file diff --git a/README.md b/README.md index 3d6af67..889f49b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,24 @@ +# About + +As I've started learning Latin from Lingua Latina Per Se Illustrata I've encourtered the urge for Duolingo-like interface allowing me to : +1. check given words in the wiktionairy, so I could see IPA, meaning, declinations etc. next to the text, +2. perform the Pensa so that I could see the mistakes I've made. + +# Parsers +## Text to Pensum + +```text2pensum.py``` takes text file as an input and generates HTML form from it. Marking is as follows: + - all vowel-dash-vowel combinations (```i-i```) are transformed into a long vowel marked with macron (```ī```) + - underscore-string-underscore combinations (```_us_```) are transformed intorequiered html text input field with string between underscores as a value of ```data-expected``` atribute (``````). + +# TODO + - [ ] text to html parser to swiftly migrate the cloze Pensa + - [ ] dictionairy interface + - [ ] + # Development -To run the app: +To run the app on your own machine: 1. ```pipenv shell``` 2. ```export FLASK_APP=main.py``` 3. ```export FLASK_ENV=development``` diff --git a/app/routes.py b/app/routes.py index 436299f..b189151 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,5 +1,6 @@ from app import app from flask import render_template +import os @app.route('/') @app.route('/index') @@ -12,7 +13,13 @@ def latin(): @app.route('/latin/llpsi') def llpsi(): - return render_template('LLPSI/01_Imperium_Romanum/Pensum_A.html') + return render_template('LLPSI/LLPSI.html') + +@app.route('/latin/llpsi/') +def pensum(pensum_id): + filename = 'templates/Pensa/' + pensum_id + '.html' + with open(filename, 'r') as file: + return render_template('LLPSI/Pensum_cloze.html', pensum_content=file.read()) @app.route('/latin/coniugationes') def coniugationes(): diff --git a/app/templates/LLPSI/LLPSI.html b/app/templates/LLPSI/LLPSI.html new file mode 100644 index 0000000..124b425 --- /dev/null +++ b/app/templates/LLPSI/LLPSI.html @@ -0,0 +1,11 @@ + + + + + Lingua Latina Per Se Illustrata + + +

Lingua Latina Per Se Illustrata


+ Pensum A + + \ No newline at end of file diff --git a/app/templates/LLPSI/01_Imperium_Romanum/Pensum_A.html b/app/templates/LLPSI/Pensum_cloze.html similarity index 89% rename from app/templates/LLPSI/01_Imperium_Romanum/Pensum_A.html rename to app/templates/LLPSI/Pensum_cloze.html index 693e16d..adfc8bf 100644 --- a/app/templates/LLPSI/01_Imperium_Romanum/Pensum_A.html +++ b/app/templates/LLPSI/Pensum_cloze.html @@ -25,7 +25,8 @@
- Nilus fluvi est.
+ {{pensum_content|safe}} +
diff --git a/app/templates/Pensa/01_Imperium_Romanum_Pensum_A b/app/templates/Pensa/01_Imperium_Romanum_Pensum_A new file mode 100644 index 0000000..25b19de --- /dev/null +++ b/app/templates/Pensa/01_Imperium_Romanum_Pensum_A @@ -0,0 +1 @@ +Ni-ilus fluvi_us_ est. Ni-ilus et Rhe-enus fluvi_i-i_ _sunt_, Cre-eta i-insul_a_ _est_. Cre-eta et Rhodus i-insul_ae_ sunt. Brundisium oppid_um_ _est_. Brundisium et Tu-usculum oppid_a_ sunt. \ No newline at end of file diff --git a/app/templates/Pensa/01_Imperium_Romanum_Pensum_A.html b/app/templates/Pensa/01_Imperium_Romanum_Pensum_A.html new file mode 100644 index 0000000..e8fa12d --- /dev/null +++ b/app/templates/Pensa/01_Imperium_Romanum_Pensum_A.html @@ -0,0 +1 @@ +Nīlus fluvi est. Nīlus et Rhēnus fluvi , Crēta īnsul . Crēta et Rhodus īnsul sunt. Brundisium oppid . Brundisium et Tūsculum oppid sunt. \ No newline at end of file diff --git a/text2pensum.py b/text2pensum.py new file mode 100755 index 0000000..33174d0 --- /dev/null +++ b/text2pensum.py @@ -0,0 +1,25 @@ +import sys +import re + +with open(sys.argv[1], 'r') as infile: + content = infile.read() + +# Replace _string_ with html +html_head = '' +content = re.sub(r'_([a-zA-Z\-]+)_', html_head+r'\1'+html_tail, content) + +# Replace vowel-dash-vowel with vowels with macrons +content = content.replace('A-A', 'Ā') +content = content.replace('a-a', 'ā') +content = content.replace('E-E', 'Ē') +content = content.replace('e-e', 'ē') +content = content.replace('I-I', 'Ī') +content = content.replace('i-i', 'ī') +content = content.replace('O-O', 'Ō') +content = content.replace('o-o', 'ō') +content = content.replace('U-U', 'Ū') +content = content.replace('u-u', 'ū') + +with open(sys.argv[1] + '.html', 'w+') as outfile: + outfile.write(content) \ No newline at end of file