Skip to content

Instantly share code, notes, and snippets.

@dmarrazzo
Created March 16, 2016 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmarrazzo/07cf2ba81f714f2db8d6 to your computer and use it in GitHub Desktop.
Save dmarrazzo/07cf2ba81f714f2db8d6 to your computer and use it in GitHub Desktop.
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