sportdb-update 0.0.1 → 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d7dc97665809b5836d920a86ee6763ed254e567
4
+ data.tar.gz: a04f3d981e6d985634a3d7e6bf5d44a29a5958e1
5
+ SHA512:
6
+ metadata.gz: 19d4eb34c5e107259fb0094ab0d15d6f44267ef1eda55eccae56a67457fc3ba2a6217565a24befac6a54ce6dc704c332ec6667e64691675ff24248350fc081fc
7
+ data.tar.gz: e7934b2fa0cb0322921dc162710b96906a4b7c8d6f85f3b67b09b980ad5ae065e74dc959fa30839e8c485dd982bd1eb5eed536dc57938d3a6610c79b26c45745
data/Manifest.txt CHANGED
@@ -3,4 +3,5 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/sportdb/update.rb
6
+ lib/sportdb/update/updater.rb
6
7
  lib/sportdb/update/version.rb
@@ -0,0 +1,158 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # note: Updates lives/resides in "regular" SportDb namespace
5
+ # do NOT use nested SportDb::Update namespace
6
+
7
+
8
+ module SportDb
9
+
10
+ class Updater
11
+
12
+ include LogUtils::Logging
13
+
14
+ ######
15
+ # NB: make models available in sportdb module by default with namespace
16
+ # e.g. lets you use Team instead of Model::Team
17
+ include Models
18
+
19
+
20
+ def map_event_to_dlurl( event )
21
+
22
+ league_key = event.league.key
23
+ season_key = event.season.key
24
+
25
+ repo_path, folder_path = map_key_to_repo_n_folder_path( league_key )
26
+
27
+ return nil if repo_path.nil? # no match/mapping found; cancel download
28
+
29
+ season_path = season_key.gsub( '/', '_') # convert 2013/14 to 2013_14
30
+
31
+ #####
32
+ # quick hack!!!!
33
+ # - find something better e.g. more generic/easy to configure etc.
34
+ if league_key == 'world' # world cup repo mappings include host country e.g. 2014--brazil etc.
35
+ season_path = '2006--germany' if season_path == '2006'
36
+ season_path = '2010--south-africa' if season_path == '2010'
37
+ season_path = '2014--brazil' if season_path == '2014'
38
+ end
39
+
40
+ ###
41
+ # e.g. https://raw.github.com/openfootball/at-austria/master/2013_14
42
+
43
+ dlurl = "https://raw.github.com/openfootball/#{repo_path}/master"
44
+ dlurl << "/#{folder_path}" if folder_path.present?
45
+ dlurl << "/#{season_path}"
46
+ dlurl
47
+ end
48
+
49
+
50
+ def map_key_to_repo_n_folder_path( key )
51
+
52
+ ### allow * for regex match w/ .+
53
+ map = [
54
+ [ 'at', 'at-austria' ],
55
+ [ 'at.*', 'at-austria' ],
56
+ [ 'de', 'de-deutschland' ],
57
+ [ 'de.*', 'de-deutschland' ],
58
+ [ 'en', 'en-england' ],
59
+ [ 'es', 'es-espana' ],
60
+ [ 'it', 'it-italy' ],
61
+ [ 'be', 'europe', 'be-belgium' ], # NB: europe/be-belgium
62
+ [ 'ro', 'europe', 'ro-romania' ],
63
+ [ 'cl', 'europe-champions-league' ],
64
+ [ 'el', 'europe-champions-league' ],
65
+ [ 'br', 'br-brazil' ],
66
+ [ 'mx', 'mx-mexico' ], # todo: add mx.* for clausura etc ??
67
+ [ 'euro', 'euro-cup' ],
68
+ [ 'world', 'world-cup' ],
69
+ [ 'world.*', 'world-cup' ]]
70
+
71
+ map.each do |entry|
72
+ pattern = entry[0]
73
+ path = [ entry[1], entry[2] ] # repo n folder path
74
+
75
+ if pattern.index( '*' ).nil? # match just plain string (no wildcard *)
76
+ return path if key == pattern
77
+ else
78
+ # assume regex match
79
+ regex = pattern.gsub( '.', '\.' ).gsub( '*', '.+' )
80
+ return path if key =~ /#{regex}/
81
+ end
82
+ end
83
+ nil # return nil; no match found
84
+ end
85
+
86
+ def update_event( event )
87
+ logger.info "update event >>#{event.title}<< (#{event.league.key}+#{event.season.key})"
88
+
89
+ dlbase = map_event_to_dlurl( event )
90
+ if dlbase.nil?
91
+ logger.warn " [Updater] skip download; no download source mapping found for >#{event.key}<"
92
+ return # cancel download; no mapping found
93
+ end
94
+
95
+ puts " using dlbase >>#{dlbase}<<"
96
+
97
+ if event.sources.nil?
98
+ logger.warn " [Updater] skip download; no download event source configured/found for >#{event.key}<"
99
+ return
100
+ end
101
+
102
+ sources = event.sources.gsub(' ','').split(',') # NB: remove all blanks (leading,trailing,inside)
103
+
104
+
105
+ text_ary = [] # array of fixtures (text)
106
+
107
+ ## collect all fixtures (text)
108
+ sources.each_with_index do |source,i|
109
+ dlurl = "#{dlbase}/#{source}.txt"
110
+ logger.info " downloading source (#{i+1}/#{sources.length}) >>#{dlurl}<< ..." # todo/check: use size for ary or length - does it matter?
111
+
112
+ # download fixtures into string
113
+ text = Fetcher.read( dlurl )
114
+
115
+ logger.debug "text.encoding.name (before): #{text.encoding.name}"
116
+
117
+ ###
118
+ # NB: Net::HTTP will NOT set encoding UTF-8 etc.
119
+ # will mostly be ASCII
120
+ # - try to change encoding to UTF-8 ourselves
121
+
122
+ #####
123
+ # NB: ASCII-8BIT == BINARY == Encoding Unknown; Raw Bytes Here
124
+
125
+ ## NB:
126
+ # for now "hardcoded" to utf8 - what else can we do?
127
+ # - note: force_encoding will NOT change the chars only change the assumed encoding w/o translation
128
+ text = text.force_encoding( Encoding::UTF_8 )
129
+ logger.debug "text.encoding.name (after): #{text.encoding.name}"
130
+
131
+ text_ary << text
132
+ end
133
+
134
+ ## note: need to pass in all fixtures at once (e.g as array) for @last_pos calc etc to work
135
+ ## if multipe "files"/strings are used
136
+ unless text_ary.empty?
137
+ puts " importing/reading source..."
138
+ # passing dummy include_path (not needed for reading from string)
139
+ # fix: use/add proper api for reading from string e.g. read and read_file ?? etc.
140
+ reader= GameReader.new( '/tmp' )
141
+ ### fix: allow to pass in event (to avoid lookup)
142
+ reader.read_fixtures_from_string( event.key, text_ary )
143
+ end
144
+ end
145
+
146
+
147
+ def run
148
+ # for now update all events (fixtures only) - not *.yml
149
+
150
+ Event.all.each do |event|
151
+ update_event( event )
152
+ end
153
+
154
+ end
155
+
156
+ end # class Updater
157
+
158
+ end # module SportDb
@@ -1,6 +1,24 @@
1
1
 
