dtv_tournaments 0.0.1
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 +15 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +9 -0
- data/dtv_tournaments.gemspec +27 -0
- data/lib/dtv_tournaments/number_fetcher.rb +141 -0
- data/lib/dtv_tournaments/version.rb +3 -0
- data/lib/dtv_tournaments.rb +9 -0
- data/spec/number_fetcher_spec.rb +4 -0
- data/spec/spec_helper.rb +17 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDg1MmVkMDExYTUzMTRlMjdiMGFlYzc5YjYzYmFhZjk4YjA5YTU0Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZThiODk3ZDc2ZTY1NGIzN2U1YWE2MWNhMjY4M2RiZDMxMjdmMzdiYg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjI5YjIyNmRhNWRlOTNlMGI5OGM1ZDIwZmFjM2FmZTk1NjgyMWZmZTJiNzIz
|
10
|
+
NzJiOTdkZWQ4ZTRkMzc1MTRiMzMzZmJlNmNlZmZlMWVmNGNjYmI5OWE1OWJh
|
11
|
+
MjM3NDcxZTgwODMzOTU1NDcyZmUxY2E3ODQzNGU3YjA4NGNkODU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OTc4ZjA5NTUzZWFhNDczMzYxNGFiMjE5Mzc3ZjgwZjQ5ZGEyYmM1ZWRkOWEx
|
14
|
+
MDM0ZTRhMzMxNzIyMTEzNzE4OGUyZGQ1NzcxOTk2OWFjNDlkODkyN2M2YTAw
|
15
|
+
MDZkOWM3MzdmN2MwMjJiODE2ZjE5N2UxMGE5MGU1ZTc4Mjk1MGM=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Daniel Schmidt
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# DtvTournaments
|
2
|
+
|
3
|
+
A ruby gem for fetching tournaments from the dtv tournaments portal. The gem only works with rails, because it's using the rails caching methods. Later on, they may be configured in a config file, so rails won't be necessary anymore.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dtv_tournaments'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dtv_tournaments
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Just call ``DtvTournaments.get_by_number(number, options={})`` and you will get a hash like this returned
|
22
|
+
|
23
|
+
{
|
24
|
+
zip: ...,
|
25
|
+
city: ...,
|
26
|
+
street: ...,
|
27
|
+
number: ...,
|
28
|
+
time: ...,
|
29
|
+
date: ...,
|
30
|
+
datetime: ...,
|
31
|
+
kind: ...,
|
32
|
+
ageset: ...
|
33
|
+
}
|
34
|
+
|
35
|
+
The default options are
|
36
|
+
|
37
|
+
{
|
38
|
+
cached: false, # If you want to get an uncached version but don't override the cached version
|
39
|
+
rerun: false # If you want to override the cache
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
## Todos
|
44
|
+
- migrate old code to project
|
45
|
+
- test old code
|
46
|
+
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it ( http://github.com/DanielMSchmidt/dtv_tournaments/fork )
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dtv_tournaments/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dtv_tournaments"
|
8
|
+
spec.version = DtvTournaments::VERSION
|
9
|
+
spec.authors = ["Daniel Schmidt"]
|
10
|
+
spec.email = ["dschmidt@weluse.de"]
|
11
|
+
spec.summary = "A ruby gem for fetching tournaments from the dtv tournaments portal"
|
12
|
+
spec.description = "This gem fetches the appsrv.tanzsport.de/dtv-webdbs/turnier/suche.spf portal and gives all available informations about the tournaments"
|
13
|
+
spec.homepage = "https://github.com/DanielMSchmidt/dtv_tournaments"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "mechanize", "~> 2.7.2"
|
26
|
+
spec.add_runtime_dependency "rails"
|
27
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
|
3
|
+
module NumberFetcher
|
4
|
+
attr_accessor :number, :rerun, :cached
|
5
|
+
PREFIX = "tr"
|
6
|
+
FETCHINGURL = "http://appsrv.tanzsport.de/td/db/turnier/einzel/suche"
|
7
|
+
|
8
|
+
def self.get_by_number number, options={}
|
9
|
+
@number = number
|
10
|
+
@rerun = options[:rerun] || false
|
11
|
+
@cached = options[:cached] || false
|
12
|
+
|
13
|
+
# Rails.cache.delete("#{NumberFetcher::PREFIX}-#{@number}") if @rerun
|
14
|
+
|
15
|
+
if @cached
|
16
|
+
NumberFetcher::get_cached_tournament_data
|
17
|
+
else
|
18
|
+
get_tournament_data
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.get_cached_tournament_data
|
23
|
+
#return Rails.cache.fetch("#{NumberFetcher::PREFIX}-#{@number}") do
|
24
|
+
self.get_tournament_data
|
25
|
+
#end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.get_tournament_data
|
29
|
+
puts "Tournament data is fetching for #{@number}"
|
30
|
+
hash = NumberFetcher::extract_results(NumberFetcher::get_result_page(@number))
|
31
|
+
hash[:number] = @number
|
32
|
+
hash
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.get_result_page(number)
|
36
|
+
mechanize = Mechanize.new { |agent|
|
37
|
+
agent.read_timeout = 3
|
38
|
+
}
|
39
|
+
|
40
|
+
mechanize.get(NumberFetcher::FETCHINGURL)
|
41
|
+
search_form = mechanize.page.forms.last
|
42
|
+
|
43
|
+
search_form.nr = number
|
44
|
+
search_form.submit
|
45
|
+
|
46
|
+
mechanize.page
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.extract_results page
|
50
|
+
raw_data = NumberFetcher::get_raw_data(page)
|
51
|
+
extracted_results = {}
|
52
|
+
raw_data.each do |key, value|
|
53
|
+
extracted_results[key] = send("extract_#{key}", value) unless value.nil?
|
54
|
+
end
|
55
|
+
create_time_and_date extracted_results
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.create_time_and_date hash
|
59
|
+
time = hash.delete(:time)
|
60
|
+
date = hash.delete(:date)
|
61
|
+
hash[:datetime] = DateTime.parse("#{date} #{time}")
|
62
|
+
hash[:date] = Date.parse(date)
|
63
|
+
hash[:time] = Time.parse("#{date} #{time}")
|
64
|
+
hash
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.extract_kind(content)
|
68
|
+
NumberFetcher::convert_to_text(content)
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.extract_date(content)
|
72
|
+
NumberFetcher::convert_to_text(content).scan(/^\d{1,2}.\d{1,2}.\d{4}/).first
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.extract_time(content)
|
76
|
+
NumberFetcher::convert_to_text(content).scan(/\d{1,2}:\d{2}/).first
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.extract_notes(content)
|
80
|
+
NumberFetcher::convert_to_text(content)
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.extract_street(content)
|
84
|
+
NumberFetcher::convert_to_text(content).split("\t").join("").split("\n").delete_if{|x| x.empty? }.join(" ")
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.extract_zip(content)
|
88
|
+
content.text.gsub(/(\W)/, "").gsub(/(\D)/, "")
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.extract_city(content)
|
92
|
+
content.text.gsub(/(\W)/, "").gsub(/(\d)/, "")
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.convert_to_text(content)
|
96
|
+
if content.class == String
|
97
|
+
content
|
98
|
+
else
|
99
|
+
content.text
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.get_raw_data(page)
|
104
|
+
#Test id its a multiline tournament
|
105
|
+
if page.search(".markierung .uhrzeit").first.text.empty?
|
106
|
+
puts "This Tournament seems to be a big one: #{@number}"
|
107
|
+
|
108
|
+
page.search(".turniere tr").each do |single_tournament|
|
109
|
+
next_kind = NumberFetcher::get_subelement_if_available(single_tournament, ".turnier")
|
110
|
+
kind = next_kind unless next_kind.nil? || next_kind.empty?
|
111
|
+
|
112
|
+
next_time = NumberFetcher::get_subelement_if_available(single_tournament, ".uhrzeit")
|
113
|
+
time = next_time unless next_time.nil? || next_time.empty?
|
114
|
+
|
115
|
+
break if single_tournament.attributes().has_key?('class')
|
116
|
+
end
|
117
|
+
else
|
118
|
+
kind = page.search(".markierung .turnier")
|
119
|
+
time = page.search(".markierung .uhrzeit")
|
120
|
+
end
|
121
|
+
notes = page.search(".turniere tr .bemerkung").to_a.collect(&:text).reject{|x| x.nil? || x.empty?}.join("\n")
|
122
|
+
date = page.search(".kategorie")
|
123
|
+
street = page.search(".ort")
|
124
|
+
street.search("strong").remove # remove zip and city from field
|
125
|
+
zip = page.search(".ort strong")
|
126
|
+
city = page.search(".ort strong")
|
127
|
+
{ kind: kind, date: date, time: time, notes: notes, street: street, zip: zip, city: city }
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.get_subelement_if_available(element, selector)
|
131
|
+
unless element.search(selector).first.nil?
|
132
|
+
element.search(selector).first.text
|
133
|
+
else
|
134
|
+
nil
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
__END__
|
140
|
+
|
141
|
+
DtvTournaments.get_by_number(38543)
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
require 'dtv_tournaments'
|
5
|
+
require 'mechanize'
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dtv_tournaments
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Schmidt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
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: mechanize
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.7.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.7.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: This gem fetches the appsrv.tanzsport.de/dtv-webdbs/turnier/suche.spf
|
84
|
+
portal and gives all available informations about the tournaments
|
85
|
+
email:
|
86
|
+
- dschmidt@weluse.de
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- .rspec
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- dtv_tournaments.gemspec
|
98
|
+
- lib/dtv_tournaments.rb
|
99
|
+
- lib/dtv_tournaments/number_fetcher.rb
|
100
|
+
- lib/dtv_tournaments/version.rb
|
101
|
+
- spec/number_fetcher_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
homepage: https://github.com/DanielMSchmidt/dtv_tournaments
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.2.1
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: A ruby gem for fetching tournaments from the dtv tournaments portal
|
127
|
+
test_files:
|
128
|
+
- spec/number_fetcher_spec.rb
|
129
|
+
- spec/spec_helper.rb
|