Skip to content

Instantly share code, notes, and snippets.

@dmarrazzo

dmarrazzo/cf.py

Created Mar 16, 2016
Embed
What would you like to do?
estrae data da codice fiscale
# Open a file
fi = open("/home/donato/cf.txt", "r+")
fo = open("/home/donato/date.txt", "w+")
meseCod = "ABCDEHLMPRST"
for cf in fi:
try:
anno = int(cf[6:8])
mese = meseCod.index(cf[8:9]) + 1
giorno = int(cf[9:11])
if giorno > 40:
giorno -= 40
if giorno > 31:
giorno -= 10
if giorno < 1:
giorno = 1
fo.write("%02d-%02d-%02d\n" % (giorno, mese, anno))
except:
fo.write("01-01-78\n")
# Close opend file
fo.close()
fi.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.