get_dic.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #import msoffcrypto
  2. from .flightDB import flightDB
  3. from pypinyin import pinyin, Style
  4. #import io
  5. import openpyxl
  6. from unitls.LogerinTxt import app_logger
  7. import datetime
  8. def get_full_pinyin1(word, style=Style.NORMAL, separator=''):
  9. pinyin_list = pinyin(word, style=style)
  10. #使用列表推导式获取每个汉字的第一个拼音(不带声调),并使用 separator 连接
  11. full_pinyin = separator.join([''.join(syllable[0]) for syllable in pinyin_list])
  12. return full_pinyin
  13. def get_full_pinyin2(word, style=Style.NORMAL, separator=''):
  14. return ''.join([word[0][0] for word in pinyin(word, style=Style.NORMAL)])
  15. def get_dic(database:flightDB, fileName):
  16. dic=["维修一队","维修二队","维修三队","维修四队","支援人员"]
  17. try:
  18. fdb = database
  19. IDS=fdb.getSingledata("工号",'workerinfo')
  20. IDSNOW=[]
  21. try:
  22. workbook = openpyxl.load_workbook(filename=fileName) #非加密文档
  23. for sheetname in dic:
  24. mysheet = workbook[sheetname]
  25. myrows = list(mysheet.values)[1:]
  26. mytitle = list(mysheet.values)[0]
  27. for myrow in myrows:
  28. mydics0 = {}
  29. mydics1 = {}
  30. for i in range(0, (len(mytitle))):
  31. a = get_full_pinyin1(str(myrow[0])) + ":" + get_full_pinyin2(str(myrow[0]))
  32. mydics0[mytitle[i]] = "%s"%myrow[i]
  33. mydics0[mytitle[11]] = "%s" % a
  34. if i != 3 and i != 11:
  35. mydics1[mytitle[i]] = "'%s'" % myrow[i]
  36. elif i == 11:
  37. mydics1[mytitle[11]] = "'%s'" % a
  38. #a= fdb.getSingledata("工号",'workerinfo')
  39. if str(mydics0["工号"]) in str(IDS) or str(mydics0["工号"]) in IDSNOW:
  40. fdb.lazyUpdateItem('workerinfo',mydics1,"工号='%s'"%mydics0["工号"])
  41. else:
  42. fdb.lazyInsertData('workerinfo',mydics0)
  43. IDSNOW.append(mydics0["工号"])
  44. #print(1)
  45. fdb.FunctionCommit()
  46. return "ok"
  47. except Exception as e:
  48. print(datetime.datetime.now(),'[数据库操作]数据库获取错误!!检查通讯录文件!人员显示功能失效!!')
  49. print(e)
  50. app_logger.log_error(e)
  51. # 需要QT输出警告弹框信息
  52. fdb.FunctionCommit()
  53. return "fail"
  54. except Exception as e:
  55. app_logger.log_error(e)
  56. return "fail"