authorize.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:GoogleGmail-Skill 作者: jcasoft 项目源码 文件源码
def config_file():
    home_dir = os.path.expanduser('~')
    credential_dir = os.path.join(home_dir, '.mycroft')
    filename = os.path.join(credential_dir,'mycroft.conf')
    if os.path.isfile(filename):
        try:
            with open(filename, "r") as jsonFile:
                data = json.load(jsonFile, object_pairs_hook=OrderedDict)
                resultado = list(v for k,v in data.items() if "GoogleGmailSkill" in k.lower())
                if len(resultado) == 0: 
            print "Updating configuration file"
                    data["GoogleGmailSkill"]={"loginEnabled":False,"loginLevel":3,"maxResults":5,"time_format":12}
                    try:
                        with open(filename, "w") as jsonFile:
                            jsonFile.write(json.dumps(OrderedDict(data), indent=4, sort_keys=False))
                    except IOError as error:
                            print "Saving configuration file failed"
                            return False
                    time.sleep(10)
                else:
                    return data

        except IOError as error:
            print "Reading config file failed"
            return False
    else:
        print "Creating new Config file"
        data = {"GoogleGmailSkill":{"loginEnabled":False,"loginLevel":3,"maxResults":5,"time_format":12}}
        try:
            with open(filename, "w") as jsonFile:
                jsonFile.write(json.dumps(OrderedDict(data), indent=4, sort_keys=False))
        except IOError as error:
            print "Saving configuration file failed: "
            return False

        time.sleep(10)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号