2
2
  module SportDb
3
- module Update
4
- VERSION = '0.0.1'
3
+ module Update
4
+
5
+ MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
+ MINOR = 1
7
+ PATCH = 0
8
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
9
+
10
+ def self.version
11
+ VERSION
12
+ end
13
+
14
+ def self.banner
15
+ "sportdb-update/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
5
16
  end
17
+
18
+ def self.root
19
+ "#{File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )}"
20
+ end
21
+
22
+ end # module Update
6
23
  end
24
+
@@ -8,22 +8,9 @@ require 'sportdb'
8
8
  # our own code
9
9
 
10
10
  require 'sportdb/update/version' # let it always go first
11
+ require 'sportdb/update/updater'
11
12
 
12
13
 
13
- module SportDb
14
- module Update
15
-
16
- def self.banner
17
- "sportdb-update/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
18
- end
19
-
20
- def self.root
21
- "#{File.expand_path( File.dirname( File.dirname(File.dirname(__FILE__))) )}"
22
- end
23
-
24
- end # module Update
25
- end # module SportDb
26
-
27
14
 
28
15
  puts SportDb::Update.banner # say hello
29
16
 
metadata CHANGED
@@ -1,38 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-update
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gerald Bauer
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-08-10 00:00:00.000000000 Z
11
+ date: 2014-11-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rdoc
16
- requirement: &83336190 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '4.0'
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *83336190
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: hoe
27
- requirement: &83335950 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ~>
31
+ - - "~>"
31
32
  - !ruby/object:Gem::Version
32
- version: '3.11'
33
+ version: '3.13'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *83335950
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.13'
36
41
  description: sportdb-update - sport.db addon for auto-updates (e.g. pulling n merging
37
42
  updates from upstream sources)
38
43
  email: opensport@googlegroups.com
@@ -48,33 +53,33 @@ files:
48
53
  - README.md
49
54
  - Rakefile
50
55
  - lib/sportdb/update.rb
56
+ - lib/sportdb/update/updater.rb
51
57
  - lib/sportdb/update/version.rb
52
58
  homepage: https://github.com/sportdb/sport.db.update.ruby
53
59
  licenses:
54
60
  - Public Domain
61
+ metadata: {}
55
62
  post_install_message:
56
63
  rdoc_options:
57
- - --main
64
+ - "--main"
58
65
  - README.md
59
66
  require_paths:
60
67
  - lib
61
68
  required_ruby_version: !ruby/object:Gem::Requirement
62
- none: false
63
69
  requirements:
64
- - - ! '>='
70
+ - - ">="
65
71
  - !ruby/object:Gem::Version
66
72
  version: 1.9.2
67
73
  required_rubygems_version: !ruby/object:Gem::Requirement
68
- none: false
69
74
  requirements:
70
- - - ! '>='
75
+ - - ">="
71
76
  - !ruby/object:Gem::Version
72
77
  version: '0'
73
78
  requirements: []
74
79
  rubyforge_project:
75
- rubygems_version: 1.8.17
80
+ rubygems_version: 2.4.2
76
81
  signing_key:
77
- specification_version: 3
82
+ specification_version: 4
78
83
  summary: sportdb-update - sport.db addon for auto-updates (e.g. pulling n merging
79
84
  updates from upstream sources)
80
85
  test_files: []