コンテンツにスキップ

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

利用者:素手/柔道Bot

#coding:utf-8
from urllib import urlopen
import re
import linecache
import sqlite3
import func

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

kanaName = "ディミトリ・ドラジャン" # 外国人はカタカナ、漢字圏は漢字
judoInsideUrl = "http://www.judoinside.com/uk/?factfile/view/18865/dimitri_dragin"

j = urlopen(judoInsideUrl).readlines()
i = 1
tes = 1
sex = "男子"
results = []
try:
	for a in j:
		#yahoo.writelines(a+"○")
		if re.search("<title>",a): #ラテン文字名前を取得
			laname = a.replace(" - JudoInside.com","")
			laname = laname.replace("<title>","")
			laname = laname.replace("</title>","")
			laname = laname.strip()
			print "名前:"+laname
			
		#国籍取得
		if re.search("Nationality:",a):
			national = a[-15:-12]
			print "代表国:"+national
		if re.search("/lib/img/factfile/w.gif",a):
			sex = "女子"
			print "性別:"+sex
		if re.search("years",a):
			birth = a
			birth = birth.split()
			if birth[0][0] == "0":
				print "誕生日0でーす"
				birth[0] = birth[0][1]
			print "生年月日:"+birth[2]+"年"+func.monthChange(birth[1])+"月"+birth[0]+"日"
		if re.search("Olympic medals:",a):
			oMedals = [func.medalCut(a)[1], func.medalCut(a)[2] ,func.medalCut(a)[3]]
			print oMedals[:]
		if re.search("World Championships medals:",a):
			wMedals = [func.medalCut(a)[1], func.medalCut(a)[2] ,func.medalCut(a)[3]]
			print wMedals[:]
		if re.search("Continental medals:",a):
			cMedals = [func.medalCut(a)[1], func.medalCut(a)[2] ,func.medalCut(a)[3]]
			print cMedals[:]
		if re.search("World Cup/Grand Prix/Grand Slam:",a):
			gMedals = [func.medalCut(a)[1], func.medalCut(a)[2] ,func.medalCut(a)[3]]
			print gMedals[:]
		if re.search("National Ch. medals:",a):
			nMedals = [func.medalCut(a)[1], func.medalCut(a)[2] ,func.medalCut(a)[3]]
			print nMedals[:]
		if re.search("</td><td>\d</td><td><a class=\"black none\" href=\"\?factfile/tournament/",a):
			funcResults = a.strip()
			funcResults = funcResults.split("</td>")
			del  funcResults[5]
			funcResults[0] = funcResults[0].replace("<tr><td>","")
			funcResults[1] = funcResults[1].replace("<td>","")
			funcResults[4] = funcResults[4].replace("<td>","")
			funcResults[2] = funcResults[2].replace("<td><a class=\"black none\" href=\"?factfile/tournament/","")
			funcResults[2] = funcResults[2].replace("</a>","")
			b = funcResults[2][0:funcResults[2].index(">")+1]
			print b
			funcResults[2] = funcResults[2].replace(b,"")
			b = funcResults[3][0:funcResults[3].index(">")+1]
			funcResults[3] = funcResults[3].replace(b,"")
			
			funcResults[1] = funcResults[1]+"位"
			
			#階級にUが含まれていれば以下級に変更。含まれていなければ超級に変更
			if re.search("open",funcResults[4]):
				funcResults[4] = "無差別級"
			elif re.search("U",funcResults[4]):
				funcResults[4] = funcResults[4].replace("U","")
				funcResults[4] = funcResults[4]+"kg級"
			elif re.search("O",funcResults[4]):
				funcResults[4] = funcResults[4].replace("O","")
				funcResults[4] = funcResults[4]+"kg超級"
			date = funcResults[0].split("-")
			try:
				date[1] = "[["+func.monthChange(date[1])+"月"
			except IndexError:
				print "Oops"
			
			try:
				if date[0][0] == "0":
					print "0でーす"
					date[0] = date[0][1]
				date[0] = date[0]+"日]]"
			except IndexError:
				print "Oops"
			try:
				date[2] = "[["+date[2]+"年]]"
			except IndexError:
				print "Oops"
			try:
				funcResults[0] = date[2]+date[1]+date[0]
			except IndexError:
				print "Oops"
			
			results.append(funcResults)
			tes += 1
finally:
	print "終わり"
	
flagdata = open("fragdata.txt","r")
f = flagdata.readlines()

#国籍テンプレをフルテキストに変換
for a in f:
	if re.search(national,a):
		fullNational = a[4:].rstrip()

#戦績取得



