コンテンツにスキップ

英文维基 | 中文维基 | 日文维基 | 草榴社区

利用者:素手/BCリーグBot

#coding:utf-8
from urllib import urlopen
import re
import linecache
import wikipedia
import math

"""バグ情報
平泉 悠
外人選手
陽介
上田 真幸
山﨑 大志
"""



#小数を四捨五入し3ケタ未満なら0を追加
def shosu(f):
	fr = str(round(f,3))
	
	if len(fr) == 3:
		fr = fr+"00"
	if len(fr) == 4:
		fr = fr+"0"
	
	if fr[0] == "0":
		return fr[1:]
	else:
		return fr

def templateTeamLink(team):
	if team == "新潟":
		return "新潟アルビレックス・ベースボール・クラブ|新潟"
	if team == "石川":
		return "石川ミリオンスターズ|石川"
	if team == "富山":
		return "富山サンダーバーズ|富山"
	if team == "福井":
		return "福井ミラクルエレファンツ|福井"
	if team == "群馬":
		return "群馬ダイヤモンドペガサス"
	if team == "信濃":
		return "信濃グランセローズ|信濃"

def defaultsort(furi):
	furi = furi.replace("が", "か")
	furi = furi.replace("ぎ","き")
	furi = furi.replace("ぐ","く")
	furi = furi.replace("げ","け")
	furi = furi.replace("ご","こ")
	furi = furi.replace("ざ","さ")
	furi = furi.replace("じ","し")
	furi = furi.replace("ず","す")
	furi = furi.replace("ぜ","せ")
	furi = furi.replace("ぞ","そ")
	furi = furi.replace("だ","た")
	furi = furi.replace("ぢ","ち")
	furi = furi.replace("づ","つ")
	furi = furi.replace("で","て")
	furi = furi.replace("ど","と")
	furi = furi.replace("ば","は")
	furi = furi.replace("び","ひ")
	furi = furi.replace("ぶ","ふ")
	furi = furi.replace("べ","へ")
	furi = furi.replace("ぼ","ほ")
	furi = furi.replace("ぱ","は")
	furi = furi.replace("ぴ","ひ")
	furi = furi.replace("ぷ","ふ")
	furi = furi.replace("ぺ","へ")
	furi = furi.replace("ぽ","ほ")
	furi = furi.replace("ゃ","や")
	furi = furi.replace("ゅ","ゆ")
	furi = furi.replace("ょ","よ")
	return furi

yahoo = open("yahoo.txt","w")

playerName = "友哉" # 全角スペース
nick = "" #登録名の選手のみ登録名の読み
DefaulltSort = "ともや" #デフォルトソートを記入
baseUrl = "http://www.bc-l.jp/team/shinano/catcher.html"
shubi = "捕手"
club = "信濃グランセローズ"

