football-sources 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9b9787aaaaad173642d6bf3ddd19bb573f8f997eb04dbe2e702dc830144eedb
4
- data.tar.gz: e2f0e59b5949d9994a4eb01b2ae2ef0deaa959042cb1a98feccf9c009a01ffbd
3
+ metadata.gz: 42b02267a8c37a2b3a38662941d13ac8e61e622c8b45dc0c06a28453e272b2dc
4
+ data.tar.gz: e26f5cf47b6c0390b4f5d99b85919852eb46e7822201e4d6eba52315dc683e44
5
5
  SHA512:
6
- metadata.gz: b95e6df43a8374cbc66d8e4774443a613de9a35ba8adc9041b496c1ae4f34ba03b55b887ed6f2573cafae37ecf3828490fa15bc0ea5c8b89d1723d6a45030db2
7
- data.tar.gz: 6674c3799a962cc57405f4cab10cf273bbc856f3268c9f556c02fc5da7541703e205ace4e1b431b417195aeab33a9666d084e0cb3a5dc3e14c0cdac273698e1b
6
+ metadata.gz: 24038df8393a7ab1635cd6a5a9376e20c29ba077fbe3db63a917a5f59154aec50c1f6f99c68e1f51cbbd1c28ce07412e89387ae9576e8fc22c2bc872df689ae0
7
+ data.tar.gz: d27328142ffed18c30078e66c5a313a9df7a12be714401cba36cfa6752c08d0f1c158a796e87c50202ba08ae5ab2212061db494982656b378c3374c3e1cd23c5
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 0.1.1
1
+ ### 0.2.0
2
2
 
3
3
  ### 0.0.1 / 2020-11-09
4
4
 
data/Manifest.txt CHANGED
@@ -2,6 +2,8 @@ CHANGELOG.md
2
2
  Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
+ bin/fbgen
5
6
  lib/football-sources.rb
7
+ lib/football-sources/process.rb
6
8
  lib/football-sources/version.rb
7
9
  lib/football/sources.rb
data/Rakefile CHANGED
@@ -21,6 +21,10 @@ Hoe.spec 'football-sources' do
21
21
 
22
22
  self.extra_deps = [
23
23
  ['sportdb-catalogs'], #, '>= 1.0.0'],
24
+ ['sportdb-writers'],
25
+ ## footballdata sources
26
+ ['footballdata-api'],
27
+ ['worldfootball'],
24
28
  ]
25
29
 
26
30
  self.licenses = ['Public Domain']
