betforker 1.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.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +2 -0
  6. data/Gemfile.lock +90 -0
  7. data/README.md +53 -0
  8. data/Rakefile +12 -0
  9. data/betforker.gemspec +23 -0
  10. data/bin/betforker +64 -0
  11. data/config.yml +14 -0
  12. data/lib/betforker.rb +80 -0
  13. data/lib/betforker/bookmakers/__to_change__/betfair.rb +112 -0
  14. data/lib/betforker/bookmakers/__to_change__/parimatch.rb +137 -0
  15. data/lib/betforker/bookmakers/__to_change__/sbobet.rb +90 -0
  16. data/lib/betforker/bookmakers/__to_change__/winlinebet.rb +122 -0
  17. data/lib/betforker/bookmakers/marathon.rb +121 -0
  18. data/lib/betforker/bookmakers/williamhill.rb +115 -0
  19. data/lib/betforker/comparer.rb +176 -0
  20. data/lib/betforker/config.rb +201 -0
  21. data/lib/betforker/downloader.rb +128 -0
  22. data/lib/betforker/event.rb +74 -0
  23. data/lib/betforker/fork.rb +29 -0
  24. data/lib/betforker/names_winlinebet.rb +1092 -0
  25. data/lib/betforker/parsed_page.rb +13 -0
  26. data/lib/betforker/version.rb +3 -0
  27. data/spec/betforker_spec.rb +39 -0
  28. data/spec/bookmakers/__to_change__/betfair_test.rb +40 -0
  29. data/spec/bookmakers/__to_change__/parimatch_test.rb +41 -0
  30. data/spec/bookmakers/__to_change__/sbobet_test.rb +40 -0
  31. data/spec/bookmakers/__to_change__/winlinebet_test.rb +39 -0
  32. data/spec/bookmakers/marathon_spec.rb +84 -0
  33. data/spec/bookmakers/williamhill_spec.rb +81 -0
  34. data/spec/comparer_spec.rb +162 -0
  35. data/spec/config_spec.rb +155 -0
  36. data/spec/downloader_spec.rb +88 -0
  37. data/spec/event_spec.rb +94 -0
  38. data/spec/features/without_downloads_spec.rb +138 -0
  39. data/spec/fork_spec.rb +21 -0
  40. data/spec/spec_helper.rb +199 -0
  41. data/spec/support/html/betfair/betfair1.html +3453 -0
  42. data/spec/support/html/betfair/betfair2.html +3996 -0
  43. data/spec/support/html/betfair/betfair3.html +6566 -0
  44. data/spec/support/html/betfair/betfair4.html +3373 -0
  45. data/spec/support/html/betfair/bf_live.htm +5905 -0
  46. data/spec/support/html/fake/fake.html +15759 -0
  47. data/spec/support/html/marathon/first.html +2717 -0
  48. data/spec/support/html/marathon/live_page.html +7226 -0
  49. data/spec/support/html/marathon/second.html +3500 -0
  50. data/spec/support/html/marathon/with_forks.html +2525 -0
  51. data/spec/support/html/parimatch/parimatch1.html +588 -0
  52. data/spec/support/html/parimatch/parimatch2.html +589 -0
  53. data/spec/support/html/parimatch/parimatch3.html +581 -0
  54. data/spec/support/html/parimatch/parimatch4.html +641 -0
  55. data/spec/support/html/parimatch/pm_live.html +1049 -0
  56. data/spec/support/html/sbobet/sb1.htm +8 -0
  57. data/spec/support/html/sbobet/sb2.htm +8 -0
  58. data/spec/support/html/sbobet/sb3.htm +8 -0
  59. data/spec/support/html/sbobet/sb4.htm +8 -0
  60. data/spec/support/html/sbobet/sbobet_live.htm +8 -0
  61. data/spec/support/html/williamhill/first.html +13273 -0
  62. data/spec/support/html/williamhill/live_page.html +42735 -0
  63. data/spec/support/html/williamhill/second.html +15759 -0
  64. data/spec/support/html/williamhill/with_forks.html +13473 -0
  65. data/spec/support/html/williamhill/without_forks.html +14016 -0
  66. data/spec/support/html/winlinebet/win1.htm +23797 -0
  67. data/spec/support/html/winlinebet/win2.htm +23797 -0
  68. data/spec/support/html/winlinebet/win3.htm +23797 -0
  69. data/spec/support/html/winlinebet/win4.htm +23797 -0
  70. data/spec/support/html/winlinebet/win_live.htm +23815 -0
  71. metadata +211 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3749157daf9c994010c16ccde4aba24637909989
