基于python的类的调用(快递查询,天气查询,学员管理,旅游查询,电影查询,景点查询,手机销售系统,内涵段子,手机号id查询))

一、汇总模型

#模块<==>python文件
#引入express中的KD类
from express import KD
from weather import WT
from student_dict_object import ST
from phone_dict_object import PHONE
from travel import Travel
from movie import Movie
from scene import Scene
from nhdz import NH
from phoneid import PHONES
while 1:
    print('1.快递查询')
    print('2.天气查询')
    print('3.学员管理')
    print('4.旅游查询')
    print('5.电影查询')
    print('6.景点查询')
    print('7.手机销售系统')
    print('8.内涵段子')
    print('9.手机号id查询')
    print('0.退出')
    num = input('请选择:')
    if num == '1':
        #创建一个KD对象
        kd = KD()
        kd.query_express()
    elif num == '2':
        wt = WT()
        wt.weather()
    elif num == '3':
        st = ST()
        st.start()
    elif num == '4':
        tr = Travel()
        tr.travel()
    elif num == '5':
        mm = Movie()
        mm.query_movie()
    elif num == '6':
        ss = Scene()
        ss.query_scene()
    elif num == '7':
        phone = PHONE()
        phone.start()
    elif num == '8':
        nh = NH()
        nh.Nhdz()
    elif num == '9':
        ph = PHONES()
        ph.phone()
    else:
        print('退出')
        break
二,快递查询

import requests
import json
class KD(object):
    def __init__(self):
        self.kd_dict = {1:'shentong',2:'ems',3:'shunfeng',4:'yuantong',5:'zhongtong',6:'yunda',7:'tiantian',8:'huitong',9:'quanfeng',10:'debang',11:'zhaijisong'}
    def query_express(self):
        while 1:
            print('请选择您的快递公司:')
            print('1.申通快递:')
            print('2.EMS邮政快递:')
            print('3.顺丰递运:')
            print('4.圆通快递:')
            print('5.中通快递:')
            print('6.韵达快递:')
            print('7.天天快递:')
            print('8.汇通快递:')
            print('9.全峰快递:')
            print('10.德邦物流:')
            print('11.宅急送:')
            print('0.退出')
            num = int(input('选择您的快递公司:'))

            while num not in range(0,12):
                num = int(input('选项有误,请重选:'))
            if num == 0:
                break
            type = self.kd_dict[num]
            postid = input('请输入您的快递单号:')
            url = 'http://www.kuaidi100.com/query?type=%s&postid=%s'%(type,postid)
            rs = requests.get(url)
            kd_info = json.loads(rs.text)
            msg = kd_info['message']
            if msg == 'ok':
                print('您的快递%s物流信息如下:'%postid)
                data = kd_info['data']
                for data_dict in data:
                    time = data_dict['time']
                    context = data_dict['context']
                    print('时间:%s %s'%(time,context))
            else:
                if msg == '参数错误':
                    print('您输入信息有误,请重输:')
                else:
                    print(msg)

print(__name__)
if __name__ == '__main__':
    ex = KD()
    ex.query_express()
二、天气查询

#天气预报
#引入requests
import requests
#引入python内置的包json,用来解析和生成
import json
class WT():
    def __init__(self):
        pass
    def weather(self):
        #url统一资源定位符  主机域名/目录/?地点&格式。。。
        #windows+r  cmd   打开命令行工具  输入pip install requests
        print('欢迎进入天气预报查询系统!')
        while 1:
            city = input('请输入想要查询的城市的名称(输入0退出):')
            if city == '0':
                print('已退出天气预报查询系统!')
                break
            else:
                url = 'http://api.map.baidu.com/telematics/v3/weather?location=%s&output=json&ak=TueGDhCvwI6fOrQnLM0qmXxY9N0OkOiQ&callback=?'%city
                #使用requests发起请求,接受返回的结果
                response = requests.get(url)
                #使用loads函数 将json字符串转化为python 的字典或列表
                rs_dict = json.loads(response.text)
                #取出error
                error_code = rs_dict['error']
                if error_code == 0:
                    #从字典中取出数据
                    results = rs_dict['results']
                    #根据索引取出城市天气信息字典
                    info_dict = results[0]
                    #取出城市名称
                    city_name = info_dict['currentCity']
                    pm25 = info_dict['pm25']
                    print('当前城市:%s pm25:%s'%(city_name,pm25))
                    #取出天气列表
                    weather_data = info_dict['weather_data']
                    #for循环取出每一天的小字典
                    for weather_dict in weather_data:
                        date = weather_dict['date']
                        weather = weather_dict['weather']
                        wind = weather_dict['wind']
                        temperature = weather_dict['temperature']
                        print('%s %s %s %s'%(date,weather,wind,temperature))

                    index = info_dict['index']
                    for index_dict in index:
                        title = index_dict['title']
                        zs = index_dict['zs']
                        tipt = index_dict['tipt']
                        des = index_dict['des']
                        print('%s %s %s %s'%(title,zs,tipt,des))
                else:
                    print('没有查询到天气信息')
print(__name__)
if __name__ == '__main__':
    wt = WT()
    wt
  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值