Bora vê
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

beuty.py 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. def beut(tabela1, tabela2):
  2. from bs4 import BeautifulSoup
  3. with open('tabela.html', 'r') as file:
  4. soup = BeautifulSoup(file, "html5lib")
  5. soup.prettify()#reorganiza as tags
  6. tabela_all = soup.find_all('tbody')
  7. coluna1 = tabela_all[0].find_all('tr')
  8. coluna2 = tabela_all[1].find_all('tr')
  9. valores_return(coluna1, tabela1)
  10. valores_return(coluna2, tabela2)
  11. def valores_return(colunas, tabela):
  12. for coluna in colunas:
  13. celula = coluna.find_all('td')
  14. celula = [ele.text.strip() for ele in celula]
  15. tabela.append([ele for ele in celula if ele])
  16. def separar(palavra):
  17. numero = []
  18. for word in palavra:
  19. if word.isdigit():
  20. numero += word
  21. return (''.join(numero))
  22. def initsintatico(token, args,erro):
  23. import os
  24. if not(os.path.isfile('dicionario1.dtc')and os.path.isfile('dicionario2.dtc')):
  25. save()
  26. from sintatico import analisadorsintatico
  27. dict_tabela1 = load("dicionario1.dtc")
  28. dict_tabela2 = load("dicionario2.dtc")
  29. analisadorsintatico(dict_tabela1, dict_tabela2, token, args,erro)
  30. def load(filename):
  31. import pickle
  32. file = open(filename, "rb")
  33. return pickle.load(file)
  34. def save():
  35. tabela1 = []
  36. tabela2 = []
  37. beut(tabela1, tabela2)
  38. topo = tabela1[0]
  39. del tabela1[0]
  40. dict_tabela1 = {}
  41. dict_tabela2 = {}
  42. for linhas in tabela1:
  43. i = 0;
  44. for linha in linhas:
  45. if linha.isdigit() and i <= len(topo):
  46. dict_tabela1[(linhas[0], topo[i - 1])] = [int(linha)]
  47. i += 1
  48. for i in range(len(tabela2)):
  49. if (((tabela2[i][1]).split('::= '))[1]).split(" ")[0] != 'î':
  50. dict_tabela2[int(separar(tabela2[i][0]))] = ((((tabela2[i][1]).split('::= '))[1]).split())
  51. else:
  52. dict_tabela2[int(separar(tabela2[i][0]))] = []
  53. saveFile(dict_tabela1, "dicionario1.dtc")
  54. saveFile(dict_tabela2, "dicionario2.dtc")
  55. def saveFile(dict, filename):
  56. import pickle
  57. dicionario = open(filename, "wb")
  58. pickle.dump(dict, dicionario)
  59. dicionario.close()