10cbazbt3.py 文件源码

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

项目:10cbazbt3 作者: bazbt3 项目源码 文件源码
def login():
    # Input account name:
    my_acctname = input(Fore.YELLOW + Style.DIM + "10C Username (account email address): " + Fore.WHITE)
    # Input account password:
    my_acctpass = getpass.getpass(Fore.YELLOW + Style.DIM + "10C Password (is not shown onscreen): " + Style.RESET_ALL)
    # Construct the login URL & data passed to the API:
    url = 'https://api.10centuries.org/auth/login'
    loginheaders = {'Content-Type': 'application/x-www-form-urlencoded'}
    data = {'client_guid': my_client_guid, 'acctname': my_acctname, 'acctpass': my_acctpass}
    response = requests.post(url, headers=loginheaders, data=data)
    # Saves the server's JSON response to 'loginresponse.txt':
    file = open("loginresponse.txt", "w")
    file.write(response.text)
    file.close()
    # Extracts the auth token from the JSON file:
    json_data = open("loginresponse.txt", "r")
    decoded = json.load(json_data)
    temptoken = decoded['data']['token']
    # Saves just the auth token to authtoken.txt:
    file = open("authtoken.txt", "w")
    file.write(temptoken)
    file.close()
    # Let the user know the application is authorised:
    print("")
    print(Fore.BLACK + Back.GREEN + "Authorised" + Style.RESET_ALL + Fore.YELLOW + Style.DIM + " (but check for a 'Connected' indicator!)" + Style.RESET_ALL)
    print("")
    setloginstatus("In")
    authorise()


# Define the 'logout' subroutine:
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号