francescomecca.eu/_site/accenti.py
2017-03-20 00:46:14 +01:00

45 lines
1.3 KiB
Python

import re
letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y', 'z']
symbols = ['"','#','`','%','&','\'','(',')','*','+',',','-','.','/', '\n']
errDict = {'á': 'à', 'í': 'ì', 'ó': 'ò', 'ú': 'ù', 'É': 'È'}
# printl = print ('what')
def main (filename):
# you could write better things
with open (filename, "r") as f:
wordsAll = f.read ()
# with open (filename + '.corretto.md' , "w") as f:
with open (filename , "w") as f:
for w in wordsAll.split (' '):
# á ó é ú í
# check verbo essere
try:
if w[0] == 'é':
w.replace ('é', 'è')
if w[0] == 'e' and w[1] == '`':
w.replace ('e`', 'è')
w = w[1:]
except:
pass
try:
# check vocali gravi
w = [e if e not in errDict else errDict[e] for e in w]
w = ''.join (w)
except:
# ugly, check len
pass
if '' in w:
w = w.replace ('', 'po\'')
f.write (w + ' ')
# print (w + ' ', end='')
f.write ('\n')
if __name__ == '__main__':
import sys
for arg in sys.argv[1:]:
main (arg)