# -*- encoding: utf-8 -*-import reimport sysimport MySQLdb# db = MySQLdb.connection import json reload(sys)sys.setdefaultencoding("utf-8") keyword = {} for line in open(‘keyword.txt‘, ‘r‘): datas = line.strip().split(‘:‘) keyword[datas[0].decode(‘utf8‘)] = int(datas[1]) def Score(title=‘‘): score = 0 for key in keyword.keys(): # print key.decode(‘utf8‘) if title.find(key) >= 0: score = max(score, keyword[key]) return score for line in open(‘chuli_chulihou.txt‘, ‘r‘): line = line.strip().decode(‘utf8‘) score = Score(line) print score lines = line.strip().encode(‘gbk‘, ‘ignore‘).replace(‘\u1edd‘, ‘‘).split(‘:‘) a = lines[1] print a # b = str(score)+":"+a+"\n" # f = open(u‘chuli_chulihou.txt‘, ‘a+‘) # f.write(b) # f.close() keyword.txt:
JQK:1生存战争:187红楼梦:3河马:1SL-i联赛:1史努比:3勒索:1宋智孝:44878小D:1papi酱:3BIGBANG:1倚天屠龙记:3克鲁伊夫的神迹:1取款机:1累了醉了就想哭:1波峰中学:1杀手:1郭麒麟:4闫鹤翔:4牛魔:1郑元畅:4林依晨:5
chuli_chulihou.txt
2:小伙子在河边发现一台拖拉机铲车,直接开着挖沙子去了2:男子带着桑塔纳换的观音拿去鉴宝,专家鉴定后可以直接换新车!5:YY小虾米-《闯天涯》唱的极好听4:沈腾挑衅东北老娘们太逗了!1:真实婚礼5:猫和老鼠真实版5:王者荣耀秒会露娜无限连招奥秘光速上钻石5:东北一家人最动人的地方,一家人总是坐在一起吃饭拌嘴,其乐融融3:解说若枫梦三国希望乱迷魂劣势路祝融未曾见过5:这部豆瓣超高分7.9分高智商犯罪大片,你绝对猜不到结局!0:一首特别好听的歌曲,特别适合晚上听
时间: 2024-10-13 19:28:57