17歌词解析

class Lyric():
    @classmethod
    def load_file(cls):
        with open("./lyric.txt", "r", encoding="utf-16") as f:
            conten = f.read()
            return conten
    @classmethod
    def operation(cls, time):
        n2 = ''
        for str1 in time:
            if "0" <= str1 <= "9":
                n2 += str1
        t = int(n2) // 10000 * 60 * 100 + int(n2) // 100 % 100 * 100 + int(n2) % 100
        lylic = cls.load_file()
        ly_list = []
        for item in lylic.split():
            ly_dit = {}
            n =""
            a =""
            n1=[]
            for str1 in item:
                if "0"<=str1<="9":
                    n += str1
                    if len(n)== 6:
                        time1 =int(n)//10000*60*100+int(n)//100%100*100+int(n)%100
                        n1.append(time1)
                        n = ""
                if "一" <= str1 <= "龿":
                    a += str1
            # print(n1)
            for time in n1:
                ly_dit["time"] = time
                ly_dit["lyric"] = a
                ly_list.append(ly_dit.copy())
        # print(ly_list)
        temp = [].copy()
        for dit in ly_list:
                if dit["time"] <= t:
                    temp.append(dit)
        if len(temp):
            max_time = temp[0]["time"]
            max_dit = temp[0]
            for dit in temp:
                if dit["time"] > max_time:
                    max_time = dit["time"]
                    max_dit = dit
            return max_dit["lyric"]

if __name__ == '__main__':
    # time = input("请输入一个时间:")
    lyric = ''
    for time in range(10, 30000):
        lyric1 = Lyric.operation(str(time))
        if lyric != lyric1:
            lyric = lyric1
            print(lyric)

运行效果:
None
蓝莲花
没有什么能够阻挡
你对自由地向往
天马行空的生涯
你的心了无牵挂
穿过幽暗地岁月
也曾感到彷徨
当你低头地瞬间
才发觉脚下的路
心中那自由地世界
如此的清澈高远
盛开着永不凋零
蓝莲花
穿过幽暗地岁月
也曾感到彷徨
当你低头地瞬间
才发觉脚下的路
穿过幽暗地岁月
也曾感到彷徨
当你低头地瞬间
才发觉脚下的路
心中那自由地世界
如此的清澈高远
也曾感到彷徨
当你低头地瞬间
才发觉脚下的路
穿过幽暗地岁月
也曾感到彷徨
当你低头地瞬间
才发觉脚下的路
心中那自由地世界
如此的清澈高远
盛开着永不凋零
蓝莲花

你可能感兴趣的:(17歌词解析)