Updated README.md and added multifile support for text2pensum.py

This commit is contained in:
sergiusz 2020-11-24 19:31:28 +01:00
parent 541173d829
commit d3d826fdcb
2 changed files with 22 additions and 25 deletions

View File

@ -12,14 +12,10 @@ As I've started learning Latin from Lingua Latina Per Se Illustrata I've encourt
- underscore-string-underscore combinations (```_us_```) are transformed intorequiered html text input field with string between underscores as a value of ```data-expected``` atribute (```<input type="text" data-expected="us" required>```). - underscore-string-underscore combinations (```_us_```) are transformed intorequiered html text input field with string between underscores as a value of ```data-expected``` atribute (```<input type="text" data-expected="us" required>```).
# TODO # TODO
- [ ] text to html parser to swiftly migrate the cloze Pensa - [x] text to html parser to swiftly migrate the cloze Pensa
- [ ] dictionairy interface - [ ] dictionairy interface
- [ ] - [ ]
# Development # Development
To run the app on your own machine: To run the app on your own machine use ```pipenv shell 'flask run'```.
1. ```pipenv shell```
2. ```export FLASK_APP=main.py```
3. ```export FLASK_ENV=development```
4. ```flask run```

39
text2pensum.py Executable file → Normal file
View File

@ -1,25 +1,26 @@
import sys import sys
import re import re
with open(sys.argv[1], 'r') as infile: for filename in sys.argv[1:]:
content = infile.read() with open(filename, 'r') as infile:
content = infile.read()
# Replace _string_ with html # Replace _string_ with html
html_head = '<input type="text" data-expected="' html_head = '<input type="text" data-expected="'
html_tail = '" required/>' html_tail = '" required/>'
content = re.sub(r'_([a-zA-Z\-]+)_', html_head+r'\1'+html_tail, content) content = re.sub(r'_([a-zA-Z\-]+)_', html_head+r'\1'+html_tail, content)
# Replace vowel-dash-vowel with vowels with macrons # Replace vowel-dash-vowel with vowels with macrons
content = content.replace('A-A', 'Ā') content = content.replace('A-A', 'Ā')
content = content.replace('a-a', 'ā') content = content.replace('a-a', 'ā')
content = content.replace('E-E', 'Ē') content = content.replace('E-E', 'Ē')
content = content.replace('e-e', 'ē') content = content.replace('e-e', 'ē')
content = content.replace('I-I', 'Ī') content = content.replace('I-I', 'Ī')
content = content.replace('i-i', 'ī') content = content.replace('i-i', 'ī')
content = content.replace('O-O', 'Ō') content = content.replace('O-O', 'Ō')
content = content.replace('o-o', 'ō') content = content.replace('o-o', 'ō')
content = content.replace('U-U', 'Ū') content = content.replace('U-U', 'Ū')
content = content.replace('u-u', 'ū') content = content.replace('u-u', 'ū')
with open(sys.argv[1] + '.html', 'w+') as outfile: with open(filename + '.html', 'w+') as outfile:
outfile.write(content) outfile.write(content)