码迷,mamicode.com
首页 > 微信 > 详细

练习题(登陆-进度条-微信接口判断qq-微信接口判断列车时刻表-)

时间:2016-09-17 00:39:19      阅读:327      评论:0      收藏:0      [点我收藏+]

标签:

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(‘\r%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("\r[%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)

 

练习题(登陆-进度条-微信接口判断qq-微信接口判断列车时刻表-)

标签:

原文地址:http://www.cnblogs.com/renfanzi/p/5834622.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!