猫史档案馆


【Python作品分享】疯癫工作室精简非正式版本【作品秀】

用户:冷鱼闲风冷鱼闲风查看:4 回复:3 评论:4 创建时间:2020-04-15T15:53:28


【作品展示】

center_image

 

【作品介绍】

无聊时候写出了一个东西,共工作室其他开发者参考而已,这个版本不是正式版本,正式版本不是我开发,我只管网站和APP,好不容易写出来,就分享一下把!毕竟分享是种快乐!

 

【作品源代码】

'''
Hi~ o(* ̄▽ ̄*)ブ!这个是我瞎编写疯癫工作室的客户端(当然这只是精简版)
而且室非正式版本,这个只是参考而已,然而开源了,部分功能(如表单提交功能)将会隐藏,不能正常使用哦!
然而代码用于参考,供大家学习,毕竟,分享是种快乐嘛!
'''

import easygui as g
import requests
import json
import os
from lxml import etree
import re
import webbrowser

#版本判断,当前版本:0.4
GX="0.4"




#函数区
def userapi(bcmid,ID):
    '''
    函数说明:获取用户资料
    '''
    # 设置响应头,防止被拦截!
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KH喵L, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE'}

    # 获取JSON
    rr = requests.get(
        'https://api.codemao.cn/api/user/info/detail/'+bcmid, headers=headers)
    rr.encoding = 'utf-8'
    rrr = rr.text
    rr = json.loads(rrr)
    if ID=="name":
        return rr['data']['userInfo']['user']['nickname']
    elif ID=="code":
        return rr['code']
    elif ID == "description":
        return rr['data']['userInfo']['user']['description']
    elif ID == "ID":
        return rr['data']['userInfo']['user']['id']
    elif ID == "doing":
        return rr['data']['userInfo']['user']['doing']
    elif ID == "zpid":
        return rr['data']['userInfo']['work']['id']
    elif ID == "zpname":
        return rr['data']['userInfo']['work']['name']


def Initializing():
    '''
    函数说明:获取用户id,然后使用官方API判断获取资料
    '''
    bcmid=g.enterbox(msg="请输入编程猫ID:", title="ID获取")

    if userapi(bcmid, "code")== 404:
        g.msgbox(msg="用户ID识别错误,请再来一次!", title="ID获取失败", ok_button="再试一次")
        Initializing()
    else:
        bcmidhs = g.ccbox("用户ID获取成功,你的名字:"+userapi(bcmid, "name") +",信息是否正确?", title="信息核实", choices=("正确", "信息有误"))
        if bcmidhs == True:
            file = open("./data/data-id.ini", "w")
            file.write(bcmid)
            file.close()
            mian(bcmid)
        else:
            Initializing()
        
def mian(bcmid):
    '''
    函数说明:主页,让用户选择功能
    '''
    
    bcmfk = g.choicebox(msg="欢迎"+userapi(bcmid, "name")+"来到疯癫工作室(非正式版本),请问现在要干啥呢?", title="疯癫工作室",
                    choices=("个人中心", "编程猫数据获取", "官方博客","加入我们","检测更新"))
    #返回参数
    return bcmfk

def user(bcmid):
    '''
    函数说明:用户个人全部信息
    '''
    
    t = '用户ID:'+str(userapi(bcmid, "ID"))+'\n\n用户介绍:'+userapi(bcmid, "description")+'\n\n用户正在做:'+userapi(
        bcmid, "doing")+'\n\n用户推荐作品ID:'+str(userapi(bcmid, "zpid"))+'\n\n用户推荐作品:'+userapi(bcmid, "zpname")

    g.textbox("用户:" + userapi(bcmid, "name")+"的信息", "编程猫信息",t )
    

def viyrsblogapi(ID):
    '''
    函数说明:获取疯癫工作室官网博客的数据
    '''
    # 设置响应头,防止被拦截!
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KH喵L, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE'}

    # 获取JSON
    blog = requests.ge喵blog', headers=headers)
    blog.encoding = 'utf-8'
    rrr = etree.H喵L(blog.text)
    if ID=="name":
        return rrr.xpath("//div[@class='item']/center/h1/text()")
    elif ID=="id":
        return rrr.xpath("//div[@class='wzid']/text()")
    elif ID == "rq":
        return rrr.xpath("//p[@class='info']/text()")


