"""
@autor:Yue
@date::16:22
@file:rwKeyData.py
@project:appQutoInfo

"""
import configparser,json,time
from blueprints.settings import testConfig,baseConfig
class rwKeyData:
    def __init__(self,config=baseConfig):
        #kd=config.kdfile
        self.c=configparser.RawConfigParser()
        self.file=config.kdfile
        #print(self.file)



    def readKeyData(self,section,k):


        self.c.read(self.file)
        try:
            #self.c.read(self.file)
            if self.c.get(section,k):
                return self.c.get(section,k)
            else:
                #print("没有找到======", section, k, self.c.get(section, k))
                return self.c.get(section,k)
                # tt=self.c.get(section,k)
                # if tt:
                #     return tt
                #


        except Exception as e:
            #raise Exception("该选项({0}-{1})不存在".format(section, k))
            #raise  Exception("error info=====",e)
            pass
            #return None

    def deleteKeyData(self,section,k=None):

        try:
            self.c.read(self.file)
            if k:
                self.c.remove_option(section,k)

            else:
                self.c.remove_section(section)
            with open(self.file, "w+", encoding="utf8") as file:
                self.c.write(file)


        except Exception as e:
            print(e)



    def getOptions(self,section):
        self.c.read(self.file)
        return self.c.options(section)

    def writeKeyData(self,section,k,v):
        self.c.read(self.file)
        if section in self.c.sections():
            self.c.set(section,k,v)
        else:

            self.c.add_section(section)
            self.c.set(section, k, v)


        with open(self.file,"w+",encoding="utf8") as file:
            self.c.write(file)








if __name__ == '__main__':
    rw=rwKeyData(testConfig)
    #rw.writeKeyData("test","a",1)
    phone_no=18526333369
    t=rw.readKeyData('testsuit','cases_number1121')
    print(t)
    #rw.writeKeyData('baseinfo', 'phone_no', phone_no)

    # rw.writeKeyData('ces1','ces',6)
    # tt=rw.readKeyData('ces1','ces')
    # print(tt,type(tt))
    # for i in range(6):
    #     #tt=int(tt)-1
    #     rw.writeKeyData('ces1', 'ces', int(tt)-1)
    #     tt = rw.readKeyData('ces1','ces')
    #     print(tt)

    #rw.deleteKeyData('circleData')





    #tt=json.loads(t)
    #print(tt,type(tt))