4
+ data.tar.gz: adbdaf874f2b70dadef7f8783d60fe5418b4116b
5
+ SHA512:
6
+ metadata.gz: c7a51d74a283ec7ddd955b29616c7d24e19775eb666064c99ff2c9e963d849a6e6b804472c887da286c5978e0a6c4f383149dd14b7e40c8b3973737a6250e4b1
7
+ data.tar.gz: 0be39ec13be2fe1c79da586fdfa6d015c5e4eba482090a5d144dd30627a7b9ab43f944f22cd7c634508a34f54f09df4aee933550bcfe42d4d54a43efa6f9bfca
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg/
2
+ logs/
3
+ *.swp
4
+ tmp/
5
+ .bundle/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm: 2.3.0
3
+ script: bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,90 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ betforker (1.0.1)
5
+ highline (~> 1.7)
6
+ mechanize (~> 2.7)
7
+ nokogiri (~> 1.6)
8
+ poltergeist (= 1.9)
9
+ thor (~> 0.19)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ addressable (2.4.0)
15
+ capybara (2.7.1)
16
+ addressable
17
+ mime-types (>= 1.16)
18
+ nokogiri (>= 1.3.3)
19
+ rack (>= 1.0.0)
20
+ rack-test (>= 0.5.4)
21
+ xpath (~> 2.0)
22
+ cliver (0.3.2)
23
+ diff-lcs (1.2.5)
24
+ domain_name (0.5.20160615)
25
+ unf (>= 0.0.5, < 1.0.0)
26
+ highline (1.7.8)
27
+ http-cookie (1.0.2)
28
+ domain_name (~> 0.5)
29
+ mechanize (2.7.4)
30
+ domain_name (~> 0.5, >= 0.5.1)
31
+ http-cookie (~> 1.0)
32
+ mime-types (>= 1.17.2, < 3)
33
+ net-http-digest_auth (~> 1.1, >= 1.1.1)
34
+ net-http-persistent (~> 2.5, >= 2.5.2)
35
+ nokogiri (~> 1.6)
36
+ ntlm-http (~> 0.1, >= 0.1.1)
37
+ webrobots (>= 0.0.9, < 0.2)
38
+ mime-types (2.99.2)
39
+ mini_portile2 (2.1.0)
40
+ multi_json (1.12.1)
41
+ net-http-digest_auth (1.4)
42
+ net-http-persistent (2.9.4)
43
+ nokogiri (1.6.8)
44
+ mini_portile2 (~> 2.1.0)
45
+ pkg-config (~> 1.1.7)
46
+ ntlm-http (0.1.1)
47
+ pkg-config (1.1.7)
48
+ poltergeist (1.9.0)
49
+ capybara (~> 2.1)
50
+ cliver (~> 0.3.1)
51
+ multi_json (~> 1.0)
52
+ websocket-driver (>= 0.2.0)
53
+ rack (1.6.4)
54
+ rack-test (0.6.3)
55
+ rack (>= 1.0)
56
+ rake (11.2.2)
57
+ rspec (3.4.0)
58
+ rspec-core (~> 3.4.0)
59
+ rspec-expectations (~> 3.4.0)
60
+ rspec-mocks (~> 3.4.0)
61
+ rspec-core (3.4.4)
62
+ rspec-support (~> 3.4.0)
63
+ rspec-expectations (3.4.0)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.4.0)
66
+ rspec-mocks (3.4.1)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.4.0)
69
+ rspec-support (3.4.1)
70
+ thor (0.19.1)
71
+ unf (0.1.4)
72
+ unf_ext
73
+ unf_ext (0.0.7.2)
74
+ webrobots (0.1.2)
75
+ websocket-driver (0.6.4)
76
+ websocket-extensions (>= 0.1.0)
77
+ websocket-extensions (0.1.2)
78
+ xpath (2.0.0)
79
+ nokogiri (~> 1.3)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ betforker!
86
+ rake (~> 11.2)
87
+ rspec (~> 3.4)
88
+
89
+ BUNDLED WITH
90
+ 1.12.5
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # betforker
2
+
3
+ [![Build Status](https://travis-ci.org/akkmaxon/betforker.svg?branch=master)](https://travis-ci.org/akkmaxon/betforker)
4
+
5
+ ## Description
6
+
7
+ The app is looking for bet forks.
8
+
9
+ ## Installation
10
+
11
+ Requirements:
12
+
13
+ - ruby
14
+ - phantomjs
15
+
16
+ After that run:
17
+
18
+ $ gem install betforker
19
+
20
+ Do not forget about extending your $PATH with rubygems' binaries.
21
+
22
+ ## Using
23
+
24
+ Execute the app:
25
+
26
+ $ betforker
27
+
28
+ View help:
29
+
30
+ $ betforker help
31
+
32
+ ## License
33
+
34
+ Copyright (c) 2015-2016 Maxim Akkuzin
35
+
36
+ Permission is hereby granted, free of charge, to any person obtaining
37
+ a copy of this software and associated documentation files (the
38
+ "Software"), to deal in the Software without restriction, including
39
+ without limitation the rights to use, copy, modify, merge, publish,
40
+ distribute, sublicense, and/or sell copies of the Software, and to
41
+ permit persons to whom the Software is furnished to do so, subject to
42
+ the following conditions:
43
+
44
+ The above copyright notice and this permission notice shall be
45
+ included in all copies or substantial portions of the Software.
46
+
47
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
51
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
52
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
53
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems/package_task'
2
+ require 'rdoc/task'
3
+ require 'rake/testtask'
4
+ spec = eval(File.read('betforker.gemspec'))
5
+
6
+ Gem::PackageTask.new(spec) do |pkg|
7
+ end
8
+ RDoc::Task.new do |rdoc|
9
+ rdoc.main = "README.md"
10
+ rdoc.rdoc_files.include("README.md", "lib/**/*.rb", "bin/**/*")
11
+ rdoc.title = 'Betforker doc'
12
+ end
data/betforker.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # Ensure we require the local version and not one we might have installed already
2
+ require File.join([File.dirname(__FILE__),'lib','betforker','version.rb'])
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = 'betforker'
5
+ s.version = Betforker::VERSION
6
+ s.author = 'Akkuzin Maxim'
7
+ s.email = 'akkmaxon2307@gmail.com'
8
+ s.homepage = 'https://github.com/akkmaxon/betforker'
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = "No comments..."
11
+ s.files = `git ls-files`.split("
12
+ ")
13
+ s.require_paths << 'lib'
14
+ s.bindir = 'bin'
15
+ s.executables << 'betforker'
16
+ s.add_dependency('nokogiri', '~> 1.6')
17
+ s.add_dependency('mechanize', '~> 2.7')
18
+ s.add_dependency('poltergeist', '1.9')
19
+ s.add_dependency('thor', '~> 0.19')
20
+ s.add_dependency('highline', '~> 1.7')
21
+ s.add_development_dependency('rake', '~> 11.2')
22
+ s.add_development_dependency('rspec', '~> 3.4')
23
+ end
data/bin/betforker ADDED
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+ require 'betforker'
4
+ include Betforker
5
+
6
+ class Betforker::App < Thor
7
+
8
+ if ARGV.size == 0
9
+ ARGV << 'default'
10
+ end
11
+
12
+ desc 'config', 'Change app\'s configuration'
13
+ map '-c' => :config, '--config' => :config
14
+ def config
15
+ Betforker::Config.update
16
+ end
17
+
18
+ desc 'events', 'List all current live events and exit'
19
+ map '-e' => :events, '--events' => :events
20
+ def events
21
+ Betforker.build_events $config[:bookmakers], $config[:sport]
22
+ end
23
+
24
+ desc 'parse ADDRESS', 'Parse event of given address'
25
+ map '-p' => :parse, '--parse' => :parse
26
+ def parse(address)
27
+ Downloader.prepare_phantomjs
28
+ event = Event.new [address]
29
+ event.get_webpages
30
+ event.parse_webpages $config[:bookmakers]
31
+ event.print_parsed_webpages
32
+ end
33
+
34
+ desc 'version', 'Show version of betforker'
35
+ map '-v' => :version, '--version' => :version
36
+ def version
37
+ say "Version: #{Betforker::VERSION}"
38
+ end
39
+
40
+ desc 'silent', 'Run betforker without logs with showing only desktop notifications'
41
+ map '-s' => :silent, '--silent' => :silent
42
+ def silent
43
+ $config[:log] = false
44
+ default
45
+ end
46
+
47
+ desc 'default', 'Run betforker with logs and notifications if forks were found(default mode)'
48
+ def default
49
+ loop do
50
+ events = Betforker::build_events $config[:bookmakers], $config[:sport]
51
+ events_size = events.size
52
+ events.each_with_index do |event, index|
53
+ event.print_message_about_event(events_size, index + 1) if $config[:log]
54
+ forks = event.find_forks
55
+ forks.each do |f|
56
+ f.desktop_show
57
+ end
58
+ end
59
+ Capybara.current_session.driver.browser.restart
60
+ end
61
+ end
62
+ end
63
+
64
+ Betforker::App.start
data/config.yml ADDED
@@ -0,0 +1,14 @@
1
+ ---
2
+ :marathon_changable: https://www.sportmarafonbet.com
3
+ :williamhill_changable: http://sports.bukstavki77.com
4
+ :min_percent: 1.0
5
+ :filtering: false
6
+ :sound_notification: true
7
+ :sport: tennis
8
+ :bookmakers:
9
+ - Marathon
10
+ - WilliamHill
11
+ :log: true
12
+ :time_of_notification: 20
13
+ :download_timeout: 25
14
+ :phantomjs_logger: false
data/lib/betforker.rb ADDED
@@ -0,0 +1,80 @@
1
+ require 'capybara/poltergeist'
2
+ require 'yaml'
3
+ require 'nokogiri'
4
+ require 'mechanize'
5
+ require 'thor'
6
+ require 'highline/import'
7
+ require 'betforker/version'
8
+ require 'betforker/event'
9
+ require 'betforker/parsed_page'
10
+ require 'betforker/downloader'
11
+ require 'betforker/comparer'
12
+ require 'betforker/fork'
13
+ require 'betforker/config'
14
+ require 'betforker/bookmakers/williamhill'
15
+ require 'betforker/bookmakers/marathon'
16
+
17
+ module Betforker
18
+ include Bookmakers
19
+ module_function
20
+
21
+ MARATHON_CHANGABLE, WILLIAMHILL_CHANGABLE = Config.changable_addresses
22
+ MARATHON_BASE = MARATHON_CHANGABLE + "/en"
23
+ MARATHON_TENNIS_LIVE = MARATHON_BASE + '/live/22723'
24
+ WILLIAMHILL_BASE = WILLIAMHILL_CHANGABLE + "/bet/en-ie"
25
+ WILLIAMHILL_LIVE = WILLIAMHILL_BASE + '/betlive/all'
26
+
27
+ def build_events(bookmakers, sport)
28
+ Downloader.prepare_phantomjs
29
+ need_to_be_structured = pull_live_events bookmakers, sport
30
+ structured_events = structure_events need_to_be_structured
31
+ print_all_events(structured_events, sport) if $config[:log]
32
+ structured_events.values.map { |addresses| Event.new(addresses, sport) }
33
+ end
34
+
35
+ def pull_live_events(bookmakers, sport)
36
+ result = {}
37
+ bookmakers.each do |bookie|
38
+ page = download_live_page_for bookie
39
+ result.merge! eval(bookie).parse_live_page(page, sport)
40
+ end
41
+ result
42
+ end
43
+
44
+ def download_live_page_for(bookie)
45
+ Downloader.download_live_page bookie
46
+ end
47
+
48
+ def structure_events(unstructured)
49
+ structured = {}
50
+ unstructured.each do |addr, names|
51
+ unless structured.key? names
52
+ structured[names] = [addr]
53
+ else
54
+ structured[names] << addr
55
+ end
56
+ end
57
+ remove_single_events structured
58
+ end
59
+
60
+ def remove_single_events(events)
61
+ events.select do |names, addresses|
62
+ addresses.size > 1
63
+ end
64
+ end
65
+
66
+ def print_all_events(events, sport)
67
+ print '=' * 20
68
+ print "V #{events.size} events of #{sport} V"
69
+ puts '=' * 20
70
+ events.each do |names, addresses|
71
+ puts names + ':'
72
+ addresses.each do |address|
73
+ puts " - #{address}"
74
+ end
75
+ end
76
+ print '=' * 20
77
+ print "^ #{events.size} events of #{sport} ^"
78
+ puts '=' * 20
79
+ end
80
+ end
@@ -0,0 +1,112 @@
1
+ class Betfair
2
+ attr_reader :live_address
3
+
4
+ def initialize
5
+ @live_address = 'http://www.betfair.com/sport/inplay'
6
+ @parsed_event = {
7
+ bookie: 'Betfair',
8
+ score: '',
9
+ home_player: Hash.new,
10
+ away_player: Hash.new
11
+ }
12
+ end
13
+
14
+ def live_page_parsed html_source
15
+ nok = Nokogiri::HTML(html_source)
16
+ links = Hash.new
17
+ nok.css('.sport-2 .section .details-event').each do |chunk|
18
+ href = ""
19
+ chunk.css('a').map {|link| href = link['href']}
20
+ domain = 'https://www.betfair.com'
21
+ href = domain + href unless href.include?(domain)
22
+ who_home = chunk.css('.home-team-name').text.strip
23
+ who_away = chunk.css('.away-team-name').text.strip
24
+ links[href] = unified_names("#{who_home} v #{who_away}")
25
+ end
26
+ links
27
+ end
28
+
29
+ def event_parsed html_source
30
+ nok = Nokogiri::HTML(html_source)
31
+ nok.css('script').remove
32
+ home_set = nok.css('.runners-table .home-header .active-set').text.strip
33
+ away_set = nok.css('.runners-table .away-header .active-set').text.strip
34
+ home_game = nok.css('.runners-table .ui-score-home').text.strip
35
+ away_game = nok.css('.runners-table .ui-score-away').text.strip
36
+ @parsed_event[:score] = "#{home_game}:#{away_game} (#{home_set}:#{away_set})"
37
+ nok.css('.list-minimarkets .mod-minimarketview').each do |event|
38
+ what = event.css('.minimarketview-header span.title').text
39
+ next if what =~ /Point|Handicap|Set Betting|Games|A Set/ or event.css('.ui-market-suspended').to_s.size > 1
40
+ target_filler(event, what, 'home')
41
+ target_filler(event, what, 'away')
42
+ end
43
+ @parsed_event[:home_player][:name] ||= 'HomePlayer'
44
+ @parsed_event[:away_player][:name] ||= 'AwayPlayer'
45
+ @parsed_event
46
+ end
47
+
48
+ private
49
+
50
+ def unified_names who
51
+ w = []
52
+ if who.include?(' v ')
53
+ who.split(' v ').each do |pl|
54
+ w += second_names_finder(pl)
55
+ end
56
+ else
57
+ w += second_names_finder(who)
58
+ end
59
+ who = ""
60
+ w.sort.each {|wh| who << wh}
61
+ who
62
+ end
63
+
64
+ def second_names_finder names
65
+ w = []
66
+ names.gsub!('-', ' ')
67
+ if names.include? ',' #remove names for beginning
68
+ ss = names.split(/,/)
69
+ w << ss[0].scan(/\w+/)[-1] #if singles play
70
+ ss.each do |s|
71
+ w << s.scan(/\w+/)[-1] if s.include? '/'
72
+ end
73
+ elsif names.include? '/'
74
+ ss = names.split(/\//)
75
+ ss.each do |s|
76
+ w << s.scan(/\w+/)[-1]
77
+ end
78
+ else
79
+ w << names.scan(/\w+/)[-1]
80
+ end
81
+ w
82
+ end
83
+
84
+ def target_filler event, what, h_or_a
85
+ case h_or_a
86
+ when 'home'
87
+ num = 0
88
+ player = :home_player
89
+ when 'away'
90
+ num = 1
91
+ player = :away_player
92
+ end
93
+ name = event.css('.minimarketview-content .runner-item .runner-name')[num]
94
+ name = name.text if name
95
+ @parsed_event[player][:name] ||= unified_names(name)
96
+ coeff = event.css('.minimarketview-content .runner-item span.ui-runner-price')[num]
97
+ if coeff
98
+ coeff = coeff.text.strip.to_f
99
+ return if coeff == 0.0
100
+ if what.include? 'Match Odds'
101
+ @parsed_event[player][:match] = coeff
102
+ elsif what.include? 'Game '
103
+ @parsed_event[player][:game] ||= Hash.new
104
+ @parsed_event[player][:game].merge!({what.scan(/\w+/)[-2] => coeff})
105
+ elsif what.include? 'Set' and what.include? 'Winner'
106
+ @parsed_event[player][:set] ||= Hash.new
107
+ @parsed_event[player][:set].merge!({what.scan(/\w+/)[-2].to_i.to_s => coeff})
108
+ end
109
+ end
110
+ end
111
+
112
+ end