栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

猫眼趴趴趴趴趴趴

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

猫眼趴趴趴趴趴趴

教程视频(搬运)
python表格输出
woff转ttf教程
woff转ttf-github

猫眼票房.py
import time
import random
import hashlib
import requests
import jsonpath
import re
import os
import ddddocr
import io
import uuid
import woff2ttf
from fontTools.ttLib import TTFont
from prettytable import PrettyTable
from PIL import ImageFont, Image, ImageDraw

ocr = ddddocr.DdddOcr()


def main():
    uid = uuid.uuid4()
    ts = time.time()*1000
    key = 'A013F70DB97834C0A5492378BD76C53A'
    ua = 'TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzEwMS4wLjQ5NTEuNjQgU2FmYXJpLzUzNy4zNiBFZGcvMTAxLjAuMTIxMC41Mw=='
    index = int(1000*random.random()+1)
    enstr = f'method=GET&timeStamp={ts}&User-Agent={ua}&index={index}&channelId=40009&sVersion=2&key={key}'
    signkey = hashlib.md5(enstr.encode(encoding='UTF-8')).hexdigest()
    url = f'https://piaofang.maoyan.com/dashboard-ajax?orderType=0&uuid={uid}&timeStamp={ts}&User-Agent={ua}&index={index}&channelId=40009&sVersion=2&signKey={signkey}'
    headers = {
        'Accept': 'application/json, text/plain, */*',
        'Referer': 'https://piaofang.maoyan.com/dashboard',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36 Edg/101.0.1210.53'
    }
    html = requests.get(url, headers=headers, verify=False)
    fonturl = 'http:' + 
        re.search('opentype"),url("(//.*?.woff)"',
                  html.json()['fontStyle']).group(1)
    r = requests.get(fonturl)
    with open('temp.woff', 'wb') as f:
        f.write(r.content)
        f.close
    tfont = TTFont("temp.woff")
    uni_list = tfont.getGlyphOrder()[2:]
    print('uni列表:', uni_list)

    charList = []
    woff2ttf.main("temp.woff", "temp.ttf")
    font = ImageFont.truetype("temp.ttf", 40)
    # 将10个uni字符画到im,进而使用ocr识别获得对应数字
    for uchar in uni_list:
        unknown_char = f"\u{uchar[3:]}".encode().decode("unicode_escape")
        im = Image.new(mode='RGB', size=(42, 40), color="white")
        draw = ImageDraw.Draw(im=im)
        draw.text(xy=(0, 0), text=unknown_char, fill=0, font=font)
        img_byte = io.BytesIO()
        im.save(img_byte, format='JPEG')
        charList.append(ocr.classification(img_byte.getvalue()))
    print('对应字符:', charList)
    os.remove("temp.woff")
    # os.remove("temp.ttf")
    # 解析获取需要的数据
    moviename = jsonpath.jsonpath(
        html.json(), '$.movieList.data.list..movieInfo.movieName')
    movieInfo = jsonpath.jsonpath(
        html.json(), '$.movieList.data.list..movieInfo.releaseInfo')
    sumBoxDesc = jsonpath.jsonpath(
        html.json(), '$.movieList.data.list..sumBoxDesc')
    boxRate = jsonpath.jsonpath(
        html.json(), '$.movieList.data.list..boxRate')  # 票房占比
    showCount = jsonpath.jsonpath(
        html.json(), '$.movieList.data.list..showCount')  # 排片场次
    enNum = jsonpath.jsonpath(
        html.json(), '$.movieList.data.list..boxSplitUnit.num')
    enNumDw = jsonpath.jsonpath(
        html.json(), '$.movieList.data.list..boxSplitUnit.unit')

    # 解析票房信息
    table = PrettyTable(['电影名称', '上映时间', '票房', '综合票房', '票房占比', '排片场次'])
    for j in range(len(moviename)):
        tmpstr = enNum[j].split(';')
        rstr = ''
        for i in tmpstr:
            if i == '':
                continue
            tmp = 'uni' + i.replace('&#x', '', 1).replace('.', '').upper()
            for k in range(len(uni_list)):
                if tmp == uni_list[k]:
                    if '.' in i:
                        rstr = rstr + '.'+charList[k]
                    else:
                        rstr = rstr + charList[k]
                    break
        table.add_row([moviename[j], movieInfo[j], sumBoxDesc[j],
                      rstr+enNumDw[j], boxRate[j], showCount[j]])
        # print(
        #     f'{moviename[j]}t{movieInfo[j]}t{sumBoxDesc[j]}t综合票房:{rstr}{enNumDw[j]}t票房占比:{boxRate[j]}t排片场次:{showCount[j]}')
    print(table)


