PageRenderTime 83ms CodeModel.GetById 7ms app.highlight 64ms RepoModel.GetById 8ms app.codeStats 0ms

/lib/DDG/Spice/ESPN/Racing.pm

https://github.com/robertbrook/zeroclickinfo-spice
Perl | 201 lines | 189 code | 9 blank | 3 comment | 3 complexity | 2b7d97e3caae262b3189bc8aeac33968 MD5 | raw file
  1package DDG::Spice::ESPN::Racing;
  2
  3use DDG::Spice;
  4use Time::localtime;
  5
  6description "News and stats for racing players";
  7name "ESPN Racing";
  8primary_example_queries "Kyle Busch", "Brad Keselowski";
  9topics "entertainment", "special_interest";
 10category "reference";
 11code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/ESPN/Racing.pm";
 12attribution web => ['http://duckduckgo.com', 'DuckDuckGo'],
 13            twitter => ['http://twitter.com/duckduckgo', 'duckduckgo'];
 14
 15my %leagues = (
 16    nationwide => {
 17        "justin allgaier" => 731,
 18        "aj allmendinger" => 805,
 19        "aric almirola" => 740,
 20        "marcos ambrose" => 803,
 21        "john andretti" => 89,
 22        "tim andrews" => 4352,
 23        "michael annett" => 4323,
 24        "dakoda armstrong" => 4492,
 25        "casey atwood" => 170,
 26        "stanton barrett" => 617,
 27        "trevor bayne" => 4343,
 28        "t.j. bell" => 735,
 29        "tanner berryhill" => 4532,
 30        "greg biffle" => 221,
 31        "ryan blaney" => 4531,
 32        "mike bliss" => 144,
 33        "juan carlos blum" => 4558,
 34        "jason bowles" => 4391,
 35        "alex bowman" => 4555,
 36        "chris buescher" => 4480,
 37        "james buescher" => 4309,
 38        "jeb burton" => 4527,
 39        "kurt busch" => 195,
 40        "kyle busch" => 580,
 41        "brett butler" => 4346,
 42        "ken butler" => 891,
 43        "landon cassill" => 904,
 44        "jeremy clements" => 4284,
 45        "jennifer jo cobb" => 693,
 46        "brad coleman" => 823,
 47        "chris cook" => 702,
 48        "derrike cope" => 95,
 49        "joey coulter" => 4465,
 50        "tim cowen" => 871,
 51        "matt crafton" => 486,
 52        "erin crocker" => 754,
 53        "alx danielsson" => 4599,
 54        "matt dibenedetto" => 4379,
 55        "jamie dick" => 3639,
 56        "justin diercks" => 815,
 57        "austin dillon" => 4332,
 58        "ty dillon" => 4511,
 59        "tomy drissi" => 4447,
 60        "maryeve dufault" => 4503,
 61        "t.j. duke" => 4514,
 62        "jeffrey earnhardt" => 4356,
 63        "dale earnhardt jr." => 150,
 64        "danny efland" => 897,
 65        "ricky ehrgott" => 4594,
 66        "ryan ellis" => 4538,
 67        "ron fellows" => 141,
 68        "kyle fowler" => 4525,
 69        "anthony gandon" => 4598,
 70        "joey gase" => 4498,
 71        "brendan gaughan" => 235,
 72        "bobby gerhart" => 162,
 73        "ryan gifford" => 4592,
 74        "robby gordon" => 102,
 75        "david green" => 98,
 76        "jeff green" => 104,
 77        "kenny habul" => 4537,
 78        "chad hackenbracht" => 4582,
 79        "bobby hamilton jr." => 590,
 80        "mike harmon" => 174,
 81        "daryl harr" => 4353,
 82        "paulie harraka" => 4448,
 83        "richard harriman" => 4366,
 84        "kevin harvick" => 225,
 85        "drew herring" => 4435,
 86        "sam hornish jr." => 607,
 87        "shane huffman" => 411,
 88        "billy johnson" => 4437,
 89        "jimmie johnson" => 227,
 90        "kasey kahne" => 429,
 91        "kyle kelley" => 4422,
 92        "owen kelly" => 4419,
 93        "alex kennedy" => 4418,
 94        "d.j. kennington" => 844,
 95        "matt kenseth" => 143,
 96        "brad keselowski" => 626,
 97        "kraig kinser" => 773,
 98        "parker kligerman" => 4377,
 99        "todd kluever" => 698,
100        "blake koch" => 4381,
101        "kyle krisiloff" => 732,
102        "scott lagasse jr." => 718,
103        "kyle larson" => 4539,
104        "jason leffler" => 229,
105        "kevin lepage" => 130,
106        "ashton lewis jr." => 287,
107        "joey logano" => 4319,
108        "carl long" => 161,
109        "johanna long" => 4432,
110        "hal martin" => 4360,
111        "mark martin" => 68,
112        "eric mcclure" => 629,
113        "michael mcdowell" => 4286,
114        "jamie mcmurray" => 223,
115        "casey mears" => 248,
116        "paul menard" => 575,
117        "chase miller" => 840,
118        "juan pablo montoya" => 336,
119        "joe nemechek" => 97,
120        "donnie neuenberger" => 473,
121        "johnny o'connell" => 4583,
122        "johnny oconnell" => 4583,
123        "kevin o'connell" => 4312,
124        "kevin oconnell" => 4312,
125        "max papis" => 48,
126        "travis pastrana" => 4468,
127        "danica patrick" => 697,
128        "nelson piquet jr." => 867,
129        "ryan preece" => 4585,
130        "david ragan" => 649,
131        "tony raines" => 173,
132        "andrew ranger" => 809,
133        "ryan reed" => 4559,
134        "harrison rhodes" => 4564,
135        "robert richardson jr." => 757,
136        "scott riggs" => 430,
137        "martin roy" => 4602,
138        "elliott sadler" => 137,
139        "jay sauter" => 163,
140        "johnny sauter" => 414,
141        "travis sauter" => 4593,
142        "tim schendel" => 661,
143        "brian scott" => 4281,
144        "morgan shepherd" => 100,
145        "brent sherman" => 764,
146        "ryan sieg" => 4345,
147        "bryan silas" => 884,
148        "regan smith" => 478,
149        "reed sorenson" => 755,
150        "dexter stacey" => 4550,
151        "david starr" => 272,
152        "tony stewart" => 149,
153        "brad sweet" => 4388,
154        "kevin swindell" => 4423,
155        "brad teague" => 186,
156        "derek thorn" => 4578,
157        "john wes townley" => 4317,
158        "martin truex jr." => 416,
159        "brian vickers" => 390,
160        "jacques villeneuve" => 295,
161        "kenny wallace" => 90,
162        "mike wallace" => 109,
163        "steve wallace" => 761,
164        "derek white" => 4385,
165        "jason white" => 444,
166        "cole whitt" => 4463,
167        "scott wimmer" => 230,
168        "josh wise" => 885,
169        "jon wood" => 463,
170        "j.j. yeley" => 669,
171        "john young" => 855,
172    }
173);
174
175# Transform %leagues into player => { league => "league_name", id => id_number }
176# to keep %leagues in a friendly/dry form, but keep fast lookups. This only
177# executes once.
178my %players;
179for my $league (keys %leagues) {
180    for my $player (keys %{$leagues{$league}}) {
181        $players{$player} = +{
182            id => $leagues{$league}{$player},
183            league => $league,
184        };
185    }
186}
187
188triggers any => keys %players;
189
190spice to => 'http://api.espn.com/v1/sports/racing/$1/$2/$3/$4'
191            . '?enable=stats,competitors,roster,venues&$5='
192            . (localtime->year() + 1900)
193            . '&apikey={{ENV{DDG_SPICE_ESPN_APIKEY}}}&callback=$6';
194
195spice from => '(.*)/(.*)/(.*)/(.*)/(.*)/(.*)';
196
197handle query_lc => sub {
198    return $players{$_}{league}, "athletes", $players{$_}{id}, "foo", "bar", "ddg_spice_espn";
199};
200
2011;