def upfishinfo(filename): # filename = "F:/htmls/fish_area/" + spotid html = fishinfo.readfile(filename) print(filename) bs = BeautifulSoup(html, features="lxml") ######轻重杆######## # 6 7 8 轻杆 # 9 10 重杆 # 11 12 13 鱼王杆 # tug=tree.xpath('//canvas[@class="tug_graph"]/@data-value') tug = bs.find("table", "info_section").find('tbody').findAll('tr') upsqls = [] for tr in tug: if tr: tug_time = "" tug2 = "" tugs = tr.find('canvas') fish_id = tr.find('a').get("href") fish_id = fish_id.replace("/fish/", '') leves = tr.find('td', 'text-right').findAll('img') upleve = "" for leve in leves: if leve.get('title') == '理符任务': upleve = "可" if tugs: tugs = tugs.get("data-value") tug1 = json.loads(str(tugs)) tug_time = ",".join(tug1.keys()) tuglist = [] tugset = set() for k in tug1.keys(): if tug1[k] > 0.9: tuglist.append(int(k)) for kk in tuglist: if kk <= 8 and kk >= 6: tugset.add('轻杆') elif kk <= 10 and kk >= 9: tugset.add('重杆') elif kk <= 13 and kk >= 11: tugset.add('鱼王杆') tuglist = list(tugset) tug2 = ",".join(tuglist) if upleve == '' and tug_time == '' and tug2 == '': continue else: sql = "UPDATE `ff_fish` SET `leve`='" + upleve + "',`tug_time`='" + tug_time + "',`tug`='" + tug2 + "' WHERE (`fish_id`='" + fish_id + "')" print(sql) upsqls.append(sql) fishinfo.connecttomysql(upsqls)
tug='鱼王杆' else: tug='' ############################## if hookset=='Powerful': hookset='强力提钩' elif hookset=='Precision': hookset='精准提钩' else: hookset='' ############################### # print('id:',fish_id,'name:',fish_name,'前置天气:',pW,'天气:',weather,'传承录:',folklore,'收藏品:',collectable,'鱼眼技能:',fishEyes,'提钩技能:',hookset,'杆形:',tug) # print(weather_names) sql="INSERT INTO `clock_fish` (`fish_id`, `fish_name`, `tug`, `hookset`, `collect`, `fish_eye_skill`, `folklore`, `best_catch_path`, `previous_weather`, `weather`) VALUES ('"+str(fish_id)+"', \""+str(fish_name)+"\", '"+str(tug)+"', '"+str(hookset)+"', '"+str(collectable)+"', '"+str(fishEyes)+"', '"+str(folklore)+"', '"+str(bfish)+"', '"+str(pws)+"', '"+str(ws)+"');" # fishinfo.connecttomysql(sql) sql2='' if tug!='': sql2="UPDATE `ff_fish` SET `tug`='"+str(tug)+"',`folklore`='"+str(folklore)+"', `hookset`='"+str(hookset)+"', `pweather`='"+str(pws)+"', `fish_eyes_skill`='"+str(fishEyes)+"' WHERE (`fish_name`=\""+str(fish_name)+"\")" else: sql2 = "UPDATE `ff_fish` SET `collect`='"+str(collectable)+"',`folklore`='" + str(folklore) + "', `hookset`='" + str( hookset) + "', `pweather`='" + str(pws) + "', `fish_eyes_skill`='" + str( fishEyes) + "' WHERE (`fish_name`=\"" + str(fish_name) + "\")" sqls.append(sql2) # print(sql) fishinfo.connecttomysql(sqls) '''UPDATE `ff_fish` SET `folklore`='1', `hookset`='1', `pweather`='1', `fish_eyes_skill`='1' WHERE (`fish_name`='1')'''
#用于自动更新手动更新数据 import ff14_tool_fish.fishinfo as fishinfo # 固定鱼名更新5.2鱼王 upsql = [ "UPDATE `ff_fish` SET `fish_name`='不朽巨鱼' WHERE (`fish_id`='3193')", "UPDATE `ff_fish` SET `fish_name`='白色隆索' WHERE (`fish_id`='3194')", "UPDATE `ff_fish` SET `fish_name`='仙子彩虹鳉' WHERE (`fish_id`='3196')", "UPDATE `ff_fish` SET `fish_name`='刺钉蜥蜴' WHERE (`fish_id`='3195')", "UPDATE `ff_fish` SET `fish_name`='黑色喷气乱流' WHERE (`fish_id`='3197')", "UPDATE `ff_fish` SET `fish_name`='鳍人叹息' WHERE (`fish_id`='3198')" ] fishinfo.connecttomysql(upsql)
for a in all: # print(a[3]) thr=re.sub(r'<[^>]+>',"",a[2],re.S) thr=thr.split(' ') areaname=a[1] if areaname=="Unspoiled teeming waters": areaname="未知的鱼影" elif areaname=="North Isle of Endless Summer": areaname="永夏岛北" elif areaname=="Northwest Bronze Lake": areaname="石绿湖西北岸" if "".join(thr)!='' and "".join(a)!='' and a[3]=='1': # print(ff_mapname,area,a[0],a[1],thr[0],thr[1]) sql.append("INSERT INTO `ff_fisharea` (`area_id`, `big_map_name`, `area_name`, `is_eye`, `level`, `map_name`) VALUES ('"+a[0]+"', '"+area+"', '"+areaname+"', '"+thr[1]+"', '"+thr[0]+"', '"+ff_mapname+"');") elif "".join(thr)!='' and "".join(a)!='' and a[3]=='2': sql.append("INSERT INTO `ff_fisharea` (`area_id`, `big_map_name`, `area_name`, `is_eye`, `level`, `map_name`) VALUES ('"+a[0]+"', '"+area+"', '"+areaname+"', '"+thr[1]+"', '"+thr[0]+"', '"+ff_mapname+"');") elif "".join(thr)!='' and "".join(a)!='' and a[3]=='4': sql.append("INSERT INTO `ff_fisharea` (`area_id`, `big_map_name`, `area_name`, `is_eye`, `level`, `map_name`) VALUES ('"+a[0]+"', '"+area+"', '"+areaname+"', '插鱼场', '"+thr[0]+"', '"+ff_mapname+"');") elif "".join(thr)!='' and "".join(a)!='' and a[3]=='5': sql.append("INSERT INTO `ff_fisharea` (`area_id`, `big_map_name`, `area_name`, `is_eye`, `level`, `map_name`) VALUES ('"+a[0]+"', '"+area+"', '"+areaname+"', '"+thr[1]+"', '"+thr[0]+"', '"+ff_mapname+"');") else: sql.append("INSERT INTO `ff_fisharea` (`area_id`, `big_map_name`, `area_name`, `is_eye`, `level`, `map_name`) VALUES ('"+a[0]+"', '"+area+"', '"+areaname+"', '', '', '"+ff_mapname+"');") fishinfo.connecttomysql('DELETE FROM `ff_fisharea`') fishinfo.connecttomysql(sql) # INSERT INTO `ff_fisharea` (`area_id`, `big_map_name`, `area_name`, `is_eye`, `level`, `map_name`) VALUES ('"+a[0]+"', '"+area+"', '"+a[1]+"', '"+thr[1]+"', '"+thr[0]+"', '"+ff_mapname+"');
import re import requests from pyquery import PyQuery as pq import ff14_tool_fish.fishinfo as fishinfo delsql = "DELETE FROM `ff_fishbait`" fishinfo.connecttomysql(delsql) for v in range(1, 6): url = "https://cn.ff14angler.com/?list=bait&page=" + str(v) html = requests.get(url).text html.encode('utf-8') ff = pq(html) sel = ff('ol[class=tile]').find('li').items() for i in sel: if len(i.find('a')) == 0: continue # print('%r' % i.find('a')) id = re.findall(r'<a href="/bait/(.*?)" title=".*?">', i.html()) name = i.find('a').attr('title') lv = i.find('.ilevel').text() sql = "INSERT INTO `ff_fishbait` (`bait_id`, `bait`, `level`) VALUES ('" + ''.join( id) + "', '" + name + "', '" + lv + "')" fishinfo.connecttomysql(sql) print(sql) exsql = "INSERT INTO `ff_fishbait` (`bait_id`, `bait`) VALUES ('2001', '大型叉')" fishinfo.connecttomysql(exsql) exsql2 = "INSERT INTO `ff_fishbait` (`bait_id`, `bait`) VALUES ('2002', '中型叉')" fishinfo.connecttomysql(exsql2) exsql3 = "INSERT INTO `ff_fishbait` (`bait_id`, `bait`) VALUES ('2003', '小型叉')" fishinfo.connecttomysql(exsql3)
def fishinfo_fivepointtwo(filename): # filename = "F:/htmls/fish/" + fileid html = fishinfo.readfile(filename) print(filename) bs = BeautifulSoup(html,features="lxml") headinfo = bs.find('table',class_="fish_info") fishname = headinfo.find('span',class_="name").get_text() fishid = headinfo.find('span',class_="toggle_timetable").get("data-fish") msg = headinfo.find('td',colspan="3").get_text() msg = msg.replace('\n','').replace('\t','') msg2 = headinfo.find('td',colspan="4") if msg2: msg2 = msg2.get_text() else: msg2 = "" il = re.findall('<span class="ilevel">(.*?)<span class="patch"',str(headinfo)) il = il[0].replace("\u3000","") use = bs.find("h3",id="receipe") uses = [] if use: use = use.fetchNextSiblings()[0] use = use.find_all('img',class_="icon") for u in use: # print(u.get('src')) if u.get('src') == '/img/i_relavant007.png': uses.append("炼金") if u.get('src') == '/img/i_relavant008.png': uses.append("食材") use = ",".join(uses) version = headinfo.find('span',class_="patch").get('patch') weather = bs.find('tbody',class_="graph") weathers = [] if weather: weather = weather.findAll('img') for wt in weather: weathers.append(wt.get('title')) weather = ",".join(weathers) else: weather = "" leve = bs.find('h3',id="leve") if leve: leve="可" else: leve="" time = bs.find('tr',class_="graph").findAll('td') times = [] for td in time: if td.find('div'): # print(td.find('label').get_text()) times.append(td.find('label').get_text()) if len(times) == 24 : time = "无时间限制" else: time = '有时限,有效时间为:' + fishinfo.timearea(times) plus = headinfo.find('div',class_="fancy info_icon_area") gyotaku = plus.find('a') if gyotaku: gyotaku = gyotaku.get('data-text') else: gyotaku = "" doubleHooking = "" aquarium = "" if plus.find('span'): tmp = plus.find_all('span') for t in tmp: t1 = t.find('img').get('src') if t1 == "/img/double_hooking.png": doubleHooking = t.get('data-text') if t1.startswith('/img/aquarium'): aquarium = t.get('data-text') king = fishinfo.is_king(int(fishid)) #######选饵####### pat2 = '<form action="" method="post" name="bait_delete">.*?<tbody>(.*?)</tbody>.*?</form>' res1 = re.findall(pat2, html, re.S) pat1 = '<td><label>(.*?)</label></td>.*?<img src="/img/icon/(.*?).png"></span>(.*?)</a>(.*?)</td>' pat3 = '<td><label>(.*?)</label></td>.*?<a href="/bait/(.*?)">.*?</span>(.*?)</a>(.*?)</td>' html2 = "".join(res1) res2 = re.findall(pat1, html2, re.S) res3 = re.findall(pat3, html2, re.S) upsqls = [] fish_bait = [] if res3: for x in res3: fb = f_b() fb.bid = x[1] fb.bname = re.sub(r'<[^>]+>', "", x[2], re.S) fb.fid = fishid fb.fname = fishname fb.gl = x[0] if x[3]: bei_smalltobig = x[3] + "by" + re.sub(r'<[^>]+>', "", x[2], re.S) updatesql = "UPDATE `ff_fish` SET `is_small_to_big`='" + x[3] + "' WHERE (`fish_id`='" + x[1] + "');" upsqls.append(updatesql) fb.stob = x[3] # print(fb) sql2 = "INSERT INTO `ff_bait_fish` (`fish_id`, `fishname`, `bait_id`, `baitname`, `probability`, `is_small_to_big`) VALUES ('" + fb.fid + "', \"" + fb.fname + "\", '" + fb.bid + "', \"" + fb.bname + "\", '" + fb.gl + "', '" + fb.stob + "');" fish_bait.append(sql2) # print("起钓概率:",x[0],"鱼饵id:",x[1],"鱼饵:",re.sub(r'<[^>]+>',"",x[2],re.S),"是否以小钓大:",x[3]) else: for x in res2: fb = f_b() fb.bname = re.sub(r'<[^>]+>', "", x[2], re.S) fb.fid = fishid fb.fname = fishname fb.gl = x[0] # print(fb) sql2 = "INSERT INTO `ff_bait_fish` (`fish_id`, `fishname`, `bait_id`, `baitname`, `probability`, `is_small_to_big`) VALUES ('" + fb.fid + "', \"" + fb.fname + "\", '" + fb.bid + "', \"" + fb.bname + "\", '" + fb.gl + "', '" + fb.stob + "');" fish_bait.append(sql2) # print("起钓概率:",x[0],"鱼叉:",re.sub(r'<[^>]+>',"",x[2],re.S),"是否以小钓大:",x[3]) fishinfo.connecttomysql(upsqls) #更新以小钓大数据 # fishinfo.connecttomysql(fish_bait) #更新鱼与鱼饵关系 # sql = "INSERT INTO `ff_fish` " \ # "(`fish_id`, `fish_name`, `msg`, `msg2`, `is_small_to_big`, `IL`, `use`, `version`, `weather`, `collect`, `leve`, `time`, `gyotaku`, `double_hooking`) VALUES" \ # " ('"+fishid+"', '"+fishname+"', '"+msg+"', '"+msg2+"', '', '"+il+"', '"+use+"', '"+version+"', '"+weather+"', '', '"+leve+"', '"+time+"', '"+gyotaku+"', '"+doubleHooking+"')" sql = "INSERT INTO `ff_fish` " \ "(`fish_id`, `fish_name`, `msg`, `msg2`, `is_small_to_big`, `IL`, `use`, `version`, `weather`, `collect`, `leve`, `time`, `gyotaku`, `double_hooking` , `is_king` , `aquarium`) VALUES" \ " ('%s', \"%s\", \"%s\", \"%s\", '', '%s', '%s', '%s', '%s', '', '%s', '%s', '%s', '%s', '%s', '%s')" %\ (fishid,fishname,msg,msg2,il,use,version,weather,leve,time,gyotaku,doubleHooking,king,aquarium) return sql