footty 2025.4.9 → 2025.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3101d3bc2cbc21aae12dcc1a108f7972211d55c86415a06c48e0a8db945ac3f
4
- data.tar.gz: afaa93ffb303fd4205acdaa1aee1c80ec810a7bf723dabb99960025edb03076b
3
+ metadata.gz: 597423aa8445e6fd662c9a6541230726d1d97316e5f9a7ec7c8781dbf5f2f4e6
4
+ data.tar.gz: c5bf0acffaa91bd215253eef1b8271348e9596499ff202ef131fa8ef002abd5a
5
5
  SHA512:
6
- metadata.gz: 8d23098b1142d238c5f18bec351b6aff504682cb21e724df04dace6a9e40294267463037313c0fafae9a51e46ae80f88e976b681fb6d79fd51832282610957b7
7
- data.tar.gz: 3906e217d2f73536b52295c6502eed1b96af0d4cd436a331c075ecc1780ab8c005ebbad260ef3856a70009cd5a4befd037f700e4a3f1d050b7bc3842b70a5b90
6
+ metadata.gz: fe813055addd774484ca21f19f4200c4cd567f242121df493192fbb5ea1b96a50a893d157c12d255b17743b1014eed13020914859bd23984aa969836e9302b20
7
+ data.tar.gz: 140a848370b4d24ce43c9cc815fb2b28e2745eb68060dcae43415c1a54c770f9aaeb675d0b809ffbaf753b7b1353b9e98a7d021b1fb73fdc5d08d5adfe15b936
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 2025.4.9
1
+ ### 2025.5.2
2
2
  ### 1.0.0 / 2018-06-09
3
3
 
4
4
  * Everything is new (again). First release.
data/Manifest.txt CHANGED
@@ -5,7 +5,6 @@ Rakefile
5
5
  bin/footty
6
6
  bin/ftty
7
7
  lib/footty.rb
8
- lib/footty/datalib.rb
9
8
  lib/footty/dataset.rb
10
9
  lib/footty/openfootball.rb
11
10
  lib/footty/print.rb
data/README.md CHANGED
@@ -81,7 +81,7 @@ More
81
81
  - `world` => World Cup
82
82
  - `euro` => "Euro" - European Championship
83
83
 
