-
Notifications
You must be signed in to change notification settings - Fork 0
/
bet.rb
101 lines (79 loc) · 1.96 KB
/
bet.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
require 'open-uri'
require 'nokogiri'
require 'mongo'
require 'watir-webdriver'
require 'mechanize'
require 'mongo'
$i=1
$Limit=2.0
$doBet=false
$oddsWanted = []
def write_in_mongo(doc)
collection = $client[:bets]
result = collection.insert_one(doc)
puts result.n
end
#/div/div/div/div/div/input
def click(i)
$b.li(:onclick => i.to_s).when_present.click
end
def Bet(doc,b)
=begin
b.td(:id, 'stakebox_2').set '1'
puts doc.search('div/input').xpath('@id')
sleep(10)
doc = Nokogiri::HTML.parse(b.html)
puts doc.search('td').xpath('text()')
=end
#/html/body/div[5]/div[3]/div[2]/div[2]/div/div[1]/div[1]/div/ul/li[1]/div[1]/div[2]
end
def retrive_wanted_odds(h)
h.each {
|i|
if $doBet==false
unless i.to_s.split(',')[4].to_f > 1.30 #if it's the odd we are interested in
if i.to_s.split(',')[4].to_s.include? '.' # if doesn't have the comma we don't want it
$i*= i.to_s.split(',')[4].to_f #total of cotas
#$oddsWanted << i
puts i
click(i)
puts $i
puts $doBet
if $i>$Limit
puts 'true'
$doBet=true
break
end
end
end
end
}
return $oddsWanted
end
def read_page(h)
unless $doBet == true
$b.li(:id => "#{h}").fire_event :onclick
sleep(10)
$doc = Nokogiri::HTML.parse($b.html)
# puts "###############################################################"
# puts "############# Basquetebol ###################"
# puts "###############################################################"
$h1 = $doc.search('li').xpath('@onclick')
puts retrive_wanted_odds($h1)
end
end
########################################################
$b = Watir::Browser.new
$b.goto 'https://www.bet.pt/todays-events/'
#/html/body/div[5]/div[3]/div[2]/div[1]/div[2]/div/ul/li[1]/ul/li
$doc = Nokogiri::HTML.parse($b.html)
$h2 = $doc.search('li/ul/li').xpath('@id')
#puts $h2
$h2.each { |x|
if(x.to_s.include? "tp")
read_page(x.to_s)
end
}
# if($doBet)
Bet($doc,$b)
# end