wtth 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ coverage
2
+ rdoc
3
+ pkg
@@ -0,0 +1,18 @@
1
+ = Welcome to the Horde
2
+
3
+ This is a program that watches {HVZ Source}[http://humansvszombies.org/] and posts messages to {Twitter}[http://twitter.com/] when people are zombified. See {@wtthumd}[http://twitter.com/wtthumd] for an example(game starts 2009-09-27 at about 22:00).
4
+
5
+ Please only run one WTTH or similar per game. Check to see if your game already has one before starting your own. Nothing is gained by running duplicates, and it wastes the resources of Twitter and HVZ Source.
6
+
7
+ == Installation
8
+ WTTH is written in {Ruby}[http://www.ruby-lang.org/] and requires the {nokogiri}[http://nokogiri.rubyforge.org/] and {twitter}[http://twitter.rubyforge.org/] {gems}[http://docs.rubygems.org/].
9
+
10
+ WTTH now has a gem in {Gemcutter}[http://gemcutter.org/] and can be installed as <tt>wtth</tt>. This should install all the dependencies and put <tt>wtth</tt> into your path like magic. If you'd previously installed <tt>mdonoughe-wtth</tt> from Github's gem service, you should uninstall that version before installing the new one.
11
+
12
+ After you've gotten everything installed, run <tt>wtth init</tt> to give the program access to a Twitter account. I'd suggest not using your usual Twitter account for this.
13
+
14
+ Running <tt>wtth init</tt> will create a file called <tt>.wtth.yml</tt> in your home directory. You'll want to open that and change <tt>player_list_uri</tt> to point at the correct HVZ Source page for your game.
15
+
16
+ You'll probably want to make some sort of cron job to run <tt>wtth</tt>. It makes at most one request to HVZ Source and posts at most one message to Twitter per run. Set this to a responsible interval. You can probably get away with as low as once a minute, but that's completely unnecessary in my opinion.
17
+
18
+ Please remember not to have the cron job running when the game is not in session.
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "wtth"
8
+ gem.summary = %Q{Watches humans vs. zombies games and tweets new zombies.}
9
+ gem.description = %Q{Welcome to the Horde is a program that tweets when people join the zombie horde(in humans vs. zombies).}
10
+ gem.email = "mdonoughe@gmail.com"
11
+ gem.homepage = "http://github.com/mdonoughe/wtth"
12
+ gem.authors = ["Matthew Donoughe"]
13
+ gem.add_development_dependency "shoulda"
14
+ gem.add_runtime_dependency "nokogiri", ">= 1.0.0"
15
+ gem.add_runtime_dependency "twitter", ">= 0.5.0"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/*_test.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/*_test.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install relevance-rcov"
40
+ end
41
+ end
42
+
43
+ task :test => :check_dependencies
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ if File.exist?('VERSION')
50
+ version = File.read('VERSION')
51
+ else
52
+ version = ""
53
+ end
54
+
55
+ rdoc.rdoc_dir = 'rdoc'
56
+ rdoc.title = "wtth #{version}"
57
+ rdoc.rdoc_files.include('README*')
58
+ rdoc.rdoc_files.include('lib/**/*.rb')
59
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.3.0
data/bin/wtth CHANGED
@@ -1,69 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems'
4
- require 'net/http'
5
- require 'nokogiri'
6
- require 'twitter'
7
- require 'yaml'
3
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'wtth')
8
4
 
9
- wtth_path = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'wtth')
10
- require File.join(wtth_path, 'config')
11
- require File.join(wtth_path, 'hvzsource')
12
- require File.join(wtth_path, 'twitter')
13
-
14
- module WTTH
15
- VERSION = '1.2.1'
16
- load_config
17
-
18
- if ARGV.length > 0 and ARGV[0] == 'init'
19
- twitter_init
20
- exit 0
21
- end
22
-
23
- unless twitter_is_authorized?
24
- puts 'You have not yet authorized WTTH to access Twitter.'
25
- puts 'Please run `wtth init` first'
26
- exit 1
27
- end
28
-
29
- # get new zombies and zombies that weren't reported last time
30
- to_welcome = CONFIG[:backlog]
31
- if to_welcome == nil
32
- to_welcome = get_new_zombies
33
- elsif to_welcome.join(', ').length < 140
34
- to_welcome = get_new_zombies + to_welcome
35
- end
36
-
37
- if to_welcome != []
38
- this_batch = []
39
- recovery = []
40
- size = 0
41
-
42
- # get the least recent kills, no more than 140 characters worth
43
- until size > 140 or to_welcome.empty?
44
- zombie = to_welcome.last
45
- size += zombie.length
46
- size += 2 if this_batch.length > 0
47
- if size <= 140
48
- this_batch << zombie
49
- recovery << to_welcome.pop
50
- end
51
- end
52
-
53
- # remember who we haven't reported
54
- CONFIG[:backlog] = to_welcome
55
-
56
- # welcome with the most recent first so things are in order on twitter
57
- this_batch.reverse!
58
-
59
- begin
60
- tweet(this_batch.join(', '))
61
- rescue Twitter::TwitterError
62
- puts "TwitterError #{$!}"
63
- # throw the message onto the backlog so we can try again next time
64
- CONFIG[:backlog] = to_welcome + recovery.reverse
65
- end
66
- end
67
-
68
- save_config
5
+ if ARGV.length > 0 and ARGV[0] == 'init'
6
+ WTTH::init
7
+ else
8
+ WTTH::update
69
9
  end
@@ -0,0 +1,74 @@
1
+ require 'rubygems'
2
+ require 'net/http'
3
+ require 'nokogiri'
4
+ require 'twitter'
5
+ require 'yaml'
6
+
7
+ wtth_path = File.join(File.expand_path(File.dirname(__FILE__)), 'wtth')
8
+ require File.join(wtth_path, 'config')
9
+ require File.join(wtth_path, 'hvzsource')
10
+ require File.join(wtth_path, 'twitter')
11
+
12
+ module WTTH
13
+ VERSION = '1.2.1'
14
+
15
+ def self.init
16
+ load_config
17
+ twitter_init
18
+ end
19
+
20
+ def self.update
21
+ load_config
22
+
23
+ unless twitter_is_authorized?
24
+ puts 'You have not yet authorized WTTH to access Twitter.'
25
+ puts 'Please run `wtth init` first'
26
+ exit 1
27
+ end
28
+
29
+ # get new zombies and zombies that weren't reported last time
30
+ to_welcome = CONFIG[:backlog]
31
+ if to_welcome == nil
32
+ to_welcome = get_new_zombies
33
+ elsif to_welcome.join(', ').length < 140
34
+ to_welcome = get_new_zombies + to_welcome
35
+ end
36
+
37
+ if to_welcome != []
38
+ this_batch = []
39
+ recovery = []
40
+ size = 0
41
+
42
+ # get the least recent kills, no more than 140 characters worth
43
+ until size > 140 or to_welcome.empty?
44
+ zombie = to_welcome.last
45
+ size += zombie.length
46
+ size += 2 if this_batch.length > 0
47
+ if size <= 140
48
+ this_batch << zombie
49
+ recovery << to_welcome.pop
50
+ end
51
+ end
52
+
53
+ # remember who we haven't reported
54
+ CONFIG[:backlog] = to_welcome
55
+
56
+ # welcome with the most recent first so things are in order on twitter
57
+ this_batch.reverse!
58
+
59
+ begin
60
+ tweet(this_batch.join(', '))
61
+ rescue Twitter::TwitterUnavailable
62
+ puts "TwitterUnavailable #{$!}"
63
+ # throw the message onto the backlog so we can try again next time
64
+ CONFIG[:backlog] = to_welcome + recovery.reverse
65
+ rescue Twitter::TwitterError
66
+ puts "TwitterError #{$!}"
67
+ # throw the message onto the backlog so we can try again next time
68
+ CONFIG[:backlog] = to_welcome + recovery.reverse
69
+ end
70
+ end
71
+
72
+ save_config
73
+ end
74
+ end
@@ -25,7 +25,7 @@ module WTTH
25
25
  end
26
26
  end
27
27
  end
28
- CONFIG[:zombies] = zombies
28
+ CONFIG[:zombies] = zombies unless zombies.length == 0
29
29
  return to_welcome
30
30
  end
31
31
  end
@@ -7,8 +7,6 @@ module WTTH
7
7
  oauth = Twitter::OAuth.new(APP_TOKEN, APP_SECRET)
8
8
  oauth.authorize_from_access(CONFIG[:access_token], CONFIG[:access_secret])
9
9
  twitter = Twitter::Base.new(oauth)
10
- p message
11
- return
12
10
  twitter.update(message)
13
11
  end
14
12
 
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'wtth'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class WtthTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ #flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wtth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Donoughe
@@ -9,9 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-27 00:00:00 +00:00
13
- default_executable:
12
+ date: 2009-11-30 00:00:00 +00:00
13
+ default_executable: wtth
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: nokogiri
17
27
  type: :runtime
@@ -40,22 +50,27 @@ extensions: []
40
50
 
41
51
  extra_rdoc_files:
42
52
  - LICENSE
43
- - README.markdown
53
+ - README.rdoc
44
54
  files:
45
- - README.markdown
55
+ - .gitignore
56
+ - LICENSE
57
+ - README.rdoc
58
+ - Rakefile
59
+ - VERSION
46
60
  - bin/wtth
61
+ - lib/wtth.rb
47
62
  - lib/wtth/config.rb
48
63
  - lib/wtth/hvzsource.rb
49
64
  - lib/wtth/twitter.rb
50
- - LICENSE
65
+ - test/test_helper.rb
66
+ - test/wtth_test.rb
51
67
  has_rdoc: true
52
68
  homepage: http://github.com/mdonoughe/wtth
53
69
  licenses: []
54
70
 
55
71
  post_install_message:
56
72
  rdoc_options:
57
- - --main
58
- - README.markdown
73
+ - --charset=UTF-8
59
74
  require_paths:
60
75
  - lib
61
76
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -76,6 +91,7 @@ rubyforge_project:
76
91
  rubygems_version: 1.3.5
77
92
  signing_key:
78
93
  specification_version: 3
79
- summary: Welcome to the Horde is a program that tweets when people join the zombie horde(in humans vs. zombies).
80
- test_files: []
81
-
94
+ summary: Watches humans vs. zombies games and tweets new zombies.
95
+ test_files:
96
+ - test/test_helper.rb
97
+ - test/wtth_test.rb
@@ -1,18 +0,0 @@
1
- # Welcome to the Horde
2
-
3
- This is a program that watches [HVZ Source](http://humansvszombies.org/) and posts messages to [Twitter](http://twitter.com/) when people are zombified. See [@wtthumd](http://twitter.com/wtthumd) for an example(game starts 2009-09-27 at about 22:00).
4
-
5
- Please only run one WTTH or similar per game. Check to see if your game already has one before starting your own. Nothing is gained by running duplicates, and it wastes the resources of Twitter and HVZ Source.
6
-
7
- ## Installation
8
- WTTH is written in [Ruby](http://www.ruby-lang.org/) and requires the [nokogiri](http://nokogiri.rubyforge.org/) and [twitter](http://twitter.rubyforge.org/) [gems](http://docs.rubygems.org/).
9
-
10
- WTTH now has a gem in the [GitHub gem source](http://gems.github.com/) and can be installed as `mdonoughe-wtth`. This should install all the dependencies and put `wtth` into your path like magic.
11
-
12
- After you've gotten everything installed, run `wtth init` to give the program access to a Twitter account. I'd suggest not using your usual Twitter account for this.
13
-
14
- Running `wtth init` will create a file called `.wtth.yml` in your home directory. You'll want to open that and change `player_list_uri` to point at the correct HVZ Source page for your game.
15
-
16
- You'll probably want to make some sort of cron job to run `wtth`. It makes at most one request to HVZ Source and posts at most one message to Twitter per run. Set this to a responsible interval. You can probably get away with as low as once a minute, but that's completely unnecessary in my opinion.
17
-
18
- Please remember not to have the cron job running when the game is not in session.