import re
import json
import string


class IdCardStraight:
    """
    """

    def __init__(self, result):
        self.result = [
            i.replace(" ", "").translate(str.maketrans("", "", string.punctuation))
            for i in result
        ]
        self.out = {"Data": {"FrontResult": {}}}
        self.res = self.out["Data"]["FrontResult"]
        self.res["data"] = ""
        self.res["isauthor"] = ""

    # def IS_author(self):
    #     """
    #     签发机关
    #     """

    # def

    def isauthor(self):
        """
        签发机关
        """
        addString = []
        # for i in range(len(self.result)):
        txt = self.result[2]
        txt = txt.replace("中华人民共和国", "").replace("居民身份证", "").replace("签发机关", "")
        print(txt)
        # txt2=txt.split("签发日期")
        print('--------')
        print(txt)
        # addString.insert(0, txt.split("有效期限")[-1])

        addString.append(txt)
        # self.result= "temp"
        if len(addString) > 0:
            self.res["isauthor"] = "".join(addString)

    def data(self):
        """
        签发机关
        """
        addString = []
        txt = self.result[3]
        txt = txt.replace("中华人民共和国", "").replace("居民身份证", "").replace("有效期限", "")
        addString.append(txt)
        # self.result= "temp"
        if len(addString) > 0:
            self.res["data"] = "".join(addString)

    def run(self):
        print(self)
        self.data()
        # self.national()
        # self.birth_no()
        self.isauthor()
        print(self.out)
        return json.dumps(self.out)
