back.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import re
  2. import json
  3. import string
  4. class IdCardStraight:
  5. """
  6. """
  7. def __init__(self, result):
  8. self.result = [
  9. i.replace(" ", "").translate(str.maketrans("", "", string.punctuation))
  10. for i in result
  11. ]
  12. self.out = {"Data": {"FrontResult": {}}}
  13. self.res = self.out["Data"]["FrontResult"]
  14. self.res["data"] = ""
  15. self.res["isauthor"] = ""
  16. # def IS_author(self):
  17. # """
  18. # 签发机关
  19. # """
  20. # def
  21. def isauthor(self):
  22. """
  23. 签发机关
  24. """
  25. addString = []
  26. # for i in range(len(self.result)):
  27. txt = self.result[2]
  28. txt = txt.replace("中华人民共和国", "").replace("居民身份证", "").replace("签发机关", "")
  29. print(txt)
  30. # txt2=txt.split("签发日期")
  31. print('--------')
  32. print(txt)
  33. # addString.insert(0, txt.split("有效期限")[-1])
  34. addString.append(txt)
  35. # self.result= "temp"
  36. if len(addString) > 0:
  37. self.res["isauthor"] = "".join(addString)
  38. def data(self):
  39. """
  40. 签发机关
  41. """
  42. addString = []
  43. txt = self.result[3]
  44. txt = txt.replace("中华人民共和国", "").replace("居民身份证", "").replace("有效期限", "")
  45. addString.append(txt)
  46. # self.result= "temp"
  47. if len(addString) > 0:
  48. self.res["data"] = "".join(addString)
  49. def run(self):
  50. print(self)
  51. self.data()
  52. # self.national()
  53. # self.birth_no()
  54. self.isauthor()
  55. print(self.out)
  56. return json.dumps(self.out)