zoukankan      html  css  js  c++  java
  • 练习题(登陆-进度条-微信接口判断qq-微信接口判断列车时刻表-)

    1、写一个用户的登陆注册的界面,用户的密码用hashlib加密存在文件中,登陆时候,用户的密码要和文件中的密码一致才行

    def sha(password):                                #加密函数
        passwd = hashlib.sha256(bytes('wxtrkbc', encoding='utf-8'))
        passwd.update(bytes(password,encoding='utf-8'))
        return passwd.hexdigest()
     
    def register(user,passwd):                           #注册函数,并将密码加密后存在文件中
        with open('db','a') as f :
            f.write(user+':'+sha(passwd))
     
    def login(user,passwd):                             #登陆函数 并判断登陆密码是否正确
        with open('db','r',encoding='utf-8')as f :
            for line in f :
                info=line.strip().split(':')
                if user==info[0] and sha(passwd)==info[1]:          # 将密码加密后与文件中存储的进行对比,一样就是相同的用户
                    print('login success')
                    return True
                else:
                    print('login error')
                    return False
     
    def main():
        k=input('1注册,2登陆')
        if int(k)==1:
            user=input('输入用户名:')
            passwd=input('输入密码:')
            register(user,passwd)
        elif int(k)==2:
            user = input('输入用户名:')
            passwd = input('输入密码:')
            login(user,passwd)
        else:
            return
    

    2、写一个进度条,用百分比显示进度  

    import os,sys,time
    for i in range(101):
        sys.stdout.write('
    %s %s%%' % ('#'*int(i/100*100),int(i/100*100)))
        sys.stdout.flush()
        # s+='#'
        # print('%s %s%%' %(s,int(i/50*100)))
        time.sleep(0.2)
    # for i in range(101):              #改进一下
    #    #显示进度条百分比  #号从1开始 空格从99递减
    #    hashes = '#' * int(i / 100.0 * 100)
    #    spaces = ' ' * (100 - len(hashes))
    #    sys.stdout.write("
    [%s] %d%%" % (hashes + spaces, i))
    #    sys.stdout.flush()
    #    time.sleep(0.05)
    

    3、利用微信接口来判断某一QQ号的状态 

    import requests
    from xml.etree import ElementTree as ET
    response = requests.get('http://www.webxml.com.cn//webservices/qqOnlineWebService.asmx/qqCheckOnline?qqCode=5768476386')
    r = response.text
    node = ET.XML(r)
    if node.text == 'Y':
        print('在线')
    elif node.text == 'V':
        print('隐身')
    else:
        print('离线')
    

    4、利用微信接口来获取列车时刻表 

    import requests
    from xml.etree import ElementTree as ET
    response=requests.get('http://www.webxml.com.cn/WebServices/TrainTimeWebService.asmx/getDetailInfoByTrainCode?TrainCode=K234&UserID=')
    r=response.text
    root=ET.XML(r)
    for node in root.iter('TrainDetailInfo'):
        print(node.find('TrainStation').text,node.find('ArriveTime').text)
    
    作者:沐禹辰
    出处:http://www.cnblogs.com/renfanzi/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
  • 相关阅读:
    根据输入参数,判定时间范围CheckTimeSpan
    C#登出系统并清除Cookie
    MySQL中使用group_concat遇到的坑
    MySQL中group by 与 order by 一起使用排序问题
    使用VMware安装CentOS 7
    VMware安装Linux提示此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态
    Yii2处理密码加密及验证
    Yii2 的安装及简单使用
    git merge的使用
    PHP中上传文件打印错误,错误类型
  • 原文地址:https://www.cnblogs.com/renfanzi/p/5834622.html
Copyright © 2011-2022 走看看