"""
from pandas_ods_reader import read_ods
#on peut aussi utiliser le csv
df = read_ods("mots.ods",1, columns=["type", "freq", "mot"])
#premier mot à la ligne 4
for i in range(4,15):
  print(df['mot'][i],i)
"""
import random
import keyboard
import time
f=open('mots.csv','r').read()

deb=0
vocab=[]
while "\n" in f[deb:]:
  #extraire la ligne
  ligne=f[deb:f.find('\n',deb+1)]
  deb+=len(ligne)
  typ=ligne.find(',',deb+1)
  freq=ligne.find(',',typ+1)
  mot=ligne.find(',',freq+1)
  vocab.append(ligne[mot+1:]+' ')
  
abc='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'.split(sep=' ')

suiv={}
for mot in vocab:
  for ind in range(len(mot)):
    lettre=mot[ind]
    try:
      suiv[lettre]=suiv.get(lettre,[])+[mot[ind+1]]
    except:
      pass
def create(weird=None):
  if not weird: weird=random.choice(abc)
  choice=''
  while choice!=' ':
    try:
      choice=random.choice(suiv[weird[-1]])
    except:
      choice=''
    weird+=choice
  return weird[:-1]
for i in range(10):
  print(create())