j = urlopen(baseUrl).readlines()
num = 0
job = -1
realname = "hello"
realfuri = -1
try:
	for a in j:
		if re.search(playerName+"<span>",a) or re.search(playerName+"]<span>",a) or re.search(playerName+"]<span",a):
			r = a
			furigana = a
			furigana = furigana.replace(playerName,"").replace("<span>","").replace("</span>","").replace(" "," ")[2:-3]
			print "ふりがな=",furigana
			print r
			
			if r.find("[") != -1:
				print "1見つかったで~~~~~~~"
				r = r[r.find("[")+2:r.find("]")]
				realname = r
				print "本名=",realname
				realfuri = furigana
			elif r.find("[") != -1:
				print "2見つかったで~~~~~~~"
				r = r[r.find("[")+1:r.find("]")]
				realname = r
				print "本名=",realname
				realfuri = furigana
				
			if furigana.find("(") != -1:
				print "みつこうたで"
				realfuri = furigana[furigana.find("(")+2:]
			print "ふりがな",furigana
			for b in j[num:]:
				if re.search("背番号",b):
					sebango = j[num+1]
					sebango = sebango[16:-6]
					print sebango
				if re.search("出身地",b):
					from1 = j[num+1]
					from1 = from1[16:-6]
					print from1
				if re.search("<th scope=\"col\">生年月日",b):
					birth = j[num+1]
					birth = birth[4:-12]
					birth = birth.split("/")
					
					year = birth[0]
					year = year+"年"
					
					month = birth[1]
					month = month.replace("/","")
					if month[0] == "0":
						month = month[1]
					month = month+"月"
					
					day = birth[2]
					if day[0] == "0":
						day = day[1]
					day = day+"日"
					print year+month+day
					
				if re.search("身長・体重",b):
					hw = j[num+1]
					hw = hw[4:-6]
					hw = hw.split("・")
					
					height = hw[0]
					height = height[:-2]
					print height
					
					weight = hw[1]
					weight = weight[:-2]
					print weight
				
				if re.search("<th scope=\"col\">投打",b):
					kikiude = j[num+1]
					kikinage = kikiude[4:6]
					print kikinage
					kikiuchi = kikiude[10:12]
					print kikiuchi
				if re.search("高校</th",b):
					hs = j[num+1]
					hs = hs[4:-6]
					hs = hs.replace("高校","高等学校")
					print hs
				if re.search("大学・専門学校</th>",b):
					un = j[num+1]
					un = un[4:-6]
					print un
				if re.search("社会人</th>",b):
					job = j[num+1]
					job = job[16:-6]
					job = job.split("→")
					print job
					break
				num += 1
		#		print "hello1"
		#	print "hello"
		num += 1
		#print "hello2"
		if job != -1:
			break
except IOError:
	num += 1

try:
	
	
	bc = ["0","1","2"]
	bc[0] = open("bc2007_b.txt","r")
	bc[1] = open("bc2008_b.txt","r")
	bc[2] = open("bc2009_b.txt","r")
	
	templateCheck = 0
	baseyear = 2007
	tsusan = 0
	tr = range(20)
	che = 0
	for a in tr:
		tr[che] = 0
		che += 1
	tavr = 0.00
	tdaseki = 0
	truida = 0
	nyudan = 2010
	rw1 = []
	rw2 = []
	rw3 = []
	rwcheck = 0
	tsusanCheck = 0
	cteam = "null"
	checknum = 0
	for i in bc:
		text = i.readlines()
		
		for t in text:
			if re.search(playerName.replace(" "," "),t):
				results = t.split("\t")
				print results[4:]
				daseki = int(results[6])+int(results[14])+int(results[15])+int(results[16])+int(results[17])
				ruida = int(results[8])+int(results[9])+int(results[10])*2+int(results[11])*3
				
				#出塁率
				obp = (float(results[8])+float(results[14])+float(results[15])) / (float(results[6])+float(results[14])+float(results[15])+float(results[17]))
				#長打率
				sp = float(ruida / float(results[6]))
				ops = obp + sp
				
				
				print ruida
				print int(results[6])
				print "長打率",sp
				print "ops",ops
				rw1.append("|-\n|style=\"text-align:center\"|{{by2|"+str(baseyear)+"}}\n")
				if nyudan == 2010:
					nyudan = baseyear
				
				if cteam == results[0]:
					rw2[tsusanCheck] = "|style=\"text-align:center\" rowspan=\""+str(tsusan+1)+"\"|[["+templateTeamLink(results[0])+"]]\n"
					rw2.append("<!--Bot Create-->\n")
					print "一致"
				
				else:
					rw2.append("|style=\"text-align:center\"|[["+results[0]+"]]\n")
					print "不一致"
				cteam = results[0]
				print "cteam",cteam
				
				
				
				rw3.append("||"+results[5]+"||"+str(daseki)+"||"+results[6]+"||"+results[7]+"||"+results[8]+"||"+results[9]+"||"+results[10]+"||"+results[11]+"||"+str(ruida)+"||"+results[6]+"||"	+results[18]+"||||"+results[16]+"||"+results[17]+"||"+results[14]+"||||"+results[15]+"||"+results[13]+"||"+results[19]+"||"+results[4]+"||"+shosu(obp)+"||"+shosu(sp)+"||"+shosu(ops)+"\n")
				
				tsusan += 1
				trnum = 4
				print str(tsusan)+"回目通算"
				for i in tr[4:]:
					tr[trnum] += float(results[trnum])
					trnum += 1
				print "通算",tr[4:]
				tdaseki += daseki
				truida += ruida
		baseyear += 1
	tavr = float(tr[8]) / float(tr[6])
	print "通算打率",tavr
	
	tobp = (float(tr[8])+float(tr[14])+float(tr[15])) / (float(tr[6])+float(tr[14])+float(tr[15])+float(tr[17]))
	print "通算出塁率",tobp
	
	tsp = float(truida) / float(tr[6])
	print "通算長打率",tsp
	
	tops = tobp + tsp
	print "通算OPS",tops
	
	
	tra = 0
	for i in tr:
		tr[tra] = int(tr[tra])
		tra += 1
	
	yahoo.write("{{Infobox baseball player\n")
	yahoo.write("|選手名 = "+playerName.replace(" "," ")+"\n")
	
	if realname != "hello":
		yahoo.write("|本名 = "+realname+"\n")
	yahoo.write("|所属球団 = "+club+"\n")
	yahoo.write("|背番号 = "+sebango+"\n")
	yahoo.write("|国籍 = {{JPN}}\n")
	yahoo.write("|出身地 = {{Flagicon|JPN}} [["+from1+"]]\n")
	yahoo.write("|生年月日 = {{生年月日と年齢|"+year[:-2]+"|"+month[:-2]+"|"+day[:-2]+"}}\n")
	yahoo.write("|没年月日 = \n")
	yahoo.write("|身長 = "+height+"\n")
	yahoo.write("|体重 = "+weight+"\n")
	yahoo.write("|利き腕 = "+kikinage+"\n")
	yahoo.write("|打席 = "+kikiuchi+"\n")
	yahoo.write("|守備位置 = "+shubi+"\n")
	yahoo.write("|プロ入り年度 = [["+str(nyudan)+"年]]\n")
	yahoo.write("|経歴 = \n")
	if hs[0] != "-":
		yahoo.write("*[["+hs+"]]\n")
	if un[0] != "-":
		yahoo.write("*[["+un+"]]\n")
