travian_bot 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -1,37 +1,65 @@
1
1
  require 'selenium-webdriver'
2
- require 'travian_bot/tools'
2
+ require 'chronic'
3
+ require 'yaml'
3
4
 
4
5
  class TravianBot
5
6
  class Application
6
7
  class << self
7
- include Tools
8
8
 
9
9
  def run!(*arguments)
10
- url, user, password = get_credentials
11
- driver = Selenium::WebDriver.for :firefox
12
- driver.navigate.to(url)
10
+ login
11
+ building_queue
12
+ close
13
+
14
+ return 1
15
+ end
16
+
17
+ private
18
+
19
+ # Load the credentials from ENV['HOME']/.travian_bot
20
+ def get_credentials
21
+ credentials = YAML::load(File.open("#{ENV['HOME']}/.travian_bot"))
13
22
 
14
- # Login
15
- name_input = driver.find_element(:name, 'name')
16
- password_input = driver.find_element(:name, 'password')
17
- login_button = driver.find_element(:id, 's1')
23
+ [credentials['travian_bot']['url'], credentials['travian_bot']['usr'], credentials['travian_bot']['pwd']]
24
+ end
25
+
26
+ # Login in to travian page
27
+ def login
28
+ url, user, password = get_credentials
29
+ @driver = Selenium::WebDriver.for :firefox
30
+ @driver.navigate.to(url)
31
+ name_input = @driver.find_element(:name, 'name')
32
+ password_input = @driver.find_element(:name, 'password')
33
+ login_button = @driver.find_element(:id, 's1')
18
34
 
19
35
  name_input.send_keys(user)
20
36
  password_input.send_keys(password)
21
37
  login_button.submit
22
-
23
- # Check if building something
38
+ end
39
+
40
+ # Close the selenium connection
41
+ def close
42
+ @driver.quit
43
+ end
44
+
45
+ # Check if building something
46
+ def building_queue
24
47
  begin
25
- building_pipe = driver.find_element(:id, 'building_contract')
26
- building_time = driver.find_element(:class, 'buildingTime').text
27
- puts wait_till(building_time)
48
+ building_pipe = @driver.find_elements(:xpath, "//table[@id='building_contract']/tbody/tr")
49
+
50
+ building_pipe.each do |entry|
51
+ puts entry.text
52
+ end
28
53
  rescue Selenium::WebDriver::Error::NoSuchElementError
29
- puts 'Nothing to build'
54
+ puts 'Nothing in building queue'
30
55
  end
31
-
32
- driver.quit
56
+ end
33
57
 
34
- return 1
58
+ # Get the ending time of a string
59
+ def wait_till(input)
60
+ time = input.to_s.match(/(\d*):(\d*)$/)
61
+
62
+ Chronic.parse("today #{time[0]}:#{time[1]}")
35
63
  end
36
64
  end
37
65
  end
data/travian_bot.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "travian_bot"
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Roman Simecek"]
12
- s.date = "2011-10-23"
12
+ s.date = "2011-10-24"
13
13
  s.description = "A little bot for travian."
14
14
  s.email = "roman.simecek@cyt.ch"
15
15
  s.executables = ["travianbot"]
@@ -28,7 +28,6 @@ Gem::Specification.new do |s|
28
28
  "bin/travianbot",
29
29
  "lib/travian_bot.rb",
30
30
  "lib/travian_bot/application.rb",
31
- "lib/travian_bot/tools.rb",
32
31
  "test/helper.rb",
33
32
  "test/test_travian_bot.rb",
34
33
  "travian_bot.gemspec"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travian_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-23 00:00:00.000000000Z
12
+ date: 2011-10-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver
16
- requirement: &2165343200 !ruby/object:Gem::Requirement
16
+ requirement: &2153096620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2165343200
24
+ version_requirements: *2153096620
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: chronic
27
- requirement: &2165342140 !ruby/object:Gem::Requirement
27
+ requirement: &2153095920 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2165342140
35
+ version_requirements: *2153095920
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &2165341320 !ruby/object:Gem::Requirement
38
+ requirement: &2153095200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2165341320
46
+ version_requirements: *2153095200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &2165340160 !ruby/object:Gem::Requirement
49
+ requirement: &2153094300 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2165340160
57
+ version_requirements: *2153094300
58
58
  description: A little bot for travian.
59
59
  email: roman.simecek@cyt.ch
60
60
  executables:
@@ -74,7 +74,6 @@ files:
74
74
  - bin/travianbot
75
75
  - lib/travian_bot.rb
76
76
  - lib/travian_bot/application.rb
77
- - lib/travian_bot/tools.rb
78
77
  - test/helper.rb
79
78
  - test/test_travian_bot.rb
80
79
  - travian_bot.gemspec
@@ -93,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
92
  version: '0'
94
93
  segments:
95
94
  - 0
96
- hash: -618091492996033097
95
+ hash: 295626495803354199
97
96
  required_rubygems_version: !ruby/object:Gem::Requirement
98
97
  none: false
99
98
  requirements:
@@ -1,18 +0,0 @@
1
- require 'chronic'
2
- require 'yaml'
3
-
4
- class TravianBot
5
- module Tools
6
- def get_credentials
7
- credentials = YAML::load(File.open("#{ENV['HOME']}/.travian_bot"))
8
-
9
- [credentials['travian_bot']['url'], credentials['travian_bot']['usr'], credentials['travian_bot']['pwd']]
10
- end
11
-
12
- def wait_till(input)
13
- time = input.to_s.match(/(\d*):(\d*)$/)
14
-
15
- Chronic.parse("today #{time[0]}:#{time[1]}")
16
- end
17
- end
18
- end