84
- See [footty/openfootball](https://github.com/sportdb/footty/blob/master/lib/footty/openfootball.rb) for the complete built-in list of data sources (and league codes).
84
+ See [footty/openfootball](https://github.com/sportdb/footty/blob/master/footty/lib/footty/openfootball.rb) for the complete built-in list of data sources (and league codes).
85
85
 
86
86
 
87
87
 
@@ -42,10 +42,40 @@ module Footty
42
42
  def yesterdays_matches( date: Date.today ) matches_for( date-1 ); end
43
43
 
44
44
  def matches_for( date )
45
- matches = select_matches { |match| date == Date.parse( match['date'] ) }
45
+ matches = select_matches do |match|
46
+ date == Date.parse( match['date'] )
47
+ end
46
48
  matches
47
49
  end
48
50
 
51
+
52
+ def weeks_matches( week_start, week_end ) matches_within( week_start, week_end); end
53
+
54
+ def matches_within( start_date, end_date )
55
+ matches = select_matches do |match|
56
+ date = Date.parse( match['date'] )
57
+ date >= start_date && date <= end_date
58
+ end
59
+ matches
60
+ end
61
+
62
+
63
+ def query( q )
64
+ ## query/check for team name match for now
65
+ rx = /#{Regexp.escape(q)}/i ## use case-insensitive regex match
66
+
67
+ matches = select_matches do |match|
68
+ if rx.match( match['team1'] ) ||
69
+ rx.match( match['team2'] )
70
+ true
71
+ else
72
+ false
73
+ end
74
+ end
75
+ matches
76
+ end
77
+
78
+
49
79
 
50
80
  def upcoming_matches( date: Date.today,
51
81
  limit: nil )
@@ -11,11 +11,23 @@ module Footty
11
11
  'euro' => { '2024' => 'euro/2024--germany/euro.txt',
12
12
  '2021' => 'euro/2021--europe/euro.txt'
13
13
  },
14
- 'de' => 'deutschland/$season$/1-bundesliga.txt',
15
- 'de2' => 'deutschland/$season$/2-bundesliga2.txt',
16
-
17
- 'en'=> 'england/$season$/1-premierleague.txt',
18
- 'es'=> 'espana/$season$/1-liga.txt',
14
+ 'de' => 'deutschland/$season$/1-bundesliga.txt',
15
+ 'de2' => 'deutschland/$season$/2-bundesliga2.txt',
16
+ 'de3' => 'deutschland/$season$/3-liga3.txt',
17
+ 'decup' => 'deutschland/$season$/cup.txt',
18
+
19
+
20
+ 'en' => 'england/$season$/1-premierleague.txt',
21
+ 'en2' => 'england/$season$/2-championship.txt',
22
+ ## add alternate codes!!!
23
+ ## use eflcup, facup - why? why not?
24
+ 'eneflcup' => 'england/$season$/eflcup.txt',
25
+ 'enfacup' => 'england/$season$/facup.txt',
26
+
27
+
28
+ 'es' => 'espana/$season$/1-liga.txt',
29
+ 'escup' => 'espana/$season$/cup.txt',
30
+
19
31
  'it'=> 'italy/$season$/1-seriea.txt',
20
32
 
21
33
  'at'=> 'austria/$season$/1-bundesliga.txt',
@@ -27,18 +39,31 @@ module Footty
27
39
  'nl'=> 'europe/netherlands/$season$_nl1.txt',
28
40
  'be'=> 'europe/belgium/$season$_be1.txt',
29
41
 
30
- 'champs'=> 'champions-league/$season$/cl.txt',
42
+ 'champs' => 'champions-league/$season$/cl.txt',
43
+ 'uefacl' => 'champions-league/$season$/cl.txt',
44
+ 'uefael' => 'champions-league/$season$/el.txt',
45
+ 'uefaconf' => 'champions-league/$season$/conf.txt',
46
+
31
47
 
32
48
  'br' => 'south-america/brazil/$year$_br1.txt',
33
49
  'ar' => 'south-america/argentina/$year$_ar1.txt',
34
50
  'co' => 'south-america/colombia/$year$_co1.txt',
51
+
35
52
  ## use a different code for copa libertadores? why? why not?
36
53
  'copa' => 'south-america/copa-libertadores/$year$_copal.txt',
37
54
 
38
55
  'mx' => 'world/north-america/mexico/$season$_mx1.txt',
56
+ 'mls' => 'world/north-america/major-league-soccer/$year$_mls.txt',
57
+
58
+ 'concacafcl' => 'world/north-america/champions-league/$year$_concacafcl.txt',
39
59
 
40
60
  'eg' => 'world/africa/egypt/$season$_eg1.txt',
41
61
  'ma' => 'world/africa/morocco/$season$_ma1.txt',
62
+
63
+ 'au' => 'world/pacific/australia/$season$_au1.txt',
64
+ 'jp' => 'world/asia/japan/$year$_jp1.txt',
65
+ 'cn' => 'world/asia/china/$year$_cn1.txt',
66
+
42
67
  }
43
68
 
44
69
 
@@ -51,6 +76,8 @@ module Footty
51
76
  def self.latest_season( league: )
52
77
  spec = SOURCES[ league.downcase ]
53
78
 
79
+ raise ArgumentError, "no dataset (source) for league #{league} found" if spec.nil?
80
+
54
81
  ## todo/fix - report error if no spec found
55
82
  season = if spec.is_a?( Hash ) ## assume lookup by year
56
83
  spec.keys[0]
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Footty
3
- VERSION = '2025.4.9'
3
+ VERSION = '2025.5.2'
4
4
 
5
5
  def self.banner
6
6
  "footty/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
data/lib/footty.rb CHANGED
@@ -10,7 +10,6 @@ require 'optparse'
10
10
  require_relative 'footty/version' # let version always go first
11
11
  require_relative 'footty/dataset'
12
12
  require_relative 'footty/openfootball'
13
- ## require_relative 'footty/datalib'
14
13
 
15
14
  require_relative 'footty/print'
16
15
 
@@ -23,6 +22,27 @@ Webget.config.sleep = 1 ## set delay in secs (to 1 sec - default is/maybe 3)
23
22
 
24
23
 
25
24
  module Footty
25
+
26
+
27
+ def self.week_tue_to_mon( today=Date.today )
28
+ ## Calculate the start of the (sport) week (tuesday)
29
+ ## note - wday starts counting sunday (0), monday (1), etc.
30
+ week_tue = today - (today.wday - 2) % 7
31
+ week_mon = week_tue + 6
32
+
33
+ [week_tue,week_mon]
34
+ end
35
+
36
+ def self.fmt_week( week_start, week_end )
37
+ buf = String.new
38
+ buf << "Week %02d" % week_start.cweek
39
+ buf << " - #{week_start.strftime( "%a %b/%-d")}"
40
+ buf << " to #{week_end.strftime( "%a %b/%-d %Y")}"
41
+ buf
42
+ end
43
+
44
+
45
+
26
46
  def self.main( args=ARGV )
27
47
  puts banner # say hello
28
48
 
@@ -31,13 +51,15 @@ module Footty
31
51
  verbose: false, ## add more details
32
52
  ## add cache/cache_dir - why? why not?
33
53
 
54
+ query: nil,
55
+
34
56
  ## display format/mode - week/window/upcoming/past (default is today)
35
57
  yesterday: nil,
36
58
  tomorrow: nil,
37
59
  upcoming: nil,
38
60
  past: nil,
39
61
 
40
- # week: nil,
62
+ week: false,
41
63
  # window: nil, ## 2 day plus/minus +2/-2
42
64
  }
