Created
March 16, 2016 10:30
-
-
Save dmarrazzo/07cf2ba81f714f2db8d6 to your computer and use it in GitHub Desktop.
estrae data da codice fiscale
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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