Football Data Wrangling w/ Ruby - Match 1500+ Football Club Names from Around the World using the sportdb Library and Open football.db Datasets
Gerald Bauer <[email protected]> Fri, 2 Aug 2019 19:13:01 +0200
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <CAAxEZd9AyQbWOn-oXuEM_mC9prYX00W2g6mYQZih3YkMC=GM=Q@mail.gmail.com> |
Hello, To prepare for the 2019/2020 football season kick-off I've put together a football data wrangling w/ sample that lets you match 1500+ football club names from 100+ leagues from around the world using the sportdb gem / library and open football.db (public domain) datasets. Example: ``` ruby require 'sportdb/config' ## note: requires a local copy of the football.db clubs datasets ## see https://github.com/openfootball/clubs SportDb::Import.config.clubs_dir = './clubs' m = SportDb::Import.config.clubs.match( 'Arsenal' ) m.size # 3 club matches found #=> 3 m[0].name; m[0].city; m[0].country #=> "Arsenal FC", "London", "England" m[1].name; m[1].city; m[1].country #=> "Arsenal Tula", "Tula", "Russia" m[2].name; m[2].city; m[2].country #=> "Arsenal de Sarandí", "Sarandí", "Argentina" m = SportDb::Import.config.clubs.match_by( name: 'Arsenal', country: 'eng' ) # -or- try alternative names (and auto-generated spelling variants) m = SportDb::Import.config.clubs.match_by( name: 'Arsenal FC', country: 'eng' ) m = SportDb::Import.config.clubs.match_by( name: 'Arsenal F.C.', country: 'eng' ) m = SportDb::Import.config.clubs.match_by( name: '...A.r.s.e.n.a.l... F.C...', country: 'eng' ) m.size # 1 club match found #=> 1 m[0].name; m[0].city; m[0].country #=> "Arsenal FC", "London", "England" m = SportDb::Import.config.clubs.match_by( name: 'Arsenal', country: 'ar' ) # -or- try alternative names (and auto-generated spelling variants) m = SportDb::Import.config.clubs.match_by( name: 'Arsenal Sarandí', country: 'ar' ) m = SportDb::Import.config.clubs.match_by( name: 'Arsenal Sarandi', country: 'ar' ) m.size # 1 club match found #=> 1 m[0].name; m[0].city; m[0].country #=> "Arsenal de Sarandí", "Sarandí", "Argentina" # try some more m = SportDb::Import.config.clubs.match( 'AZ' ) m[0].name; m[0].city; m[0].country #=> "AZ Alkmaar", "Alkmaar", "Netherlands" m = SportDb::Import.config.clubs.match( 'Bayern' ) # -or- try alternative names (and auto-generated spelling variants) m = SportDb::Import.config.clubs.match( 'Bayern München' ) m = SportDb::Import.config.clubs.match( 'Bayern Munchen' ) m = SportDb::Import.config.clubs.match( 'Bayern Muenchen' ) m[0].name; m[0].city; m[0].country #=> "Bayern München", "München", "Germany" # and so on # ... ``` Enjoy the beautiful game. Cheers. Prost. [1] https://github.com/sportdb/sport.db/tree/master/sportdb-config [2] https://github.com/openfootball/clubs Unsubscribe: <mailto:[email protected]?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>