43
65
 
@@ -50,6 +72,11 @@ module Footty
50
72
  opts[:verbose] = true
51
73
  end
52
74
 
75
+ parser.on( "-q NAME", "--query",
76
+ "query mode; display matches where team name matches query" ) do |query|
77
+ opts[:query] = query
78
+ end
79
+
53
80
 
54
81
  parser.on( "-y", "--yesterday" ) do |yesterday|
55
82
  opts[:yesterday] = true
@@ -63,6 +90,11 @@ module Footty
63
90
  parser.on( "-u", "--up", "--upcoming" ) do |upcoming|
64
91
  opts[:upcoming] = true
65
92
  end
93
+
94
+ parser.on( "-w", "--week",
95
+ "show matches of the (sport) week from tue to mon (default: #{opts[:week]})" ) do |week|
96
+ opts[:week] = true
97
+ end
66
98
  end
67
99
  parser.parse!( args )
68
100
 
@@ -72,9 +104,40 @@ module Footty
72
104
  puts "ARGV:"
73
105
  p args
74
106
 
107
+
108
+ ###
109
+ ## use simple norm(alize) args (that is,) league codes for now
110
+ ## - downcase, strip dot (.) etc.)
111
+ ## e.g. en.facup => enfacup
112
+ ## at.cup => atcup etc.
113
+ args = args.map { |arg| arg.downcase.gsub( /[._-]/, '' ) }
114
+
115
+
116
+
117
+ ######################
118
+ ## note - first check for buil-in "magic" commands
119
+ ## e.g. leagues / codes - dump built-in league codes
120
+
121
+ if args.include?( 'leagues' )
122
+ puts "==> openfootball dataset sources:"
123
+ pp OpenfootballDataset::SOURCES
124
+
125
+ ## pretty print keys/codes only
126
+ puts
127
+ puts OpenfootballDataset::SOURCES.keys.join( ' ' )
128
+ puts " #{OpenfootballDataset::SOURCES.keys.size} league code(s)"
129
+
130
+ exit 1
131
+ end
132
+
133
+
134
+
135
+
75
136
 