if __name__ == '__main__':
    main()

woff2ttf.py
""" https://www.yundongfang.com/Yun80697.html """
""" https://github.com/hanikesn/woff2otf """

import struct
import zlib
import os
def convert_streams(infile, outfile):
    WOFFHeader = {'signature': struct.unpack(">I", infile.read(4))[0],
                  'flavor': struct.unpack(">I", infile.read(4))[0],
                  'length': struct.unpack(">I", infile.read(4))[0],
                  'numTables': struct.unpack(">H", infile.read(2))[0],
                  'reserved': struct.unpack(">H", infile.read(2))[0],
                  'totalSfntSize': struct.unpack(">I", infile.read(4))[0],
                  'majorVersion': struct.unpack(">H", infile.read(2))[0],
                  'minorVersion': struct.unpack(">H", infile.read(2))[0],
                  'metaOffset': struct.unpack(">I", infile.read(4))[0],
                  'metaLength': struct.unpack(">I", infile.read(4))[0],
                  'metaOrigLength': struct.unpack(">I", infile.read(4))[0],
                  'privOffset': struct.unpack(">I", infile.read(4))[0],
                  'privLength': struct.unpack(">I", infile.read(4))[0]}

    outfile.write(struct.pack(">I", WOFFHeader['flavor']))
    outfile.write(struct.pack(">H", WOFFHeader['numTables']))
    maximum = list(filter(lambda x: x[1] <= WOFFHeader['numTables'], [
                   (n, 2**n) for n in range(64)]))[-1]
    searchRange = maximum[1] * 16
    outfile.write(struct.pack(">H", searchRange))
    entrySelector = maximum[0]
    outfile.write(struct.pack(">H", entrySelector))
    rangeShift = WOFFHeader['numTables'] * 16 - searchRange
    outfile.write(struct.pack(">H", rangeShift))

    offset = outfile.tell()

    TableDirectoryEntries = []
    for i in range(0, WOFFHeader['numTables']):
        TableDirectoryEntries.append({'tag': struct.unpack(">I", infile.read(4))[0],
                                      'offset': struct.unpack(">I", infile.read(4))[0],
                                      'compLength': struct.unpack(">I", infile.read(4))[0],
                                      'origLength': struct.unpack(">I", infile.read(4))[0],
                                      'origChecksum': struct.unpack(">I", infile.read(4))[0]})
        offset += 4*4

    for TableDirectoryEntry in TableDirectoryEntries:
        outfile.write(struct.pack(">I", TableDirectoryEntry['tag']))
        outfile.write(struct.pack(">I", TableDirectoryEntry['origChecksum']))
        outfile.write(struct.pack(">I", offset))
        outfile.write(struct.pack(">I", TableDirectoryEntry['origLength']))
        TableDirectoryEntry['outOffset'] = offset
        offset += TableDirectoryEntry['origLength']
        if (offset % 4) != 0:
            offset += 4 - (offset % 4)

    for TableDirectoryEntry in TableDirectoryEntries:
        infile.seek(TableDirectoryEntry['offset'])
        compressedData = infile.read(TableDirectoryEntry['compLength'])
        if TableDirectoryEntry['compLength'] != TableDirectoryEntry['origLength']:
            uncompressedData = zlib.decompress(compressedData)
        else:
            uncompressedData = compressedData
        outfile.seek(TableDirectoryEntry['outOffset'])
        outfile.write(uncompressedData)
        offset = TableDirectoryEntry['outOffset'] + 
            TableDirectoryEntry['origLength']
        padding = 0
        if (offset % 4) != 0:
            padding = 4 - (offset % 4)
        outfile.write(bytearray(padding))


def convert(infilename, outfilename):
    with open(infilename, mode='rb') as infile:
        with open(outfilename, mode='wb') as outfile:
            convert_streams(infile, outfile)
    infile.close()
    outfile.close()

def main(woff, ttf):
    source_file_name = woff
    target_file_name = ttf
    # target_file_name = source_file_name.rsplit('.', 1)[0] + '.otf'
    convert(source_file_name, target_file_name)
    return 0

if __name__ == '__main__':
    main("temp.woff", "temp.ttf")
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/950273.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号