用python做的小小软件

可以进行算术运算(二元一次方程,阶乘)
运用库进行网易云音乐的下载(需要用到cloudmusic库)
简易的文件搜索
查询天气
…(虽然有点少,但我会加油的哈哈哈哈)

import os
import sys
import cloudmusic
def get_weather_data() :
    print('------天气查询------')
    city_name = str(e.enterbox('请输入要查询的城市名称:','天气系统','佛山'))
    url1 = 'http://wthrcdn.etouch.cn/weather_mini?city='+urllib.parse.quote(city_name)
    url2 = 'http://wthrcdn.etouch.cn/weather_mini?citykey=101010100'
    weather_data = urllib.request.urlopen(url1).read()
    weather_data = gzip.decompress(weather_data).decode('utf-8')
    weather_dict = json.loads(weather_data)
    return weather_dict

def show_weather(weather_data):
    weather_dict = weather_data
    if weather_dict.get('desc') == 'invilad-citykey':
        e.msgbox('你输入的城市名有误,或者天气中心未收录你所在城市','查询错误')
    elif weather_dict.get('desc') =='OK':
        text=''
        forecast = weather_dict.get('data').get('forecast')
        text+=('城市:'+ weather_dict.get('data').get('city')+'\n')
        text+=('温度:'+ weather_dict.get('data').get('wendu') + '℃ '+'\n')
        text+=('感冒:'+ weather_dict.get('data').get('ganmao')+'\n')
        text+=('风向:'+ forecast[0].get('fengxiang')+'\n')
        text+=('风级:'+ forecast[0].get('fengli')+'\n')
        text+=('高温:'+ forecast[0].get('high')+'\n')
        text+=('低温:'+ forecast[0].get('low')+'\n')
        text+=('天气:'+ forecast[0].get('type')+'\n')
        text+=('日期:'+ forecast[0].get('date')+'\n')
        text+=('*******************************')
        e.msgbox(text)
        show()

def suanshu():
    list1=['1:二元一次方程','2:使用系统计算机','3.阶乘']
    xuanxiang = e.buttonbox(msg='请选择使用方式',title='算术系统',choices=list1)
    if xuanxiang==list1[0]:
        result=''
        list2=['二次项系数a','一次项系数b','常数c']
        a,b,c=e.multenterbox('请输入各项系数','二元一次方程',list2,'')
        a,b,c=int(a),int(b),int(c)
        w =b**2-4*a*c
        if w < 0:
            result='无解'
        elif w > 0:
            x1 = ((-b) + ((w) ** (1 / 2))) / (2 * a)
            x2 = ((-b) - ((w) ** (1 / 2))) / (2 * a)
            result+=str(x1)
            result+=' '+str(x2)
        elif w == 0:
            x3 = -b / (2 * a)
            result=x3
        if w >= 0:
            e.msgbox(result,'结果')
    if xuanxiang==list1[1]:
        os.system('calc.exe')
    if xuanxiang==list1[2]:
        enter=int(e.enterbox('请输入要求的阶乘数','阶乘系统',''))
        x=1
        if enter>1:
            for each in range(1,enter+1):
                x*=each
        elif enter==1:
            pass
        else:
            x=0
        if x:
            e.msgbox('结果为:'+str(x),'阶乘系统')
        else:
            e.msgbox('输入错误','阶乘系统')
    show()

def search_file():
        name=e.enterbox('请输入要搜索的文件名或类型','文件搜索系统')
        if not name==None:
            path=str(e.diropenbox('请寻找文件根目录'))
            os.chdir(path)
            each_dir=os.walk(os.getcwd())
            msg=''
            for each in each_dir:
                for each_file in each[2]:
                    if os.path.splitext(each_file)[1] == name or each_file == name:
                        msg+=(os.path.join(os.getcwd(),each_file))+'\n'
            if msg:e.msgbox(msg,'搜索结果')
            else:e.msgbox('未找到文件')
        else:
            pass
        show()
        
def getmusic():
    choice=['1.获取歌单信息','2.获取个人信息','3.退出本系统']
    choose=e.buttonbox('请选择操作','网易云音乐系统',choice)
    if choose == choice[0]:
        try:
            list_id=int(e.enterbox('请输入歌单的id','网易云音乐系统'))
        except:
            show()
        try:
            play_list=cloudmusic.getPlaylist(list_id)
        except:
            e.msgbox('获取失败,请输入正确的歌单id')
            getmusic()
        choice1=['1.下载歌单','2.退出本程序']
        msg=''
        for each in play_list:
            msg+=each.name+'\n'
        choose=e.buttonbox('歌曲名如下:\n'+msg,'请选择接下来的操作',choice1)
        if choose==choice1[0]:
            dir=e.diropenbox('请选择存放地址')
            os.chdir(dir)
            e.msgbox('点确定以开始下载','网易云音乐系统')
            for music in play_list:
                music.download(level='lossless')
            e.msgbox('下载完成')
        elif choose==choice1[1]:
            pass
    elif choose == choice[1]:
        id=e.enterbox('请输入要查找的id','网易云音乐系统')
        user=cloudmusic.getUser(id)
        msg=''
        dict1={'id':'用户id',
            'level':'用户等级',
            'listenSongs':'累计听歌数量',
            'createTime':'账号创建时间',
            'nickname':'用户昵称',
            'avatarUrl':'头像url',
            'city':'所在城市的行政区划代码',
            'province':'所在省份的行政区划代码',
            'vipType':'vip类型',
            'birthday':'生日时间戳',
            'signature':'个性签名',
            'fans':'粉丝数量',
            'follows':'关注的用户数量',
            'eventCount':'动态数量',
            'playlistCount':'创建的歌单数量'}
        for key,value in dict1.items():     
                msg+=str(value)+':'+str(eval('user.'+str(key)))+'\n'
        choice=['1.获取用户的歌单(下载)','2.退出本程序']
        choose=e.buttonbox('信息如下:\n'+msg,'网易云音乐系统',choice)
        if choose == choice[0]:
            msg=''
            playlist=user.getPlaylist()
            n=1
            for each in playlist:
                msg+=str(n)+'.'+each['name']+'\n'
                n+=1
            choice=['1.下载歌单','2.退出本程序']
            choose=e.buttonbox('歌单名称:\n'+msg,'网易云音乐系统',choice)
            if choose==choice[0]:
                list_range=e.multenterbox('请选择下载的范围\n'+msg,'网易云音乐系统',('起始歌单','结束歌单'))
                dir=e.diropenbox('请选择存放地址')
                for i in range(int(list_range[0])-1,int(list_range[1])):           
                    dirname=playlist[i]['name']
                    dirs=os.path.join(dir,dirname)
                    os.mkdir(dirs)
                    os.chdir(dirs)
                    download_music(playlist[i]['id'])
                    os.chdir(dir)
                    
        elif choose == choice[1]:
            pass
        
    show()
    
def download_music(list_id):
        try:
            play_list=cloudmusic.getPlaylist(list_id)
            for music in play_list:
                music.download(level='lossless')
            print('下载完成')
        except:
            print('获取失败,请输入正确的歌单id')
        
def show():
    list1=['1.算术','2.天气查询','3.搜索文件','4.网易云音乐系统','5.退出程序']
    choose=e.buttonbox('请选择功能','小小软件',list1)
    if choose == list1[0]:suanshu()
    elif choose == list1[1]:show_weather(get_weather_data()) 
    elif choose == list1[2]:search_file()
    elif choose == list1[3]:getmusic()
    elif choose == list1[4]:sys.exit()
   
   









show()
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值