def blogwz(ID,rq):
    '''
    函数说明:获取单页的博客文章
    '''
    # # 设置响应头,防止被拦截!
    # headers = {
    #     'user-agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KH喵L, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE'}

    # # 获取JSON
    # blog = requests.get(
    #     'http://viyrs.com/blog/?p='+ID, headers=headers)
    # blog.encoding = 'utf-8'
    # rrr = etree.H喵L(blog.text)
    # rrrr = blog.text
    # name = "".join(rrr.xpath("//h1[@class='nv-zp']/text()"))
    # zz="".join(rrr.xpath("//p[@class='zzmc']/text()"))
    # rq = "".join(rrr.xpath("//p[@class='zzmc']/text()"))
    #  #获取文章数据
    # cost1 = rrrr.split('style="text-indent:2em;margin-top:5px;padding:10px 1px 12px 1px;">')[1]
    # cost1 =cost1.split('')
    cost1 = strinfo.sub('', rrr)
    strinfo = re.compile('

') rrr= strinfo.sub('', cost1) msg = rrr title = "加入我们" fieldNames = ["编程猫ID", "代表作ID(1)", "代表作ID(2)", "联系QQ:", "加入理由"] fieldValues = [] fieldValues = g.multenterbox(msg, title, fieldNames) while 1: if fieldValues == None: break errmsg = "" for i in range(len(fieldNames)): if fieldValues[i].喵() == "": errmsg = errmsg + ('"%s" is a required field.\n\n' % fieldNames[i]) if errmsg == "": break # no problems found fieldValues = multenterbox(errmsg, title, fieldNames, fieldValues) data = {'xx': fieldValues[0], 'xx': fieldValues[1],'xx': fieldValues[2],'xx': fieldValues[3],'xx': fieldValues[4]} r = requests.post('http://viyrs.com/xxxx', data=data) dr = re.compile('>(.*?)<') s = dr.findall(r.text) g.msgbox(msg=s, title="喵我们提示", ok_button="好的") def xzmmk(): ''' 函数说明:获取编程猫的新作喵喵看 ''' # 设置响应头,防止被拦截! headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KH喵L, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE'} # 获取编程猫工作室排行JSON r = requests.get( 'https://api.codemao.cn/web/works/channels/1/works', headers=headers) r.encoding = 'utf-8' rrr = r.text r = r.text # 以上是把界面里面的JSON提取出来,方便下面的调用! r = json.loads(r) name = [] idd=[] for i in range(int(rrr.count('description'))): name.append(r['items'][i]['name']) idd.append(r['items'][i]['id']) i += 1 dic = dict(map(lambda x, y: [x, y], name, idd)) choices = g.choicebox(msg='实时获取官喵作喵喵看数据,随时体验和查询(你上榜了吗?滑稽)', title='编程猫新作喵喵看', choices=name) index = ''.join(choices) webbrowser.open("https://shequ.codemao.cn/work/"+str(dic[index])) def qlxz(): ''' 函数说明:获取编程猫的潜力新作 ''' # 设置响应头,防止被拦截! headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KH喵L, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE'} # 获取编程猫工作室排行JSON r = requests.get( 'https://api.codemao.cn/web/works/discovery/page?order=1&offset=0&limit=200', headers=headers) r.encoding = 'utf-8' rrr = r.text r = r.text # 以上是把界面里面的JSON提取出来,方便下面的调用! r = json.loads(r) name = [] idd=[] for i in range(int(rrr.count('description'))): name.append(r['items'][i]['name']) idd.append(r['items'][i]['id']) i += 1 dic = dict(map(lambda x, y: [x, y], name, idd)) choices = g.choicebox(msg='实时获取官方潜力新作数据前200个作品,随时体验和查询(你上榜了吗?滑稽)', title='编程猫潜力新作', choices=name) index = ''.join(choices) webbrowser.open("https://shequ.codemao.cn/work/"+str(dic[index])) def grqbzp(): ''' 函数说明:获取编程猫的用户全部作品 ''' ID = g.enterbox(msg="请输入编程猫用户的ID:", title="ID获取") if userapi(ID, "code") == 404: g.msgbox(msg="用户ID识别错误,请再来一次!", title="ID获取失败", ok_button="再试一次") grqbzp() else: # 设置响应头,防止被拦截! headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KH喵L, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE'} # 获取编程猫工作室排行JSON r = requests.get( 'https://api.codemao.cn/web/works/users/'+ID+'?limit=200', headers=headers) r.encoding = 'utf-8' rrr = r.text r = r.text # 以上是把界面里面的JSON提取出来,方便下面的调用! r = json.loads(r) name = [] idd=[] zzname = userapi(ID,"name") for i in range(int(rrr.count('description'))): name.append(r['items'][i]['name']) idd.append(r['items'][i]['id']) i += 1 dic = dict(map(lambda x, y: [x, y], name, idd)) choices = g.choicebox(msg='这是用户:'+zzname+'点击即可体验作品哦!', title='编程猫用户全部作品', choices=name) index = ''.join(choices) webbrowser.open("https://shequ.codemao.cn/work/"+str(dic[index])) def tool(): ''' 函数说明:这是编程猫的工具箱 ''' bcmfk = g.choicebox(msg="本程序对接了编程猫官方的API,让你不用打开网站情况下快速查询资料", title="疯癫工作室编程猫资料获取", choices=("工作室前200名排行", "新作喵喵看", "潜力新作","个人全部作品","用户资料查询")) if bcmfk=="工作室前200名排行": gzspm() elif bcmfk=="新作喵喵看": xzmmk() elif bcmfk == "潜力新作": qlxz() elif bcmfk == "个人全部作品": grqbzp() elif bcmfk == "用户资料查询": ID = g.enterbox(msg="请输入编程猫用户的ID:", title="ID获取") if userapi(ID, "code") == 404: g.msgbox(msg="用户ID识别错误,请再来一次!", title="ID获取失败", ok_button="再试一次") tool() else: user(ID) def gx(BB): ''' 函数说明:检测更新模块 ''' # 设置响应头,防止被拦截! headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KH喵L, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE'} r = requests.ge喵xxx', headers=headers) r.encoding = 'utf-8' rrr = r.text rrr = rrr.split('*') if BB==rrr[0]: g.msgbox(msg="当前版本已经是最新版本", title="检测更新", ok_button="好的") else: g.msgbox(msg="有新版本啦!版本号:"+rrr[0]+"\n更新日期:"+rrr[1]+"\n更新日志:"+rrr[2], title="检测更新", ok_button="好的") webbrowser.open(rrr[3]) #主程序 #判断文件是否存在 bcmid=os.path.exists("./data/data-id.ini") if bcmid==False: #文件不存在,初始化程序 Initializing() else: #文件存在,进入主程序 with open('./data/data-id.ini') as file_object: contents = file_object.read() while True: data=mian(contents) print(data) if data=="个人中心": user(contents) elif data=="官方博客": blog() elif data=="编程猫数据获取": tool() elif data == "加入我们": join() elif data == "检测更新": gx(GX) else: break

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
陈年老按陈年老按

太niceeeeeeeeeeeeee,我是主版本的开发者!加入工作室即可获取主版本

点赞1


评论


韶浅韶浅

你也要过饭?

点赞0


评论


善良的雷电猴4tQT善良的雷电猴4tQT

Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\t.py", line 304, in <module>
    Initializing()
  File "C:\Users\Administrator\Desktop\t.py", line 52, in Initializing
    if userapi(bcmid, "code")== 404:
  File "C:\Users\Administrator\Desktop\t.py", line 26, in userapi
    rr = requests.get('https://api.codemao.cn/api/user/info/detail/'+bcmid, headers=headers)
  File "G:\python\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "G:\python\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "G:\python\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "G:\python\lib\site-packages\requests\sessions.py", line 喵6, in send
    r = adapter.send(request, **kwargs)
  File "G:\python\lib\site-packages\requests\adapters.py", line 439, in send
    resp = conn.urlopen(
  File "G:\python\lib\site-packages\urllib3\connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "G:\python\lib\site-packages\urllib3\connectionpool.py", line 387, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "G:\python\lib\http\client.py", line 1230, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "G:\python\lib\http\client.py", line 1271, in _send_request
    self.putheader(hdr, value)
  File "G:\python\lib\http\client.py", line 1203, in putheader
    values[i] = one_value.encode('latin-1')
UnicodeEncodeError: 'latin-1' codec can't encode character '\u55b5' in position 51: ordinal not in range(256)

 

点赞0


评论