PageRenderTime 64ms CodeModel.GetById 2ms app.highlight 54ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/DDG/Spice/ESPN/Soccer.pm

https://github.com/ehsan/zeroclickinfo-spice
Perl | 537 lines | 525 code | 9 blank | 3 comment | 3 complexity | b19cf60ab4406f2d8fef07c431a031a5 MD5 | raw file
  1package DDG::Spice::ESPN::Soccer;
  2
  3use DDG::Spice;
  4use Time::localtime;
  5
  6description "News and stats for soccer players";
  7name "ESPN Soccer";
  8primary_example_queries "Wayne Rooney";
  9topics "entertainment", "special_interest";
 10category "reference";
 11code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/ESPN/ENG1.pm";
 12attribution web => ['http://duckduckgo.com', 'DuckDuckGo'],
 13            twitter => ['http://twitter.com/duckduckgo', 'duckduckgo'];
 14
 15my %leagues = (
 16    'eng.1' => {
 17        "charlie adam" => 108350,
 18        "gabriel agbonlahor" => 70428,
 19        "daniel agger" => 41844,
 20        "sergio agüero" => 44927,
 21        "chuba akpom" => 181092,
 22        "marc albrighton" => 132107,
 23        "neil alexander" => 116371,
 24        "daniel alfei" => 149395,
 25        "joe allen" => 93736,
 26        "jozy altidore" => 75589,
 27        "sone aluko" => 70615,
 28        "morgan amalfitano" => 84463,
 29        "jordi amat" => 144477,
 30        "sammy ameobi" => 158142,
 31        "shola ameobi" => 8958,
 32        "fernando amorebieta" => 50453,
 33        "ben amos" => 120863,
 34        "nicolas anelka" => 10862,
 35        "victor anichebe" => 74599,
 36        "vurnon anita" => 77226,
 37        "marko arnautovic" => 98193,
 38        "mikel arteta" => 9840,
 39        "iago aspas" => 92800,
 40        "oussama assaidi" => 140799,
 41        "daniel ayala" => 139243,
 42        "césar azpilicueta" => 97770,
 43        "demba ba" => 99215,
 44        "el-hadj ba" => 171680,
 45        "leandro bacuna" => 138664,
 46        "leighton baines" => 19952,
 47        "nathan baker" => 121171,
 48        "barry bannan" => 130079,
 49        "ross  barkley" => 152469,
 50        "gareth barry" => 8185,
 51        "sebastien bassong" => 66657,
 52        "luciano becchio" => 43673,
 53        "asmir begovic" => 92885,
 54        "craig bellamy" => 8952,
 55        "hatem ben arfa" => 43340,
 56        "nicklas bendtner" => 71647,
 57        "elliott bennett" => 105584,
 58        "joseph bennett" => 127261,
 59        "ryan bennett" => 98290,
 60        "darren bent" => 8111,
 61        "christian benteke" => 106957,
 62        "saido berahino" => 151276,
 63        "dimitar berbatov" => 12724,
 64        "paulinho" => 139718,
 65        "gael bigirimana" => 150760,
 66        "derek boateng" => 103114,
 67        "yannick bolasie" => 121921,
 68        "wilfried bony" => 153824,
 69        "willian" => 178487,
 70        "fabio borini" => 140931,
 71        "artur boruc" => 22764,
 72        "jordan bowery" => 124266,
 73        "dedryck boyata" => 143592,
 74        "george boyd" => 26378,
 75        "robert brady" => 153310,
 76        "matthew briggs" => 99497,
 77        "leon britton" => 7957,
 78        "wes brown" => 8866,
 79        "alex bruce" => 43942,
 80        "chris brunt" => 41967,
 81        "mark bunn" => 9240,
 82        "jacob butterfield" => 107609,
 83        "alexander büttner" => 124933,
 84        "yohan cabaye" => 69450,
 85        "gary cahill" => 40509,
 86        "geoff cameron" => 118125,
 87        "lee camp" => 29000,
 88        "fraizer campbell" => 42248,
 89        "jose ruiz herrera canas" => 130131,
 90        "etienne capoue" => 84892,
 91        "michael carrick" => 7971,
 92        "thomas carroll" => 155736,
 93        "kevin theopile catherine" => 129415,
 94        "lee cattermole" => 72918,
 95        "steven caulker" => 132436,
 96        "santi cazorla" => 40202,
 97        "petr cech" => 13069,
 98        "ondrej celustka" => 140953,
 99        "nacer chadli" => 122633,
100        "marouane chamakh" => 84609,
101        "callum chambers" => 176266,
102        "james chester" => 108328,
103        "vlad chiriches" => 164764,
104        "papiss demba cisse" => 101423,
105        "aly cissokho" => 92704,
106        "ciaran clark" => 129754,
107        "tom cleverley" => 108327,
108        "gaël clichy" => 35099,
109        "nathaniel clyne" => 127865,
110        "jack colback" => 123697,
111        "ashley cole" => 8054,
112        "joe cole" => 7976,
113        "seamus coleman" => 131639,
114        "james collins" => 5527,
115        "jack collison" => 105533,
116        "fabricio coloccini" => 12265,
117        "matthew connolly" => 86405,
118        "jack  cork" => 91481,
119        "andreas cornelius" => 176668,
120        "philippe coutinho" => 130372,
121        "don cowie" => 6925,
122        "peter crouch" => 5388,
123        "carlos jimenez cuellar" => 28541,
124        "fabio" => 122463,
125        "rafael" => 25409,
126        "luke daniels" => 82889,
127        "ben davies" => 6327,
128        "curtis davies" => 39488,
129        "kelvin davis" => 5278,
130        "steven davis" => 161788,
131        "craig dawson" => 133938,
132        "michael dawson" => 19812,
133        "kevin  de bruyne " => 134947,
134        "david de gea" => 108482,
135        "jonathan de guzman" => 69579,
136        "mathieu debuchy" => 69458,
137        "jermain defoe" => 7975,
138        "damien delaney" => 7875,
139        "fabian delph" => 98926,
140        "mousa dembele" => 67490,
141        "guy demel" => 84798,
142        "gerard deulofeu" => 156615,
143        "mobido diakite" => 87017,
144        "mohamed diame" => 86233,
145        "alou diarra" => 86228,
146        "kagisho dikgacoi" => 89826,
147        "sylvain distin" => 10438,
148        "guilherme do prado" => 36774,
149        "stephen dobbie" => 148773,
150        "ji dong-won" => 150375,
151        "graham dorrans" => 61892,
152        "oscar" => 173667,
153        "stewart downing" => 21187,
154        "damien duff" => 7779,
155        "paul dummett" => 167118,
156        "nathan dyer" => 67796,
157        "edin dzeko" => 102337,
158        "karim el ahmadi" => 42176,
159        "robert elliot" => 47039,
160        "johan elmander" => 14401,
161        "ahmed elmohamady" => 145468,
162        "christian eriksen" => 144130,
163        "michael essien" => 9799,
164        "neil etheridge" => 152246,
165        "matthew etherington" => 8157,
166        "samuel eto'o" => 11718,
167        "samuel etoo" => 11718,
168        "jonathan evans" => 83176,
169        "patrice evra" => 21931,
170        "lukasz fabianski" => 77403,
171        "abdoulaye faye" => 21990,
172        "marouane fellaini" => 84535,
173        "leroy fer" => 113083,
174        "rio ferdinand" => 7825,
175        "maynor figueroa" => 93156,
176        "mathieu flamini" => 40501,
177        "john flanagan" => 22992,
178        "steven fletcher" => 42189,
179        "chico" => 121595,
180        "jose fonte" => 104172,
181        "ben foster" => 22777,
182        "daniel fox" => 43922,
183        "david fox" => 29359,
184        "brad friedel" => 7777,
185        "emmanuel frimpong" => 127136,
186        "ezekiel fryers" => 167113,
187        "josé campaña" => 158259,
188        "daniel gabbidon" => 5537,
189        "javi garcia" => 68489,
190        "craig gardner" => 73339,
191        "javier garrido" => 40411,
192        "owen garvan" => 46329,
193        "dwight gayle" => 168992,
194        "steven gerrard" => 7935,
195        "rudy gestede" => 113079,
196        "emanuele giaccherini" => 134438,
197        "kieran gibbs" => 99500,
198        "darron gibson" => 71653,
199        "ryan giggs" => 8853,
200        "olivier giroud" => 88965,
201        "serge gnabry" => 178980,
202        "dan gosling" => 93325,
203        "yoan gouffran" => 101379,
204        "danny graham" => 159274,
205        "adlene guedioura" => 144515,
206        "magaye gueye" => 128904,
207        "sandro" => 147337,
208        "aron gunnarsson" => 95094,
209        "jonás gutiérrez" => 51559,
210        "brad guzan" => 56935,
211        "brede hangeland" => 13269,
212        "steve harper" => 8948,
213        "joe hart" => 30462,
214        "eden hazard" => 101390,
215        "john heitinga" => 10004,
216        "nicklas helenius" => 153920,
217        "jordan henderson" => 127262,
218        "chris herd" => 113837,
219        "javier hernández" => 146419,
220        "pablo" => 76090,
221        "lewis holtby" => 122289,
222        "jos hooiveld" => 31806,
223        "wesley hoolahan" => 16696,
224        "gary hooper" => 66564,
225        "tim howard" => 34158,
226        "jonathan howson" => 83517,
227        "tom huddlestone" => 26412,
228        "mark hudson" => 187814,
229        "aaron hughes" => 8953,
230        "robert huth" => 18891,
231        "jordan ibe" => 164646,
232        "tiago ilori" => 162945,
233        "ryan inniss" => 172971,
234        "stephen ireland" => 46525,
235        "branislav ivanovic" => 83519,
236        "jussi jaaskelainen" => 7908,
237        "phil jagielka" => 4745,
238        "eldin jakupovic" => 69318,
239        "adnan januzaj" => 186432,
240        "matthew jarvis" => 39484,
241        "mile jedinak" => 85979,
242        "nikica jelavic" => 39511,
243        "carl jenkinson" => 150844,
244        "cameron jerome" => 43465,
245        "declan john" => 133463,
246        "adam johnson" => 55814,
247        "bradley johnson" => 46275,
248        "glen johnson" => 23650,
249        "billy jones" => 38871,
250        "brad jones" => 46050,
251        "kenwyne jones" => 42600,
252        "phil jones" => 140032,
253        "stevan jovetic" => 119612,
254        "younes kaboul" => 42191,
255        "alexander kacaniklic" => 108312,
256        "shinji kagawa" => 102139,
257        "harry kane" => 142200,
258        "giorgos karagounis" => 57129,
259        "pajtim kasami" => 146384,
260        "jimmy kebe" => 86232,
261        "martin kelly" => 123515,
262        "ki sung-yueng" => 122608,
263        "kim bo-kyung" => 144004,
264        "aleksandar kolarov" => 103939,
265        "vincent kompany" => 72935,
266        "arouna koné" => 76732,
267        "robert koren" => 32704,
268        "laurent koscielny" => 88970,
269        "libor kozák" => 121399,
270        "tim krul" => 85285,
271        "adam lallana" => 85472,
272        "roland lamah" => 86389,
273        "rickie lambert" => 174560,
274        "erik lamela" => 130870,
275        "frank lampard" => 8941,
276        "sebastian larsson" => 42772,
277        "elliot lee" => 26614,
278        "lucas" => 108315,
279        "aaron lennon" => 35866,
280        "joleon lescott" => 5355,
281        "joe lewis" => 38402,
282        "anders lindegaard" => 82967,
283        "jake livermore" => 111336,
284        "hugo lloris" => 43372,
285        "shane long" => 127978,
286        "dejan lovren" => 123560,
287        "matthew lowton" => 145738,
288        "diego lugano" => 71137,
289        "david luiz" => 98398,
290        "fernandinho" => 178486,
291        "romelu lukaku" => 139437,
292        "mikael mandron" => 185462,
293        "vito mannone" => 85400,
294        "florian marange" => 84622,
295        "adrian mariappa" => 62131,
296        "david marshall" => 26672,
297        "russell martin" => 43408,
298        "sylvain marveaux" => 84929,
299        "joel mason" => 168766,
300        "juan mata" => 103025,
301        "charalampos mavrias" => 152193,
302        "nicky maynard" => 66557,
303        "emmanuel mayuka" => 178245,
304        "modibo maíga" => 101554,
305        "gareth mcauley" => 32588,
306        "james mccarthy" => 137100,
307        "george mccartney" => 8083,
308        "allan mcgregor" => 108348,
309        "paul mcshane" => 42732,
310        "gary medel" => 147341,
311        "per mertesacker" => 34041,
312        "david meyler" => 121849,
313        "simon mignolet" => 99829,
314        "james milner" => 26843,
315        "kevin mirallas" => 161664,
316        "ryo miyaichi" => 155458,
317        "david moberg-karlsson" => 188022,
318        "nacho monreal" => 85361,
319        "simon moore" => 138481,
320        "james morrison" => 39542,
321        "ravel morrison" => 153297,
322        "victor moses" => 112547,
323        "dean moxey" => 38715,
324        "youssuf mulumbu" => 88221,
325        "marc muniesa" => 135405,
326        "josh murphy" => 172838,
327        "jordon mutch" => 130912,
328        "boaz myhill" => 4680,
329        "buomesca tue na bangna" => 192786,
330        "steven naismith" => 108763,
331        "nani" => 67716,
332        "samir nasri" => 43531,
333        "matija nastasic" => 151765,
334        "kyle naughton" => 114546,
335        "jesús navas" => 37449,
336        "álvaro negredo" => 102978,
337        "mark noble" => 41421,
338        "kevin nolan" => 7902,
339        "craig noone" => 124973,
340        "steven nzonzi" => 113290,
341        "joey o'brien" => 45410,
342        "joey obrien" => 45410,
343        "stuart o'keefe" => 121880,
344        "stuart okeefe" => 121880,
345        "john o'shea" => 7624,
346        "john oshea" => 7624,
347        "gabriel obertan" => 86215,
348        "john mikel obi" => 60503,
349        "peter odemwingie" => 69453,
350        "jores okore" => 157389,
351        "anderson" => 88360,
352        "jonas olsson" => 67860,
353        "martin olsson" => 75987,
354        "leon osman" => 7709,
355        "pablo daniel osvaldo" => 104954,
356        "bryan oviedo" => 147197,
357        "alex oxlade-chamberlain" => 145392,
358        "wilson palacios" => 93145,
359        "costel pantilimon" => 126727,
360        "scott parker" => 7685,
361        "jonathan parr" => 121386,
362        "jermaine pennant" => 8047,
363        "mladen petric" => 102202,
364        "kevin phillips" => 8068,
365        "steven pienaar" => 19544,
366        "erik pieters" => 124890,
367        "anthony pilkington" => 93633,
368        "lukas podolski" => 39759,
369        "goran popov" => 43779,
370        "pozuelo" => 158604,
371        "lewis price" => 32769,
372        "nick proschwitz" => 136917,
373        "jason puncheon" => 42019,
374        "michu" => 125714,
375        "stephen quinn" => 65473,
376        "peter ramage" => 42714,
377        "gaston ramirez" => 130591,
378        "aaron ramsey" => 98681,
379        "angel rangel" => 102588,
380        "razvan dinca rat" => 19097,
381        "nathan redmond" => 146091,
382        "winston reid" => 99875,
383        "loïc remy" => 84886,
384        "ashley richards" => 132635,
385        "micah richards" => 66695,
386        "kieran richardson" => 23139,
387        "liam ridgewell" => 8175,
388        "sascha riether" => 102336,
389        "john arne riise" => 7936,
390        "valentin roberge" => 149625,
391        "joel robles" => 141624,
392        "hugo rodallega" => 131212,
393        "antonio luna " => 147501,
394        "jay rodriguez" => 100918,
395        "jack rodwell" => 112092,
396        "luis alberto" => 146388,
397        "wayne rooney" => 21046,
398        "danny rose" => 104991,
399        "markus rosenberg" => 69308,
400        "liam rosenior" => 133897,
401        "tomas rosicky" => 10726,
402        "wayne routledge" => 16155,
403        "john ruddy" => 42359,
404        "bryan ruiz" => 137779,
405        "yannick sagbo" => 120949,
406        "bacary sagna" => 38880,
407        "mamadou sakho" => 96162,
408        "adrián" => 134230,
409        "yaya sanogo" => 144279,
410        "davide santon" => 121811,
411        "ramires" => 99025,
412        "andre schürrle" => 136580,
413        "morgan schneiderlin" => 101461,
414        "mark schwarzer" => 7996,
415        "philippe senderos" => 19435,
416        "stephane sessegnon" => 85095,
417        "luke shaw" => 167127,
418        "ryan shawcross" => 89557,
419        "jonjo shelvey" => 119005,
420        "steve sidwell" => 15820,
421        "gylfi sigurdsson" => 121910,
422        "david silva" => 43815,
423        "scott sinclair" => 46565,
424        "moussa sissoko" => 104658,
425        "martin skrtel" => 45606,
426        "chris smalling" => 123605,
427        "tommy smith" => 127982,
428        "robert snodgrass" => 156085,
429        "roberto soldado" => 42042,
430        "thomas sorensen" => 8067,
431        "julian speroni" => 6721,
432        "jed steer" => 141558,
433        "maarten stekelenburg" => 11631,
434        "raheem sterling" => 156366,
435        "david stockdale" => 31378,
436        "john stones" => 157974,
437        "daniel sturridge" => 85291,
438        "luis suárez" => 125088,
439        "yacouba sylla" => 153075,
440        "wojciech szczesny" => 131634,
441        "josé enrique" => 68594,
442        "adel taarabt" => 87623,
443        "cabral" => 125941,
444        "andrew taylor" => 42349,
445        "matthew taylor" => 6136,
446        "neil taylor" => 107571,
447        "steven taylor" => 17812,
448        "john terry" => 8931,
449        "alexander tettey" => 71582,
450        "jerome thomas" => 16703,
451        "dwight tiendalli" => 46034,
452        "ismael cheik tioté" => 73076,
453        "james tomkins" => 104917,
454        "aleksandar tonev" => 149910,
455        "fernando torres" => 24257,
456        "yaya touré" => 69277,
457        "kolo touré" => 23601,
458        "andros townsend" => 132432,
459        "gerhard tremmel" => 84678,
460        "ben turner" => 77679,
461        "michael turner" => 27206,
462        "antonio valencia" => 65629,
463        "marco van ginkel" => 146519,
464        "robin van persie" => 18858,
465        "ricky van wolfswinkel" => 124932,
466        "david vaughan" => 131895,
467        "ricardo vaz te" => 101268,
468        "thomas vermaelen" => 40543,
469        "jan vertonghen" => 125086,
470        "nemanja vidic" => 24529,
471        "emiliano viviano" => 125001,
472        "ron vlaar" => 127433,
473        "michel vorm" => 19705,
474        "haris vuckic" => 130526,
475        "matej vydra" => 148624,
476        "álvaro vásquez" => 152574,
477        "theo walcott" => 67507,
478        "kyle walker" => 129358,
479        "jonathan walters" => 23770,
480        "victor wanyama" => 139703,
481        "joel ward" => 136571,
482        "james ward-prowse" => 163111,
483        "andreas weimann" => 138905,
484        "danny welbeck" => 115271,
485        "ashley westwood" => 7567,
486        "kieren westwood" => 129506,
487        "glenn whelan" => 5026,
488        "steven whittaker" => 108372,
489        "peter whittingham" => 101132,
490        "connor wickham" => 130189,
491        "aaron wilbraham" => 5176,
492        "andy wilkinson" => 15461,
493        "ashley williams" => 129481,
494        "jonathan williams" => 24675,
495        "michael williamson" => 37569,
496        "jack wilshere" => 122089,
497        "marc wilson" => 77070,
498        "andre wisdom" => 152596,
499        "claudio yacob" => 92080,
500        "mapou yanga-mbiwa" => 93313,
501        "maya yoshida" => 105803,
502        "ashley young" => 31810,
503        "pablo zabaleta" => 68058,
504        "wilfried zaha" => 146324,
505        "gideon zelalem" => 192048,
506        "elsad zverotic" => 119611,
507        "mesut özil" => 84775,
508    }
509);
510
511# Transform %leagues into player => { league => "league_name", id => id_number }
512# to keep %leagues in a friendly/dry form, but keep fast lookups. This only
513# executes once.
514my %players;
515for my $league (keys %leagues) {
516    for my $player (keys %{$leagues{$league}}) {
517        $players{$player} = +{
518            id => $leagues{$league}{$player},
519            league => $league,
520        };
521    }
522}
523
524triggers any => keys %players;
525
526spice to => 'http://api.espn.com/v1/sports/soccer/$1/$2/$3/$4'
527            . '?enable=stats,competitors,roster,venues&$5='
528            . (localtime->year() + 1900)
529            . '&apikey={{ENV{DDG_SPICE_ESPN_APIKEY}}}&callback=$6';
530
531spice from => '(.*)/(.*)/(.*)/(.*)/(.*)/(.*)';
532
533handle query_lc => sub {
534    return $players{$_}{league}, "athletes", $players{$_}{id}, "foo", "bar", "ddg_spice_espn";
535};
536
5371;