data/bin/fbgen ADDED
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ## tip: to test run:
4
+ ## ruby -I ./lib bin/fbgen
5
+
6
+ require 'football/sources'
7
+
8
+
9
+ load_env ## use dotenv (.env)
10
+
11
+
12
+ Webcache.root = if File.exist?( '/sports/cache' )
13
+ puts " setting web cache to >/sports/cache<"
14
+ '/sports/cache'
15
+ else
16
+ './cache'
17
+ end
18
+
19
+
20
+
21
+ ## set openfootball github org root - note - NOT monorepo (github) root dirc
22
+ SportDb::GitHubSync.root = '/sports/openfootball'
23
+
24
+
25
+ ## add convenience shortcuts
26
+ Country = Sports::Country
27
+ League = Sports::League
28
+ Club = Sports::Club
29
+
30
+ # Worldfootball.config.convert.out_dir = './o/aug29'
31
+ # Worldfootball.config.convert.out_dir = './o'
32
+ # Worldfootball.config.convert.out_dir = './o'
33
+ Worldfootball.config.convert.out_dir = if File.exist?( '/sports/cache.wfb' )
34
+ puts " setting wfb stage/cache to >/sports/cache.wfb<"
35
+ '/sports/cache.wfb'
36
+ else
37
+ './stage/wfb'
38
+ end
39
+ #########
40
+ ## staging cache settings
41
+ Footballdata.config.convert.out_dir = if File.exist?( '/sports/cache.api.fbdat' )
42
+ puts " setting fbdat stage/cache to >/sports/cache.api.fbdat<"
43
+ '/sports/cache.api.fbdat'
44
+ else
45
+ './stage/fbdat'
46
+ end
47
+
48
+ pp File.expand_path( Footballdata.config.convert.out_dir )
49
+
50
+
51
+ ## note - free tier (tier one) plan - 10 requests/minute
52
+ ## (one request every 6 seconds 6*10=60 secs)
53
+ ## 10 API calls per minute max.
54
+ ## note - default sleep (delay in secs) is 3 sec(s)
55
+ Webget.config.sleep = 10
56
+
57
+
58
+
59
+
60
+ require 'optparse'
61
+
62
+
63
+
64
+ args=ARGV
65
+
66
+
67
+ opts = {
68
+ type: 'fbdat',
69
+ download: false,
70
+ push: false,
71
+ }
72
+
73
+ parser = OptionParser.new do |parser|
74
+ parser.banner = "Usage: #{$PROGRAM_NAME} [options]"
75
+
76
+ # parser.on( "--cache", "--cached", "--offline",
77
+ # "use cached data in #{Webcache.root}" ) do |cached|
78
+ # opts[:cached] = cached
79
+ # end
80
+
81
+ parser.on( "-t NAME", "--type=NAME",
82
+ "use source type - default is (#{opts[:type]})" ) do |type|
83
+ opts[:type] = type
84
+ end
85
+ # end
86
+
87
+
88
+ # add download and push ???
89
+
90
+ end
91
+ parser.parse!( args )
92
+
93
+ puts "OPTS:"
94
+ p opts
95
+ puts "ARGV:"
96
+ p args
97
+
98
+
99
+
100
+ source = if ['fbdat'].include?( opts[:type] )
101
+ Footballdata
102
+ elsif ['wfb'].include?( opts[:type] )
103
+ Worldfootball
104
+ else
105
+ raise ArgumentError, "unknown source type - expected fbdata|wfb; got #{opts[:type]}"
106
+ end
107
+
108
+ puts "source:"
109
+ pp source
110
+
111
+
112
+ league = (args[0] || 'eng.1' ).downcase
113
+ season = (args[1] || '2024/25')
114
+
115
+ datasets = [
116
+ [league, [season]]
117
+ ]
118
+
119
+ puts "datasets:"
120
+ pp datasets
121
+
122
+
123
+
124
+ Fbgen.process( datasets,
125
+ source: source,
126
+ download: opts[:download],
127
+ push: opts[:push] )
128
+
129
+
130
+ puts "bye"
131
+
@@ -0,0 +1,68 @@
1
+
2
+
3
+ module Fbgen
4
+
5
+
6
+ class Job ## todo/check: use a module (NOT a class) - why? why not?
7
+ ## note - source expected module/class e.g. Footballdata/Worldfootball e.g.
8
+ def self.download( datasets, source: )
9
+ datasets.each_with_index do |dataset,i|
10
+ league = dataset[0]
11
+ seasons = dataset[1]
12
+
13
+ puts "downloading [#{i+1}/#{datasets.size}] #{league}..."
14
+ seasons.each_with_index do |season,j|
15
+ puts " season [#{j+1}/#{season.size}] #{league} #{season}..."
16
+ source.schedule( league: league,
17
+ season: season )
18
+ end
19
+ end
20
+ end
21
+
22
+ def self.convert( datasets, source: )
23
+ datasets.each_with_index do |dataset,i|
24
+ league = dataset[0]
25
+ seasons = dataset[1]
26
+
27
+ puts "converting [#{i+1}/#{datasets.size}] #{league}..."
28
+ seasons.each_with_index do |season,j|
29
+ puts " season [#{j+1}/#{season.size}] #{league} #{season}..."
30
+ source.convert( league: league,
31
+ season: season )
32
+ end
33
+ end
34
+ end
35
+ end # class Job
36
+
37
+
38
+ ## change download? to cache - true/false - why? why not?
39
+ ## change push: to sync - true/false - why? why not?
40
+ def self.process( datasets,
41
+ source:,
42
+ download: false,
43
+ push: false )
44
+
45
+ Job.download( datasets, source: source ) if download
46
+
47
+ ## always pull before push!! (use fast_forward)
48
+ gh = SportDb::GitHubSync.new( datasets )
49
+ gh.git_fast_forward_if_clean if push
50
+
51
+
52
+ Job.convert( datasets, source: source )
53
+
54
+ if push
55
+ Writer.config.out_dir = SportDb::GitHubSync.root # e.g. "/sports/openfootball"
56
+ else
57
+ ## fix/fix - use default - do not (re)set here - why? why not?
58
+ Writer.config.out_dir = './tmp'
59
+ end
60
+
61
+ Writer::Job.write( datasets,
62
+ source: source.config.convert.out_dir )
63
+
64
+ ## todo/fix: add a getch or something to hit return before commiting pushing - why? why not?
65
+ gh.git_push_if_changes if push
66
+ end
67
+
68
+ end # module Fbgen
@@ -1,8 +1,8 @@
1
1
 
2
2
  module FootballSources
3
3
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
4
- MINOR = 1
5
- PATCH = 1
4
+ MINOR = 2
5
+ PATCH = 0
6
6
  VERSION = [MAJOR,MINOR,PATCH].join('.')
7
7
 
8
8
  def self.version
@@ -10,7 +10,7 @@ module FootballSources
10
10
  end
11
11
 
12
12
  def self.banner
13
- "football-sources/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
13
+ "football-sources/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
14
14
  end
15
15
 
16
16
  def self.root
@@ -2,15 +2,20 @@
2
2
 
3
3
  # require 'sportdb/formats' ## for Season etc.
4
4
  require 'sportdb/catalogs' ## note: incl. deps csvreader etc.
5
+ require 'sportdb/writers'
5
6
 
6
7
 
7
-
8
+ require 'footballdata' # e.g. football-data.org (api)
9
+ require 'worldfootball' # e.g. weltfussball.de (web)
8
10
 
9
11
 
10
12
 
11
13
  ###
12
14
  # our own code
13
15
  require_relative 'football-sources/version' # let version always go first
16
+ require_relative 'football-sources/process'
17
+
18
+
14
19
 
15
20
 
16
21
  puts FootballSources.banner # say hello
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: football-sources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
@@ -24,6 +24,48 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sportdb-writers
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: footballdata-api
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: worldfootball
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: rdoc
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -61,7 +103,8 @@ dependencies:
61
103
  description: football-sources - get football match data (leagues, cups & more) via
62
104
  web pages or web api (json) calls
63
105
  email: gerald.bauer@gmail.com
64
- executables: []
106
+ executables:
107
+ - fbgen
65
108
  extensions: []
66
109
  extra_rdoc_files:
67
110
  - CHANGELOG.md
@@ -72,7 +115,9 @@ files:
72
115
  - Manifest.txt
73
116
  - README.md
74
117
  - Rakefile
118
+ - bin/fbgen
75
119
  - lib/football-sources.rb
120
+ - lib/football-sources/process.rb
76
121
  - lib/football-sources/version.rb
77
122
  - lib/football/sources.rb
78
123
  homepage: https://github.com/sportdb/sport.db