#except IndexError: #エラー時に使用
#	print "IndexError"
	
	if job[0] != "-":
		for d in job:
			yahoo.write("*[["+d+"]]\n")
	yahoo.write("*[["+club+"]]("+str(nyudan)+" - )\n")
	yahoo.write("}}\n")
	
	if realfuri == -1:
		yahoo.write("'''"+playerName.replace(" "," ")+"'''("+furigana+"、")
	else:
		yahoo.write("'''"+playerName.replace(" "," ")+"'''("+nick+"、本名:'''"+realname+"'''("+realfuri+")、")
	yahoo.write("[["+year+"]][["+month+""+day+"]] - )は[["+club+"]]に所属する[[プロ野球選手]]([["+shubi+"]])。\n\n")
	yahoo.write("==来歴==\n{{節stub}}\n\n==年度別戦績==\n\n")
	
	
	if templateCheck == 0:
		yahoo.write("{| {{年度別打撃成績|リーグ=日本プロ野球#.E7.8B.AC.E7.AB.8B.E3.83.AA.E3.83.BC.E3.82.B0}}\n")
		templateCheck = -1
	if templateCheck == -1:
		c = 0
		for i in rw1:
			yahoo.write(rw1[c])
			yahoo.write(rw2[c])
			yahoo.write(rw3[c])
			c += 1
		
		
		
		yahoo.write("|-\n!colspan=\"2\"|通算:"+str(tsusan)+"年\n")
		yahoo.write("||"+str(tr[5])+"||"+str(tdaseki)+"||"+str(tr[6])+"||"+str(tr[7])+"||"+str(tr[8])+"||"+str(tr[9])+"||"+str(tr[10])+"||"+str(tr[11])+"||"+str(truida)+"||"+str(tr[6]))
		yahoo.write("||"+str(tr[18])+"||||"+str(tr[16])+"||"+str(tr[17])+"||"+str(tr[14])+"||||"+str(tr[15])+"||"+str(tr[13])+"||"+str(tr[19])+"||"+shosu(tavr)+"||"+shosu(tobp)+"||"+shosu(tsp)+"||"+shosu(tops)+"\n|}")

