sarnesjo-twhere 0.0.0

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 (6) hide show
  1. data/LICENSE +18 -0
  2. data/README.rdoc +7 -0
  3. data/VERSION.yml +4 -0
  4. data/bin/twhere +27 -0
  5. data/lib/twhere.rb +63 -0
  6. metadata +59 -0
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2009 Jesper Särnesjö
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = twhere
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Jesper Särnesjö. See LICENSE for details.
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 0
4
+ :patch: 1
data/bin/twhere ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ require 'twhere'
5
+ require 'optparse'
6
+
7
+ options = {}
8
+ OptionParser.new do |opts|
9
+ opts.banner = 'usage: twhere.rb [options]'
10
+
11
+ opts.on('-c', '--config FILE', 'specify config file') do |c|
12
+ options[:config_file] = c
13
+ end
14
+
15
+ opts.on_tail('-h', '--help', 'show this message') do
16
+ puts opts
17
+ exit
18
+ end
19
+
20
+ opts.on_tail('--version', 'show version') do
21
+ version = YAML::load(File.open(File.join(File.dirname(__FILE__), '..', 'VERSION.yml')))
22
+ puts "#{version[:major]}.#{version[:minor]}.#{version[:patch]}"
23
+ exit
24
+ end
25
+ end.parse!
26
+
27
+ Twhere.new(options[:config_file]).run
data/lib/twhere.rb ADDED
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require 'erb'
3
+ require 'twitter'
4
+
5
+ class Twhere
6
+ def initialize(config_file)
7
+ config = YAML::load(File.open(config_file))
8
+ @locations_file = config[:twhere][:locations_file]
9
+ @tweets_file = config[:twhere][:tweets_file]
10
+ @template_file = config[:twhere][:template_file]
11
+ @twitter_username = config[:twitter][:username]
12
+ @twitter_password = config[:twitter][:password]
13
+ @google_maps_api_key = config[:google_maps][:api_key]
14
+ end
15
+
16
+ def result
17
+ # load known locations
18
+ @locations = YAML::load(File.open(@locations_file))
19
+
20
+ # create Twitter proxy object
21
+ twitter = Twitter::Base.new(Twitter::HTTPAuth.new(@twitter_username, @twitter_password))
22
+
23
+ # load saved tweets (or don't)
24
+ tweets = []
25
+ begin
26
+ tweets = YAML::load(File.open(@tweets_file))
27
+ rescue Errno::ENOENT
28
+ end
29
+
30
+ # add new tweets to collection
31
+ twitter.user_timeline.each do |t|
32
+ # we only care about these variables
33
+ h = {:twitter_id => t.id, :text => t.text, :created_at => t.created_at}
34
+ # this appears to be necessary since neither Array#| nor Array#uniq works as expected
35
+ tweets << h unless tweets.include? h
36
+ end
37
+
38
+ # sort tweets, oldest first
39
+ tweets.sort! { |a, b| a[:twitter_id].to_i <=> b[:twitter_id].to_i }
40
+
41
+ # save tweets to file
42
+ File.open(@tweets_file, 'w') { |f| f.puts tweets.to_yaml }
43
+
44
+ # group tweets by location
45
+ @located_tweets = {}
46
+ location = nil
47
+ tweets.each do |t|
48
+ md = t[:text].match(/#([a-z]+)/)
49
+ location = md[1] if md
50
+ if location and @locations.keys.include? location
51
+ @located_tweets[location] ||= []
52
+ @located_tweets[location] << t
53
+ end
54
+ end
55
+
56
+ # open template file and process with ERB
57
+ ERB.new(File.read(@template_file)).result(binding)
58
+ end
59
+
60
+ def run
61
+ puts self.result
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sarnesjo-twhere
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - "Jesper S\xC3\xA4rnesj\xC3\xB6"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-28 00:00:00 -07:00
13
+ default_executable: twhere
14
+ dependencies: []
15
+
16
+ description:
17
+ email: jesper@sarnesjo.org
18
+ executables:
19
+ - twhere
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE
25
+ files:
26
+ - README.rdoc
27
+ - VERSION.yml
28
+ - bin/twhere
29
+ - lib/twhere.rb
30
+ - LICENSE
31
+ has_rdoc: true
32
+ homepage: http://github.com/sarnesjo/twhere
33
+ post_install_message:
34
+ rdoc_options:
35
+ - --inline-source
36
+ - --charset=UTF-8
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ requirements: []
52
+
53
+ rubyforge_project:
54
+ rubygems_version: 1.2.0
55
+ signing_key:
56
+ specification_version: 2
57
+ summary: Twitter/Google Maps mashup
58
+ test_files: []
59
+