76
137
  top = [['world', '2022'],
77
138
  ['euro', '2024'],
139
+ ['mls', '2025'],
140
+ ['concacafcl', '2025'],
78
141
  ['mx', '2024/25'],
79
142
  ['copa', '2025'], ## copa libertadores
80
143
  ['en', '2024/25'],
@@ -82,8 +145,12 @@ module Footty
82
145
  ['it', '2024/25'],
83
146
  ['fr', '2024/25'],
84
147
  ['de', '2024/25'],
148
+ ['decup', '2024/25'],
85
149
  ['at', '2024/25'],
86
- ['champs', '2024/25'],
150
+ ['atcup', '2024/25'],
151
+ ['uefacl', '2024/25'],
152
+ ['uefael', '2024/25'],
153
+ ['uefaconf', '2024/25'],
87
154
  ]
88
155
 
89
156
 
@@ -108,6 +175,28 @@ module Footty
108
175
 
109
176
 
110
177
 
178
+ ###################
179
+ ## check for query option to filter matches by query (team)
180
+ if opts[:query]
181
+ q = opts[:query]
182
+ puts
183
+ puts
184
+ datasets.each do |dataset|
185
+ matches = dataset.query( q )
186
+
187
+ if matches.size == 0
188
+ ## siltently skip for now
189
+ else ## assume matches found
190
+ print "==> #{dataset.league_name}"
191
+ print " #{dataset.start_date} - #{dataset.end_date}"
192
+ print " -- #{dataset.matches.size} match(es)"
193
+ print "\n"
194
+ print_matches( matches )
195
+ end
196
+ end
197
+ exit 1
198
+ end
199
+
111
200
 
112
201
  # Dataset.new( league: 'euro', year: 2024 )
113
202
  # dataset = Dataset.new( league: league, year: year )
@@ -124,20 +213,36 @@ module Footty
124
213
  'past'
125
214
  elsif opts[:upcoming]
126
215
  'upcoming'
216
+ elsif opts[:week]
217
+ 'week'
127
218
  else
128
219
  'today'
129
220
  end
130
221
 
131
- ## start with two empty lines - assume (massive) debug output before ;-)
132
- puts
133
- puts
222
+
223
+ ## if week get week number and start and end date (tuesday to mondey)
224
+ if what == 'week'
225
+ week_start, week_end = Footty.week_tue_to_mon( today)
226
+ puts
227
+ puts "=== " + Footty.fmt_week( week_start, week_end ) + " ==="
228
+ else
229
+ ## start with two empty lines - assume (massive) debug output before ;-)
230
+ puts
231
+ puts
232
+ end
233
+
134
234
  datasets.each do |dataset|
135
235
  print "==> #{dataset.league_name}"
136
236
  print " #{dataset.start_date} - #{dataset.end_date}"
137
237
  print " -- #{dataset.matches.size} match(es)"
138
238
  print "\n"
139
239
 
140
- if what == 'yesterday'
240
+ if what == 'week'
241
+ matches = dataset.weeks_matches( week_start, week_end )
242
+ if matches.empty?
243
+ puts (' '*4) + "** No matches scheduled or played in week #{week_start.cweek}.\n"
244
+ end
245
+ elsif what == 'yesterday'
141
246
  matches = dataset.yesterdays_matches
142
247
  if matches.empty?
143
248
  puts (' '*4) + "** No matches played yesterday.\n"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: footty
3
3
  version: !ruby/object:Gem::Version
4
- version: 2025.4.9
4
+ version: 2025.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-09 00:00:00.000000000 Z
11
+ date: 2025-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-quick
@@ -91,7 +91,6 @@ files:
91
91
  - bin/footty
92
92
  - bin/ftty
93
93
  - lib/footty.rb
94
- - lib/footty/datalib.rb
95
94
  - lib/footty/dataset.rb
96
95
  - lib/footty/openfootball.rb
97
96
  - lib/footty/print.rb
@@ -1,20 +0,0 @@
1
- module Footty
2
-
3
- class Datalib ## Library (Selection) of datasets
4
- ## nameing - use datasel(ection) or datacol(lection)
5
- ## or databox or dataman(ger) or
6
- ## or datacache or
7
- ## or datacomposite/view
8
- ## or dtataportal or ???
9
-
10
-
11
- def initialize( datasets=[] )
12
- @datasets = datasets
13
- end
14
-
15
-
16
-
17
-
18
-
19
- end # class Datalib
20
- end # module Footty