socli.py 文件源码

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

项目:socli 作者: gautamkrishnar 项目源码 文件源码
def retrieveSavedProfile():
    """
    Retrieves the user's saved profile after a "socli -u" command.
    Asks the user to enter a User ID and saves it if a previous file is not found.

    :return: The user's ID as an integer
    """
    global data_file
    global app_data
    user = None
    try:
        load_datafile()
        if "user" in app_data:
            user = app_data["user"]
        else:
            raise FileNotFoundError  # Manually raising to get value
    except JSONDecodeError:
        # This maybe some write failures
        del_datafile()
        print_warning("Error in parsing the data file, it will be now deleted. Please rerun the "
                      "socli -u command.")
        exit(1)
    except FileNotFoundError:
        print_warning("Default user not set...\n")
        try:
            # Code to execute when first time user runs socli -u
            app_data['user'] = int(inputs("Enter your Stackoverflow User ID: "))
            save_datafile()
            user = app_data['user']
            print_green("\nUserID saved...\n")
        except ValueError:
            print_warning("\nUser ID must be an integer.")
            print(
                "\nFollow the instructions on this page to get your User ID: http://meta.stackexchange.com/a/111130")
            exit(1)
    return user
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号