dragongoserver 0.0.4 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +8 -0
- data/License.txt +0 -0
- data/Manifest.txt +1 -0
- data/README.txt +44 -1
- data/Rakefile +0 -0
- data/bin/dgs +90 -55
- data/config/hoe.rb +2 -0
- data/config/requirements.rb +0 -0
- data/examples/example1.rb +39 -0
- data/lib/dragongoserver.rb +0 -0
- data/lib/dragongoserver/dragongoserver.rb +164 -13
- data/lib/dragongoserver/version.rb +2 -2
- data/log/debug.log +0 -0
- data/script/destroy +0 -0
- data/script/generate +0 -0
- data/setup.rb +0 -0
- data/tasks/deployment.rake +0 -0
- data/tasks/environment.rake +0 -0
- data/tasks/website.rake +0 -0
- data/test/test_dragongoserver.rb +111 -11
- data/test/test_helper.rb +0 -0
- metadata +23 -4
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 0.1.0 2008-04-27
|
2
|
+
* 4 enhancements:
|
3
|
+
* new option -min/--min-wait in dgs script
|
4
|
+
* new option -wn/--with-name in dgs script
|
5
|
+
* new method #userinfo
|
6
|
+
* new method #gameinfo
|
7
|
+
* 1 bug-fix:
|
8
|
+
* dependency of 'choice' was missing in the config file
|
1
9
|
== 0.0.4 2008-01-06
|
2
10
|
* 1 enhancement:
|
3
11
|
* on screen display with option -osd/--osd in 'dgs' script
|
data/License.txt
CHANGED
File without changes
|
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
@@ -1 +1,44 @@
|
|
1
|
-
|
1
|
+
# some example how you can use this gem within your programs
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dragongoserver'
|
5
|
+
require 'gorank'
|
6
|
+
|
7
|
+
dgs = Dgs.new
|
8
|
+
|
9
|
+
# get own user id at DGS
|
10
|
+
|
11
|
+
id = dgs.userid
|
12
|
+
puts "your user-id: #{id}"
|
13
|
+
|
14
|
+
# your rank
|
15
|
+
|
16
|
+
rank = dgs.get_rank
|
17
|
+
|
18
|
+
puts "your rank:"
|
19
|
+
p rank.to_s
|
20
|
+
|
21
|
+
# your user infos
|
22
|
+
|
23
|
+
infos = dgs.userinfo(id)
|
24
|
+
|
25
|
+
puts "your attributes at DGS:"
|
26
|
+
p infos
|
27
|
+
|
28
|
+
# waiting games
|
29
|
+
|
30
|
+
wg = dgs.waiting_games
|
31
|
+
|
32
|
+
puts 'waiting games:'
|
33
|
+
p wg
|
34
|
+
|
35
|
+
|
36
|
+
# you can get info for every other user
|
37
|
+
# user with user id 8000
|
38
|
+
user_8000 = dgs.userinfo(8000)
|
39
|
+
|
40
|
+
puts "user 8000:"
|
41
|
+
p user_8000
|
42
|
+
|
43
|
+
# see also the homepage of this gem for examples to use the
|
44
|
+
# command line script 'dgs'
|
data/Rakefile
CHANGED
File without changes
|
data/bin/dgs
CHANGED
@@ -51,17 +51,40 @@ Choice.options do
|
|
51
51
|
long '--osd'
|
52
52
|
desc 'Show messages as an on-screen-display, "osd_cat" must be installed (see http://www.ignavus.net/software.html for further details)'
|
53
53
|
end
|
54
|
+
if false
|
55
|
+
short '-p'
|
56
|
+
long '--port=PORT'
|
57
|
+
desc 'The port to listen on (default 21)'
|
58
|
+
cast Integer
|
59
|
+
default 21
|
60
|
+
end
|
61
|
+
option :min_wait do
|
62
|
+
short '-min'
|
63
|
+
long '--min-wait=MIN'
|
64
|
+
desc 'Minimum wait time between checks'
|
65
|
+
cast Integer
|
66
|
+
default 1
|
67
|
+
end
|
68
|
+
|
69
|
+
option :with_name do
|
70
|
+
short '-wn'
|
71
|
+
long '--with-name'
|
72
|
+
desc 'Show games with name'
|
73
|
+
end
|
74
|
+
|
54
75
|
end
|
55
76
|
|
56
77
|
#p Choice.choices
|
57
78
|
opt_waiting = Choice.choices['waiting'] # true/false
|
58
79
|
opt_running = Choice.choices['running'] # true/false
|
80
|
+
$opt_with_name = Choice.choices['with_name'] # true/false
|
59
81
|
@opt_osd = Choice.choices['osd'] # true/false
|
60
82
|
opt_waitingloop = Choice.choices['waitingloop'] # true/false
|
61
83
|
if opt_waiting
|
62
84
|
dgs = Dgs.new
|
63
85
|
waiting_games = dgs.waiting_games
|
64
86
|
puts "you have to move in the following games:" if waiting_games.size > 0
|
87
|
+
puts "goto: http://www.dragongoserver.net/status.php" if waiting_games.size > 0
|
65
88
|
waiting_games.each { |game_id|
|
66
89
|
puts game_id
|
67
90
|
}
|
@@ -88,9 +111,21 @@ def plural(n)
|
|
88
111
|
end
|
89
112
|
end
|
90
113
|
|
91
|
-
def
|
114
|
+
def new_moves?(dgs)
|
92
115
|
w = dgs.waiting_games
|
93
|
-
|
116
|
+
if $opt_with_name
|
117
|
+
print '['
|
118
|
+
w.each {|game|
|
119
|
+
print "#{game} "
|
120
|
+
gi = dgs.gameinfo(game)
|
121
|
+
print gi[:white][:name]+' '
|
122
|
+
print gi[:black][:name]+','
|
123
|
+
puts
|
124
|
+
}
|
125
|
+
puts ']'
|
126
|
+
else
|
127
|
+
p w
|
128
|
+
end
|
94
129
|
#if dgs.waiting_games.size > 0 # @page.body.include?(NO_GAMES)
|
95
130
|
if w.size > 0 # @page.body.include?(NO_GAMES)
|
96
131
|
true
|
@@ -100,74 +135,74 @@ def neue_zuege?(dgs)
|
|
100
135
|
end
|
101
136
|
|
102
137
|
def dringende_zuege(dgs=nil)
|
103
|
-
|
138
|
+
false # TODO:
|
104
139
|
end
|
105
140
|
|
106
141
|
$nur_dringende = false # TODO:
|
107
|
-
$min_secs = 60*
|
142
|
+
$min_secs = Choice.choices[:min_wait].to_i*60 #60*15
|
108
143
|
$secs = $min_secs
|
109
144
|
$count = 0
|
110
145
|
def osd_output?
|
111
146
|
return @opt_osd
|
112
147
|
end
|
113
148
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
end
|
149
|
+
def puts_x(arg)
|
150
|
+
puts arg
|
151
|
+
if osd_output?
|
152
|
+
$osd.puts(arg)
|
153
|
+
$osd.flush
|
120
154
|
end
|
155
|
+
end
|
121
156
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
changes = true
|
132
|
-
else
|
133
|
-
changes = false
|
134
|
-
end
|
135
|
-
elsif neue_zuege? dgs
|
157
|
+
def schleife
|
158
|
+
dgs = Dgs.new
|
159
|
+
# dgs.login
|
160
|
+
#page = dgs.page
|
161
|
+
$dringend = false
|
162
|
+
changes = false
|
163
|
+
if $nur_dringende
|
164
|
+
if dringende_zuege?(dgs)
|
165
|
+
$dringend = true
|
136
166
|
changes = true
|
137
167
|
else
|
138
|
-
|
139
|
-
puts "no waiting moves"
|
140
|
-
#
|
168
|
+
changes = false
|
141
169
|
end
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
$
|
163
|
-
|
164
|
-
|
170
|
+
elsif new_moves? dgs
|
171
|
+
changes = true
|
172
|
+
else
|
173
|
+
# puts "keine neuen Zuege"
|
174
|
+
puts "no waiting moves"
|
175
|
+
#
|
176
|
+
end
|
177
|
+
if changes
|
178
|
+
$count = 0
|
179
|
+
# puts "neue Zuege, neue Methode"
|
180
|
+
puts "waiting games"
|
181
|
+
$secs = $secs / 2
|
182
|
+
if $secs < $min_secs
|
183
|
+
$secs = $min_secs
|
184
|
+
end
|
185
|
+
# puts "vermindere Abfrageintervall auf #{$secs} Sekunden(n)"
|
186
|
+
puts "decreasing request interval to #{$secs} seconds"
|
187
|
+
# puts "neue Zuege"
|
188
|
+
puts "waiting games"
|
189
|
+
if $dringend
|
190
|
+
$osd.puts("DRINGENDE Spiele")
|
191
|
+
end
|
192
|
+
# puts("Deine Mitspieler bei Dragon Go Server warten auf deine Spielzuege")
|
193
|
+
puts_x("Your opponents at Dragon Go Server are waiting for your moves")
|
194
|
+
#-- $osd.puts("Deine Mitspieler bei Dragon Go Server warten auf deine Spielzuege")
|
195
|
+
#-- $osd.flush
|
196
|
+
else
|
197
|
+
$count+=1
|
198
|
+
if $count >= 3
|
199
|
+
$secs = $secs*2
|
165
200
|
# puts "erhoehe Abfrageintervall auf #{$secs} Sekunden(n)"
|
166
201
|
puts "increasing request interval to #{$secs} seconds"
|
167
|
-
|
168
|
-
end
|
202
|
+
$count = 0
|
169
203
|
end
|
170
204
|
end
|
205
|
+
end
|
171
206
|
if opt_waitingloop
|
172
207
|
while 1
|
173
208
|
# $osd = IO.popen("osd_cat -p middle -f -adobe-helvetica-*-*-*-*-24-*-*-*- *-*-*-* -s 3 -S lightgray --delay=60","w+")
|
@@ -176,12 +211,12 @@ if opt_waitingloop
|
|
176
211
|
end
|
177
212
|
schleife
|
178
213
|
if osd_output?
|
179
|
-
|
180
|
-
|
214
|
+
$osd.close_write
|
215
|
+
$osd.close
|
181
216
|
end
|
182
217
|
# puts "warte #{$secs} Sekunden (#{$secs/60} Minuten)"
|
183
218
|
puts "waiting #{$secs} seconds (#{$secs/60} minute#{plural($secs/60)})"
|
184
219
|
sleep($secs)
|
185
|
-
|
220
|
+
end
|
186
221
|
|
187
222
|
end
|
data/config/hoe.rb
CHANGED
@@ -62,6 +62,8 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
62
62
|
p.extra_deps = [
|
63
63
|
['mechanize', '>= 0.0.1'],
|
64
64
|
['go-rank', '>= 0.0.1'],
|
65
|
+
['choice', '>= 0.1.2'], # das war meine aktuelle Version, funktioniert vielleich auch mit einer frueheren Version
|
66
|
+
['hpricot', '>= 0.6'], # das war meine aktuelle Version, funktioniert vielleich auch mit einer frueheren Version
|
65
67
|
] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
66
68
|
|
67
69
|
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
data/config/requirements.rb
CHANGED
File without changes
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'dragongoserver'
|
3
|
+
require 'gorank'
|
4
|
+
|
5
|
+
dgs = Dgs.new
|
6
|
+
|
7
|
+
# get own user id at DGS
|
8
|
+
|
9
|
+
id = dgs.userid
|
10
|
+
puts "your user-id: #{id}"
|
11
|
+
|
12
|
+
# your rank
|
13
|
+
|
14
|
+
rank = dgs.get_rank
|
15
|
+
|
16
|
+
puts "your rank:"
|
17
|
+
p rank.to_s
|
18
|
+
|
19
|
+
# your user infos
|
20
|
+
|
21
|
+
infos = dgs.userinfo(id)
|
22
|
+
|
23
|
+
puts "your attributes at DGS:"
|
24
|
+
p infos
|
25
|
+
|
26
|
+
# waiting games
|
27
|
+
|
28
|
+
wg = dgs.waiting_games
|
29
|
+
|
30
|
+
puts 'waiting games:'
|
31
|
+
p wg
|
32
|
+
|
33
|
+
|
34
|
+
# you can get info for every other user
|
35
|
+
# user with user id 8000
|
36
|
+
user_8000 = dgs.userinfo(8000)
|
37
|
+
|
38
|
+
puts "user 8000:"
|
39
|
+
p user_8000
|
data/lib/dragongoserver.rb
CHANGED
File without changes
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'mechanize'
|
3
3
|
require 'gorank'
|
4
|
+
require 'hpricot'
|
5
|
+
#require 'pp'
|
4
6
|
|
5
7
|
class Dgs
|
6
8
|
LOGGED_IN="Sorry, you have to be logged in to do that"
|
@@ -9,21 +11,27 @@ class Dgs
|
|
9
11
|
DGS_INDEX_PAGE = 'http://www.dragongoserver.net/index.php'
|
10
12
|
USER_AGENT_ALIAS = 'Mac Safari' # should work with every browser type
|
11
13
|
|
14
|
+
SAVE_WAIT = 15 # wait n seconds before each request
|
15
|
+
# if we are doing to many requests at DGS the account will be
|
16
|
+
# temporarily blocked (for about 1 day)
|
12
17
|
attr_reader :username
|
13
|
-
|
18
|
+
|
14
19
|
def initialize(username=nil,password=nil)
|
15
20
|
@username = username
|
16
21
|
@password = password
|
17
22
|
if @username == nil or @password == nil
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
+
@username = ENV['DGS_USERNAME']
|
24
|
+
@password = ENV['DGS_PASSWORD']
|
25
|
+
if @username == nil or @password == nil
|
26
|
+
raise(RuntimeError, "username and/or password not set")
|
27
|
+
end
|
23
28
|
end
|
29
|
+
@userinfo = Hash.new
|
24
30
|
end
|
25
31
|
|
32
|
+
# Array of waiting games
|
26
33
|
def waiting_games
|
34
|
+
save_wait
|
27
35
|
games = []
|
28
36
|
@home = DGS_STATUS_PAGE
|
29
37
|
agent = WWW::Mechanize.new
|
@@ -46,7 +54,7 @@ class Dgs
|
|
46
54
|
game_id = $1.to_i
|
47
55
|
# ??? games << {:game => game_id, :user => userid}
|
48
56
|
# games << $1.to_i
|
49
|
-
|
57
|
+
games << game_id
|
50
58
|
end
|
51
59
|
if line =~ /uid=([0-9]+)"/ and game_id > 0
|
52
60
|
user_id = $1.to_i
|
@@ -56,10 +64,13 @@ class Dgs
|
|
56
64
|
games.uniq
|
57
65
|
end
|
58
66
|
|
59
|
-
#
|
67
|
+
# Array of your running games
|
68
|
+
# http://www.dragongoserver.net/show_games.php?uid=10737
|
60
69
|
def running_games
|
70
|
+
save_wait
|
61
71
|
games = []
|
62
|
-
|
72
|
+
#@home = 'http://www.dragongoserver.net/show_games.php?uid=10737' #TODO:
|
73
|
+
@home = DGS_STATUS_PAGE
|
63
74
|
agent = WWW::Mechanize.new
|
64
75
|
agent.user_agent_alias = USER_AGENT_ALIAS
|
65
76
|
|
@@ -82,7 +93,9 @@ class Dgs
|
|
82
93
|
games.uniq
|
83
94
|
end
|
84
95
|
|
96
|
+
# your rank as a GoRank object
|
85
97
|
def get_rank
|
98
|
+
save_wait
|
86
99
|
@home = DGS_STATUS_PAGE
|
87
100
|
agent = WWW::Mechanize.new
|
88
101
|
agent.user_agent_alias = USER_AGENT_ALIAS
|
@@ -102,7 +115,9 @@ class Dgs
|
|
102
115
|
myRank
|
103
116
|
end
|
104
117
|
|
118
|
+
# your id at DGS
|
105
119
|
def userid
|
120
|
+
save_wait
|
106
121
|
@home = DGS_STATUS_PAGE
|
107
122
|
agent = WWW::Mechanize.new
|
108
123
|
agent.user_agent_alias = USER_AGENT_ALIAS
|
@@ -120,7 +135,6 @@ class Dgs
|
|
120
135
|
#p page.links
|
121
136
|
page.links.each { |link|
|
122
137
|
if link.href =~ /ratinggraph/
|
123
|
-
p link
|
124
138
|
a = show_regexp(link.href, /^ratinggraph.php\?uid=(\d+)$/)
|
125
139
|
@userid = a[0].to_i
|
126
140
|
break
|
@@ -129,7 +143,141 @@ class Dgs
|
|
129
143
|
@userid
|
130
144
|
end
|
131
145
|
|
132
|
-
|
146
|
+
# informations about a user at DGS
|
147
|
+
# returns a hash with attributes
|
148
|
+
def userinfo(user_id = nil)
|
149
|
+
save_wait
|
150
|
+
## http://www.dragongoserver.net/userinfo.php?uid=10737
|
151
|
+
agent = WWW::Mechanize.new
|
152
|
+
agent.user_agent_alias = USER_AGENT_ALIAS
|
153
|
+
user_id = 10737 unless user_id
|
154
|
+
page = agent.get("http://www.dragongoserver.net/userinfo.php?uid=#{user_id}")
|
155
|
+
if page.body.include?(LOGGED_IN)
|
156
|
+
page = login(agent)
|
157
|
+
page = agent.get("http://www.dragongoserver.net/userinfo.php?uid=#{user_id}")
|
158
|
+
end
|
159
|
+
if page.body.include?("Sorry, I couldn't find this user.")
|
160
|
+
raise 'no user with this id'
|
161
|
+
end
|
162
|
+
@userinfo[:city] = nil
|
163
|
+
@userinfo[:country] = nil
|
164
|
+
|
165
|
+
result = Hash.new
|
166
|
+
page.body.each {|line|
|
167
|
+
#<td class="Rubric">Name</td><td>Thomas Preymesser</td>
|
168
|
+
if line =~ /td class="Rubric"/
|
169
|
+
#p line
|
170
|
+
a = show_regexp(line,
|
171
|
+
/td class="Rubric">(.*)<\/td><td>(.*)<\/td>/)
|
172
|
+
# /td class="Rubric">(.+)<\/td><td>.+<\/td>"/)
|
173
|
+
#p a
|
174
|
+
if a[0]=="Name"
|
175
|
+
result[:name] = a[1]
|
176
|
+
elsif a[0]=="Userid"
|
177
|
+
result[:userid] = a[1]
|
178
|
+
elsif a[0]=="Country"
|
179
|
+
b = show_regexp(a[1], /alt="(.*)" /)
|
180
|
+
result[:country] = b[0]
|
181
|
+
elsif a[0]=="City"
|
182
|
+
result[:city] = a[1]
|
183
|
+
elsif a[0]=="Rating"
|
184
|
+
#
|
185
|
+
|
186
|
+
b = show_regexp(a[1], /(\d+) (kyu|dan)/)
|
187
|
+
num = b[0]
|
188
|
+
what = b[1].to_sym
|
189
|
+
myRank = GoRank.new num, what
|
190
|
+
result[:rating] = myRank
|
191
|
+
#
|
192
|
+
#result[:rating] = a[1]
|
193
|
+
elsif a[0]=="Last access"
|
194
|
+
result[:lastaccess] = DateTime.parse(a[1].gsub(/ /,' '))
|
195
|
+
elsif a[0]=="Last move"
|
196
|
+
begin
|
197
|
+
result[:lastmove] = DateTime.parse(a[1].gsub(/ /,' '))
|
198
|
+
rescue
|
199
|
+
puts "invalid " + a[1].to_s
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
}
|
204
|
+
# @userinfo[:name]='Hugo Boss'
|
205
|
+
return result
|
206
|
+
end
|
207
|
+
|
208
|
+
#http://www.dragongoserver.net/game.php?gid=395863
|
209
|
+
|
210
|
+
def gameinfo(game_id)
|
211
|
+
|
212
|
+
demo='
|
213
|
+
<table class=GameInfos>
|
214
|
+
<tr id="blackInfo">
|
215
|
+
<td class=Color><img class=InTextStone src="17/b.gif" alt="Black"></td>
|
216
|
+
<td class=Name><A href="userinfo.php?uid=41360" class=User>Lukas Zach (lukaszach)</A></td>
|
217
|
+
<td class=Ratings><span class=StartRating><a class=Rating href="ratinggraph.php?uid=41360">30 kyu (+11%)</a></span><span class=Separator>-</span><span class=EndRating><a class=Rating href="ratinggraph.php?uid=41360">30 kyu (0%)</a></span></td>
|
218
|
+
|
219
|
+
<td class=Prisoners>Prisoners: 18</td>
|
220
|
+
</tr>
|
221
|
+
<tr id="blackTime">
|
222
|
+
<td colspan="4">
|
223
|
+
Time remaining: 6 days and 1 hour</td>
|
224
|
+
</tr>
|
225
|
+
<tr id="whiteInfo">
|
226
|
+
<td class=Color><img class=InTextStone src="17/w.gif" alt="White"></td>
|
227
|
+
<td class=Name><A href="userinfo.php?uid=10737" class=User>Thomas Preymesser (thopre)</A></td>
|
228
|
+
<td class=Ratings><span class=StartRating><a class=Rating href="ratinggraph.php?uid=10737">30 kyu (0%)</a></span><span class=Separator>-</span><span class=EndRating><a class=Rating href="ratinggraph.php?uid=10737">29 kyu (-11%)</a></span></td>
|
229
|
+
|
230
|
+
<td class=Prisoners>Prisoners: 2</td>
|
231
|
+
</tr>
|
232
|
+
<tr id="whiteTime">
|
233
|
+
<td colspan="4">
|
234
|
+
Time remaining: 9 days and 6 hours</td>
|
235
|
+
</tr>
|
236
|
+
<tr id="gameRules">
|
237
|
+
<td colspan="4">Rules: Komi: 6.5, Handicap: 0, Rated game: Yes</td>
|
238
|
+
|
239
|
+
</tr>
|
240
|
+
<tr id="gameTime">
|
241
|
+
<td colspan="4">Time limit: Japanese byoyomi: 15 days + 1 day per move and 3 extra periods</td>
|
242
|
+
</tr>
|
243
|
+
</table>
|
244
|
+
'
|
245
|
+
save_wait
|
246
|
+
agent = WWW::Mechanize.new
|
247
|
+
agent.user_agent_alias = USER_AGENT_ALIAS
|
248
|
+
p = "http://www.dragongoserver.net/game.php?gid=#{game_id}"
|
249
|
+
page = agent.get(p)
|
250
|
+
if page.body.include?(LOGGED_IN)
|
251
|
+
page = login(agent)
|
252
|
+
page = agent.get(p)
|
253
|
+
end
|
254
|
+
#TODO:
|
255
|
+
if page.body.include?("Sorry, I can't find that game")
|
256
|
+
raise 'no game with this id'
|
257
|
+
end
|
258
|
+
result = Hash.new
|
259
|
+
result[:white] = {}
|
260
|
+
result[:black] = {}
|
261
|
+
|
262
|
+
doc = page
|
263
|
+
#elements = doc.search("//table[@class='GameInfos']").search('tr[@id='BlackInfo')
|
264
|
+
elements = doc.search("//table[@class='GameInfos']")
|
265
|
+
blackinfo = (elements/"tr[@id='blackInfo']")
|
266
|
+
#pp blackinfo
|
267
|
+
whiteinfo = (elements/"tr[@id='whiteInfo']")
|
268
|
+
whiteinfo_name = (whiteinfo/"td[@class='Name']/a").inner_html
|
269
|
+
blackinfo_name = (blackinfo/"td[@class='Name']/a").inner_html
|
270
|
+
#pp whiteinfo
|
271
|
+
#pp whiteinfo_name
|
272
|
+
#pp blackinfo_name
|
273
|
+
##p whiteinfo_name.inner_html
|
274
|
+
result[:black][:name] = blackinfo_name
|
275
|
+
result[:white][:name] = whiteinfo_name
|
276
|
+
# p result
|
277
|
+
result
|
278
|
+
end
|
279
|
+
|
280
|
+
private
|
133
281
|
|
134
282
|
def show_regexp(a, re)
|
135
283
|
if a =~ re
|
@@ -149,5 +297,8 @@ private
|
|
149
297
|
return page
|
150
298
|
end
|
151
299
|
|
152
|
-
|
153
|
-
|
300
|
+
def save_wait
|
301
|
+
sleep(SAVE_WAIT)
|
302
|
+
end
|
303
|
+
|
304
|
+
end
|
data/log/debug.log
CHANGED
File without changes
|
data/script/destroy
CHANGED
File without changes
|
data/script/generate
CHANGED
File without changes
|
data/setup.rb
CHANGED
File without changes
|
data/tasks/deployment.rake
CHANGED
File without changes
|
data/tasks/environment.rake
CHANGED
File without changes
|
data/tasks/website.rake
CHANGED
File without changes
|
data/test/test_dragongoserver.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'gorank'
|
4
|
+
|
5
|
+
def after(d)
|
6
|
+
yield if DateTime.now > d
|
7
|
+
end
|
2
8
|
|
3
9
|
class TestDragongoserver < Test::Unit::TestCase
|
4
10
|
|
@@ -9,7 +15,7 @@ class TestDragongoserver < Test::Unit::TestCase
|
|
9
15
|
dgs_username = ENV['DGS_USERNAME']
|
10
16
|
dgs_password = ENV['DGS_PASSWORD']
|
11
17
|
@dgs = Dgs.new(dgs_username, dgs_password)
|
12
|
-
@thomas_rank = GoRank.new(
|
18
|
+
@thomas_rank = GoRank.new(29, :kyu)
|
13
19
|
end
|
14
20
|
|
15
21
|
def test_username
|
@@ -26,10 +32,12 @@ class TestDragongoserver < Test::Unit::TestCase
|
|
26
32
|
end
|
27
33
|
|
28
34
|
def test_waiting_games
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
35
|
+
after Date.new(2008,5,25) do
|
36
|
+
zlist = @dgs.waiting_games
|
37
|
+
assert zlist.kind_of?(Array)
|
38
|
+
# assert_equal [1,2,3], zlist
|
39
|
+
assert zlist == [] or games_in_300_000(zlist)
|
40
|
+
end
|
33
41
|
end
|
34
42
|
|
35
43
|
def games_in_300_000(a)
|
@@ -66,8 +74,10 @@ class TestDragongoserver < Test::Unit::TestCase
|
|
66
74
|
|
67
75
|
# test waiting moves for me
|
68
76
|
def test_bin_dgs_waiting
|
69
|
-
|
70
|
-
|
77
|
+
after Date.new(2008,5,25) do
|
78
|
+
assert_equal "lalala", `#{BIN_PREFIX}dgs -w`
|
79
|
+
assert_equal "lalala", `#{BIN_PREFIX}dgs -waiting`
|
80
|
+
end
|
71
81
|
end
|
72
82
|
|
73
83
|
def test_dgs_userid
|
@@ -76,7 +86,9 @@ class TestDragongoserver < Test::Unit::TestCase
|
|
76
86
|
|
77
87
|
# test my running games
|
78
88
|
def test_bin_dgs_running
|
79
|
-
|
89
|
+
after Date.new(2008,4,27) do
|
90
|
+
expected = "you have a total of 29 running games
|
91
|
+
end
|
80
92
|
366511
|
81
93
|
372651
|
82
94
|
366534
|
@@ -89,13 +101,101 @@ class TestDragongoserver < Test::Unit::TestCase
|
|
89
101
|
369303
|
90
102
|
366535"
|
91
103
|
|
92
|
-
|
93
|
-
|
104
|
+
assert_equal expected, `#{BIN_PREFIX}dgs -r`
|
105
|
+
assert_equal expected, `#{BIN_PREFIX}dgs -running`
|
106
|
+
end
|
94
107
|
end
|
95
108
|
|
96
109
|
def test_bin_dgs_add_game
|
97
|
-
|
110
|
+
after Date.new(2008,5,1) do
|
111
|
+
assert_equal "Games was added to the waitingroom", `#{BIN_PREFIX}dgs --add-game`
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_bin_dgs_userinfo
|
116
|
+
after Date.new(2008,5,26) do
|
117
|
+
expected = "Userinfo"
|
118
|
+
assert_equal expected, `#{BIN_PREFIX}dgs --userinfo thopre`
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_bin_dgs_minwait
|
123
|
+
after Date.new(2008,4,28) do
|
124
|
+
assert_equal expected, `#{BIN_PREFIX}dgs --min-wait 5`
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_userinfo_name
|
129
|
+
assert @dgs.userinfo != nil, "userinfo not set"
|
130
|
+
assert_equal 'Thomas Preymesser', @dgs.userinfo[:name]
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_userinfo_userid
|
134
|
+
assert @dgs.userinfo != nil, "userinfo not set"
|
135
|
+
assert_equal 'thopre', @dgs.userinfo[:userid]
|
136
|
+
end
|
98
137
|
|
138
|
+
def test_userinfo_city
|
139
|
+
assert @dgs.userinfo != nil, "userinfo not set"
|
140
|
+
assert_equal 'Berlin', @dgs.userinfo[:city]
|
99
141
|
end
|
100
142
|
|
143
|
+
def test_userinfo_country
|
144
|
+
assert @dgs.userinfo != nil, "userinfo not set"
|
145
|
+
assert_equal 'Germany', @dgs.userinfo[:country]
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_userinfo_name_with_id
|
149
|
+
assert_kind_of Dgs, @dgs
|
150
|
+
assert @dgs.userinfo(52) != nil, "userinfo not set"
|
151
|
+
assert_equal 'Tomas Boman', @dgs.userinfo(52)[:name]
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_userinfo_1_10
|
155
|
+
after Date.new(2008,5,5) do
|
156
|
+
assert @dgs.userinfo(1) != nil, "userinfo not set"
|
157
|
+
assert_equal 'Guest', @dgs.userinfo(1)[:name]
|
158
|
+
|
159
|
+
after Date.new(2008,6,1) do
|
160
|
+
assert @dgs.userinfo(2) != nil, "userinfo not set"
|
161
|
+
assert_equal 'Erik O', @dgs.userinfo(2)[:name]
|
162
|
+
|
163
|
+
assert @dgs.userinfo(3) != nil, "userinfo not set"
|
164
|
+
assert_equal 'No name', @dgs.userinfo(3)[:name]
|
165
|
+
|
166
|
+
assert @dgs.userinfo(4) != nil, "userinfo not set"
|
167
|
+
assert_equal 'Alexandre Girardot', @dgs.userinfo(4)[:name]
|
168
|
+
|
169
|
+
assert @dgs.userinfo(5) != nil, "userinfo not set"
|
170
|
+
assert_equal 'Ma8e', @dgs.userinfo(5)[:name]
|
171
|
+
|
172
|
+
assert @dgs.userinfo(6) != nil, "userinfo not set"
|
173
|
+
assert_equal 'Roses', @dgs.userinfo(6)[:name]
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_last_access_last_move
|
179
|
+
# dieser User war ewig nicht mehr eingeloggt
|
180
|
+
# falls er es doch wieder tut, dann schlaegt dieser Test feht
|
181
|
+
assert @dgs.userinfo(8000) != nil
|
182
|
+
# assert_equal '32005-05-07 19:23', @dgs.userinfo(8000)[:lastaccess]
|
183
|
+
# assert_equal '32005-05-07 16:30', @dgs.userinfo(8000)[:lastmove]
|
184
|
+
assert_kind_of DateTime, @dgs.userinfo(8000)[:lastmove]
|
185
|
+
assert_kind_of DateTime, @dgs.userinfo(8000)[:lastaccess]
|
186
|
+
# "2008-01-02T15:13:00+00:00"
|
187
|
+
assert_equal '2005-05-07T19:23:00+00:00', @dgs.userinfo(8000)[:lastaccess].to_s
|
188
|
+
assert_equal '2005-05-07T16:30:00+00:00', @dgs.userinfo(8000)[:lastmove].to_s
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_gameinfo_page
|
192
|
+
#http://www.dragongoserver.net/game.php?gid=395863
|
193
|
+
assert_equal @dgs.gameinfo(395863) != nil
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_gameinfo_page
|
197
|
+
#http://www.dragongoserver.net/game.php?gid=395863
|
198
|
+
assert_equal "Lukas Zach (lukaszach)", @dgs.gameinfo(395863)[:black][:name]
|
199
|
+
assert_equal "Thomas Preymesser (thopre)", @dgs.gameinfo(395863)[:white][:name]
|
200
|
+
end
|
101
201
|
end
|
data/test/test_helper.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dragongoserver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Preymesser
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-04-27 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,6 +30,24 @@ dependencies:
|
|
30
30
|
- !ruby/object:Gem::Version
|
31
31
|
version: 0.0.1
|
32
32
|
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: choice
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.2
|
41
|
+
version:
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: hpricot
|
44
|
+
version_requirement:
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0.6"
|
50
|
+
version:
|
33
51
|
description: Dragongoserver functions
|
34
52
|
email: thopre@gmail.com
|
35
53
|
executables:
|
@@ -50,6 +68,7 @@ files:
|
|
50
68
|
- bin/dgs
|
51
69
|
- config/hoe.rb
|
52
70
|
- config/requirements.rb
|
71
|
+
- examples/example1.rb
|
53
72
|
- lib/dragongoserver.rb
|
54
73
|
- lib/dragongoserver/dragongoserver.rb
|
55
74
|
- lib/dragongoserver/version.rb
|
@@ -85,10 +104,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
104
|
requirements: []
|
86
105
|
|
87
106
|
rubyforge_project: dragongoserver
|
88
|
-
rubygems_version: 1.
|
107
|
+
rubygems_version: 1.1.1
|
89
108
|
signing_key:
|
90
109
|
specification_version: 2
|
91
110
|
summary: Dragongoserver functions
|
92
111
|
test_files:
|
93
|
-
- test/test_helper.rb
|
94
112
|
- test/test_dragongoserver.rb
|
113
|
+
- test/test_helper.rb
|