dotfiles

my dotfiles.
Log | Files | Refs | README | LICENSE

inttoesp.py (1964B)


      1 import sys
      2 
      3 first_thirty=[ "uno", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve", "diez", "once", "doce", "trece", "catorce", "quince", "dieciséis", "diecisiete", "dieciocho", "diecinueve", "veinte", "veintiuno", "veintidós", "veintitrés", "veinticuatro", "veinticinco", "veintiséis", "veintisiete", "veintiocho", "veintinueve" ]
      4 
      5 decs=[ "treinta", "cuarenta", "cincuenta", "sesenta", "setenta", "ochenta", "noventa" ]
      6 
      7 hundos=[ "ciento", "doscientos", "trescientos", "cuatrocientos", "quinientos", "seiscientos", "setecientos", "ochocientos", "novecientos" ]
      8 
      9 special={ 0 : "cero", 100 : "cien", 100000 : "cien mil" }
     10 
     11 i = int(sys.argv[1].replace(',', ''))
     12 
     13 if i in special:
     14   print(special[i])
     15   exit()
     16 
     17 s = ""
     18 limit = 10000000
     19 y = yy = False
     20 m = True
     21 
     22 while limit > 1:
     23   n = int((i % limit) / (limit / 10))
     24 
     25   if n > 0:
     26     if limit > 1000000 and n == 1:
     27       s += "un millón "
     28       m = False
     29     elif limit > 1000000:
     30       s += first_thirty[n - 1] + " millones "
     31       m = False
     32     elif limit > 100000:
     33       s += hundos[n - 1] + " "
     34       m = False
     35     elif limit > 10000 and n > 2:
     36       s += decs[n - 3] + " "
     37       yy = True
     38       m = False
     39     elif limit > 10000 and n <= 2:
     40       limit = limit / 10
     41       s += first_thirty[(n * 10) + int((i % limit) / (limit / 10)) - 1] + " mil "
     42       m = False
     43     elif limit > 1000 and n == 1 and m:
     44       s += "mil "
     45     elif limit > 1000:
     46       if yy:
     47         s += "y "
     48       if n == 1:
     49         s += "un mil "
     50       else:
     51         s += first_thirty[n - 1] + " mil "
     52     elif limit > 100:
     53       s += hundos[n - 1] + " "
     54     elif limit > 10 and n > 2:
     55       s += decs[n - 3] + " "
     56       y = True
     57     elif limit > 10 and n <= 2:
     58       limit = limit / 10
     59       s += first_thirty[(n * 10) + int((i % limit) / (limit / 10)) - 1]
     60     elif limit > 1:
     61       if y:
     62         s += "y "
     63       s += first_thirty[n - 1]
     64   #elif limit == 10000:
     65       #s += "mil "
     66 
     67   limit = limit / 10
     68 
     69 print(s.strip())