tests.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. '''
  2. Created on Jun 30, 2020 @author: Levi
  3. '''
  4. import zipfile
  5. import os
  6. from xml.etree import ElementTree as ET
  7. from dataclasses import dataclass
  8. @dataclass
  9. class Account:
  10. name: str = None
  11. folder: str = None
  12. id: str = None
  13. updated: bool = None
  14. imported: bool = None
  15. # print(os.environ)
  16. us_profile = os.environ.get('USERPROFILE').replace('\\', '/')
  17. # print(us_profile)
  18. teamnet = 'appdata/Roaming/Teamnet/'
  19. path = os.path.join(us_profile, teamnet)
  20. conf_folder = list(filter(lambda f: 'Teamnet' in f, os.listdir(path)))[0]
  21. path = os.path.join(path, conf_folder)
  22. ver = os.listdir(path)[-1]
  23. ver_folder = os.path.join(path, ver)
  24. # print(os.listdir(ver_folder))
  25. conf_file = os.path.join(ver_folder, 'user.config')
  26. revisal_tree = ET.parse(conf_file)
  27. root = revisal_tree.getroot()
  28. # for child in root[0][0][8][0][0]:
  29. accounts = []
  30. for child in root.iter('AngajatorInfo'):
  31. account = Account()
  32. for name, dir_, ident, isupd, isimport in zip(child.iter('Nume'), child.iter('Folder'), child.iter('Identificator'), child.iter('IsUpdated'), child.iter('IsImportFinished')):
  33. account.name = name.text
  34. account.folder = dir_.text
  35. account.id = ident.text
  36. account.updated = isupd.text
  37. account.imported = isimport.text
  38. accounts.append(account)
  39. path1 = os.path.join(us_profile, teamnet)
  40. db_folder = list(filter(lambda f: 'Revisal' in f, os.listdir(path1)))[0]
  41. print(db_folder)
  42. pass
  43. # path = 'c:/Users/levi/Documents/DECEL/Revisal Hg500/Rapoarte/'
  44. #
  45. # rvs_files = list(filter(lambda f: f.endswith('.rvs'), os.listdir(path)))
  46. # rvs_files_sorted = sorted(rvs_files, key=lambda x: os.stat(os.path.join(path, x)).st_mtime, reverse=True)
  47. #
  48. # rvs_file = rvs_files_sorted[0]
  49. # zipfile.ZipFile.extractall(self, path, members, pwd)
  50. # with zipfile.ZipFile(os.path.join(path, rvs_file)) as zip_file:
  51. # zip_file.extractall(path=path)