yahoo.write("{{柔道家\n")
yahoo.write("<!-- 基本情報 -->\n")
yahoo.write("| 名前                  = "+kanaName+"\n")
yahoo.write("| ラテン文字            = "+laname+"\n")
yahoo.write("| 画像                  = \n")
yahoo.write("| キャプション          = \n")
yahoo.write("| 代表国                = {{"+national+"}}\n")
yahoo.write("| 生年月日              = {{生年月日と年齢|"+birth[2]+"|"+func.monthChange(birth[1])+"|"+birth[0]+"}}\n")
yahoo.write("| 没年月日              = \n")
yahoo.write("| 出生地                = \n")
yahoo.write("| 原語表記              = \n")
yahoo.write("| 愛称                  = \n")
yahoo.write("| 身長                  = \n")
yahoo.write("| 性別                  = "+sex[0:2]+"\n")
yahoo.write("| 階級                  = "+results[0][4]+"\n")
yahoo.write("| 所属                  = \n")
yahoo.write("| 段位                  = \n")
yahoo.write("| 引退                  = \n")
yahoo.write("| JudoInsideURL         = "+judoInsideUrl+"\n")
yahoo.write("<!--獲得メダル -->\n")
yahoo.write("| 五輪金                = ")
if oMedals[0] != "0":
	yahoo.write(oMedals[0]+"\n")
else:
	yahoo.write("\n")
yahoo.write("| 五輪銀                = ")
if oMedals[1] != "0":
	yahoo.write(oMedals[1]+"\n")
else:
	yahoo.write("\n")
yahoo.write("| 五輪銅                = ")
if oMedals[2] != "0":
	yahoo.write(oMedals[2]+"\n")
else:
	yahoo.write("\n")
yahoo.write("| 世界選手権金          = ")
if wMedals[0] != "0":
	yahoo.write(wMedals[0]+"\n")
else:
	yahoo.write("\n")
yahoo.write("| 世界選手権銀          = ")
if wMedals[1] != "0":
	yahoo.write(wMedals[1]+"\n")
else:
	yahoo.write("\n")
yahoo.write("| 世界選手権銅          = ")
if wMedals[2] != "0":
	yahoo.write(wMedals[2]+"\n")
else:
	yahoo.write("\n")
yahoo.write("| ワールドマスターズ金  = \n")
yahoo.write("| ワールドマスターズ銀  = \n")
yahoo.write("| ワールドマスターズ銅  = \n")
yahoo.write("| グランプリシリーズ金  = ")
if gMedals[0] != "0":
	yahoo.write(gMedals[0]+"\n")
else:
	yahoo.write("\n")
yahoo.write("| グランプリシリーズ銀  = ")
if gMedals[1] != "0":
	yahoo.write(gMedals[1]+"\n")
else:
	yahoo.write("\n")
yahoo.write("| グランプリシリーズ銅  = ")
if gMedals[2] != "0":
	yahoo.write(gMedals[2]+"\n")
else:
	yahoo.write("\n")
yahoo.write("| 大陸選手権大会金      = ")
if cMedals[0] != "0":
	yahoo.write(cMedals[0]+"\n")
else:
	yahoo.write("\n")
yahoo.write("| 大陸選手権大会銀      = ")
if cMedals[1] != "0":
	yahoo.write(cMedals[1]+"\n")
else:
	yahoo.write("\n")
yahoo.write("| 大陸選手権大会銅      = ")
if cMedals[2] != "0":
	yahoo.write(cMedals[2]+"\n")
else:
	yahoo.write("\n")
yahoo.write("| 国内選手権大会金      = ")
if nMedals[0] != "0":
	yahoo.write(nMedals[0]+"\n")
else:
	yahoo.write("\n")
yahoo.write("| 国内選手権大会銀      = ")
if nMedals[1] != "0":
	yahoo.write(nMedals[1]+"\n")
else:
	yahoo.write("\n")
yahoo.write("| 国内選手権大会銅      = ")
if nMedals[2] != "0":
	yahoo.write(nMedals[2]+"\n")
else:
	yahoo.write("\n")
yahoo.write("}}\n")
yahoo.write("'''"+kanaName+"'''({{Lang-la|"+laname+"}}、[["+birth[2]+"年]][["+func.monthChange(birth[1])+"月"+birth[0]+"日]] - )は[["+fullNational+"]]の"+sex+"[[柔道家]]。\n\n")
yahoo.write("==来歴==\n{{節stub}}\n\n")
yahoo.write("==戦績==\n{|class=\"wikitable\"\n|-\n!日付!!大会!!階級!!順位\n|-\n")
a = 0

try:
	for i in results[:]:
		yahoo.write("|"+results[a][0]+"||"+results[a][2]+"||"+results[a][4]+"||"+results[a][1]+"\n|-\n")
		a += 1
except IndexError:
	print "Oops"
	
yahoo.write("|}\n")
yahoo.write("[[Category:"+birth[2]+"年生]]\n")
yahoo.write("[[Category:存命人物]]\n")
yahoo.write("[[Category:"+fullNational+"の柔道家]]\n")
yahoo.write("{{Judo-stub}}\n")
yahoo.write("{{DEFAULTSORT: }}\n\n")
yahoo.write("[[en:"+laname+"]]")
print "完了"