except ZeroDivisionError:
	print "0で割れません"
	
	yahoo.write("{{Infobox baseball player\n")
	yahoo.write("|選手名 = "+playerName.replace(" "," ")+"\n")
	
	if realname != "hello":
		yahoo.write("|本名 = "+realname+"\n")
	yahoo.write("|所属球団 = "+club+"\n")
	yahoo.write("|背番号 = "+sebango+"\n")
	yahoo.write("|国籍 = {{JPN}}\n")
	yahoo.write("|出身地 = {{Flagicon|JPN}} [["+from1+"]]\n")
	yahoo.write("|生年月日 = {{生年月日と年齢|"+year[:-2]+"|"+month[:-2]+"|"+day[:-2]+"}}\n")
	yahoo.write("|没年月日 = \n")
	yahoo.write("|身長 = "+height+"\n")
	yahoo.write("|体重 = "+weight+"\n")
	yahoo.write("|利き腕 = "+kikinage+"\n")
	yahoo.write("|打席 = "+kikiuchi+"\n")
	yahoo.write("|守備位置 = "+shubi+"\n")
	yahoo.write("|プロ入り年度 = [["+str(nyudan)+"年]]\n")
	yahoo.write("|経歴 = \n")
	if hs[0] != "-":
		yahoo.write("*[["+hs+"]]\n")
	if un[0] != "-":
		yahoo.write("*[["+un+"]]\n")
#except IndexError: #エラー時に使用
#	print "IndexError"
	
	if job[0] != "-":
		for d in job:
			yahoo.write("*[["+d+"]]\n")
	yahoo.write("*[["+club+"]]("+str(nyudan)+" - )\n")
	yahoo.write("}}\n")
	
	if realfuri == -1:
		yahoo.write("'''"+playerName.replace(" "," ")+"'''("+furigana+"、")
	else:
		yahoo.write("'''"+playerName.replace(" "," ")+"'''("+nick+"、本名:'''"+realname+"'''("+realfuri+")、")
	yahoo.write("[["+year+"]][["+month+""+day+"]] - )は[["+club+"]]に所属する[[プロ野球選手]]([["+shubi+"]])。\n\n")
	yahoo.write("==来歴==\n{{節stub}}\n\n==年度別戦績==\n\n")

yahoo.write("\n\n===背番号===\n*'''"+sebango+"'''("+str(nyudan)+" - )")
yahoo.write("\n\n==関連項目==\n")
league = ["明石レッドソルジャーズ","石川ミリオンスターズ","愛媛マンダリンパイレーツ","大阪ゴールドビリケーンズ","香川オリーブガイナーズ","紀州レンジャーズ","高知ファイティングドッグス","神戸9クルーズ","信濃グランセローズ","徳島インディゴソックス","富山サンダーバーズ","長崎セインツ","新潟アルビレックス・ベースボール・クラブ","福井ミラクルエレファンツ","福岡レッドワーブラーズ","コリア・ヘチ","三重スリーアローズ"]
if job[0] != "-":
	for d1 in job:
		for d2 in league:
			if d2 == d1:
				yahoo.write("*[["+d1+"の選手一覧]]\n")

yahoo.write("*[["+club+"の選手一覧]]\n*[["+from1+"出身の人物一覧]]\n\n")

yahoo.write("{{Baseball-biography-stub}}\n")
yahoo.write("{{"+club+"}}\n{{DEFAULTSORT:"+defaultsort(furigana)+"}}\n\n")
yahoo.write("[[Category:日本の野球選手]]\n[[Category:"+club+"の選手]]\n")
if job[0] != "-":
	for d1 in job:
		for d2 in league:
			if d2 == d1:
				yahoo.write("[[Category:"+d1+"の選手]]\n")
yahoo.write("[[Category:"+from1+"出身の人物]]\n[[Category:"+year+"生]]\n[[Category:存命人物]]")
				
print shosu(0.4000)
print shosu(0.4837233222)