BeginPackage["Wikicode`CollegeFootball`"]
CollegeFootballData::usage = "CollegeFootballData[\"Teams\"] gives a \
list of teams.\nCollegeFootballData[team] gives a list of seasons in \
the form {year,conference,wins,losses,ties}.\n\
CollegeFootballData[team,year] gives a list of games from that year \
for that team in the form \
{date,opponent,score,opponentScore,\"Home\"|\"Away\"|\"Neutral\"}."
Teams::usage = "Teams is a list of college football teams."
Conference::usage = "Conference[team] gives the most recent \
conference in which the given team played. Conference[team,year] \
gives the conference in which the given team played for that year."
Games::usage = "Games[team,year] gives the the list of games from \
that year for that team."
Begin["`Private`"]
CollegeFootballData["Teams"] =
Cases[Import["http://www.sports-reference.com/cfb/schools",
"Data"][[2, 2]], {_Integer, ___}][[All, 2]]
CollegeFootballData[team_?TeamQ] :=
CollegeFootballData[team] =
Cases[Import[
"http://www.sports-reference.com/cfb/schools/" <>
ToLowerCase@
StringReplace[
StringReplace[team, Except[LetterCharacter | " " | "-"] -> ""],
" " .. -> "-"],
"Data"], {_Integer, year_Integer, conference_String, wins_Integer,
losses_Integer, ties_Integer, ___} -> {year, conference, wins,
losses, ties}, 4]
CollegeFootballData[team_] = Missing["NotAvailable"]
CollegeFootballData[team_?TeamQ, year_] /;
MemberQ[CollegeFootballData[team][[All, 1]], year] :=
CollegeFootballData[team, year] =
Module[{offset, venue}, {offset, venue} =
Switch[#[[5]], "@", {1, "Away"},
"N", {1, "Neutral"}, _, {0,
"Home"}]; {DateList[#[[2]]][[;; 3]],
StringTrim@
StringReplace[#[[5 + offset]],
"(" ~~ DigitCharacter .. ~~ ")" -> ""], #[[8 +
offset]], #[[9 + offset]], venue}] & /@
Cases[Import[
"http://www.sports-reference.com/cfb/schools/" <>
ToLowerCase@
StringReplace[
StringReplace[team,
Except[LetterCharacter | " " | "-"] -> ""], " " .. -> "-"] <>
"/" <> ToString@year <> "-schedule.html",
"Data"], {_Integer, _String, ___}, 3]
CollegeFootballData[team_, year_] = Missing["NotAvailable"]
Teams = CollegeFootballData["Teams"]
TeamQ[team_String] := MemberQ[CollegeFootballData["Teams"], team]
Conference[team_?TeamQ] := CollegeFootballData[team][[1, 2]]
Conference[team_?TeamQ, year_] /;
MemberQ[CollegeFootballData[team][[All, 1]], year] :=
Cases[CollegeFootballData[team], {year, __}][[1, 2]]
Conference[__] = Missing["NotAvailable"]
Games[team_?TeamQ, year_] /;
MemberQ[CollegeFootballData[team][[All, 1]], year] :=
CollegeFootballData[team, year]
End[]
EndPackage[]
References edit
"College Football". Sports Reference. Retrieved 15 August 2013.