Hello,
I've put together the sportdb-importers gem / library v1.0 [1] that
lets you read in (import) match datafiles in comma-separated values
(csv) format into any SQL database (using the sport.db schema /
tables) using `SportDb.read_csv`.
Try it with the English Premier League e.g. 2019-20/eng.1.csv [2a]
or the Deutsche Bundesliga e.g. 2019-20/de.1.csv [2b], for example.
Show me the ruby code! From the readme - here we script:
Step 1
Setup the (SQL) database. Let's use and build a single-file SQLite
database (from scratch), as an example:
require 'sportdb/importers'
SportDb.connect( adapter: 'sqlite3',
database: './england.db' )
SportDb.create_all ## build database schema (tables, indexes, etc.)
Step 2
Let's use the public domain football.csv datasets for England (see
`footballcsv/england`, as an example:
Round, Date, Team 1, FT, HT, Team 2
1, (Fri) 9 Aug 2019, Liverpool FC, 4-1, 4-0, Norwich City FC
1, (Sat) 10 Aug 2019, West Ham United FC, 0-5, 0-1, Manchester City FC
1, (Sat) 10 Aug 2019, AFC Bournemouth, 1-1, 0-0, Sheffield United FC
1, (Sat) 10 Aug 2019, Burnley FC, 3-0, 0-0, Southampton FC
1, (Sat) 10 Aug 2019, Crystal Palace FC, 0-0, 0-0, Everton FC
1, (Sat) 10 Aug 2019, Watford FC, 0-3, 0-1, Brighton &
Hove Albion FC
1, (Sat) 10 Aug 2019, Tottenham Hotspur FC, 3-1, 0-1, Aston Villa FC
1, (Sun) 11 Aug 2019, Leicester City FC, 0-0, 0-0,
Wolverhampton Wanderers FC
1, (Sun) 11 Aug 2019, Newcastle United FC, 0-1, 0-0, Arsenal FC
1, (Sun) 11 Aug 2019, Manchester United FC, 4-0, 1-0, Chelsea FC
...
(Source: england/2019-20/eng.1.csv)
and let's try:
## assumes football.csv datasets for England in ./england directory
## see github.com/footballcsv/england
SportDb.read_csv( './england/2019-20/eng.1.csv' )
## let's try another season
SportDb.read_csv( './england/2018-19/eng.1.csv' )
SportDb.read_csv( './england/2018-19/eng.2.csv' )
All leagues, seasons, clubs, match days and rounds, match fixtures and results,
and more are now in your (SQL) database of choice.
Bonus: Let's import all datafiles for all seasons (from 1888-89 to today)
for England, use:
## note: requires a local copy of the football.csv england datasets
## see https://github.com/footballcsv/england
SportDb.read_csv( './england' )
# -or- use a zip archive
SportDb.read_csv( './england.zip' )
Enjoy the beautiful game with ruby. Cheers. Prost.
[1] https://github.com/sportdb/sport.db/tree/master/sportdb-importers
[2a] https://github.com/footballcsv/england/blob/master/2010s/2019-20/eng.1.csv
[2b] https://github.com/footballcsv/deutschland/blob/master/2010s/2019-20/de.1.csv