tweetlr 0.1.18 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/tweetlr +58 -52
- data/config/tweetlr.yml +9 -9
- data/lib/tweetlr/core.rb +17 -12
- data/lib/tweetlr.rb +1 -1
- data/tweetlr.gemspec +1 -1
- metadata +20 -20
data/bin/tweetlr
CHANGED
@@ -6,59 +6,65 @@ require 'logger'
|
|
6
6
|
require 'yaml'
|
7
7
|
require 'tweetlr'
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
9
|
+
module Tweetlr
|
10
|
+
module Runner
|
11
|
+
def self.run
|
12
|
+
begin
|
13
|
+
config_file = File.join( Dir.pwd, 'config', 'tweetlr.yml')
|
14
|
+
tid_file = File.join( Dir.pwd ,"tweetlr.tid")
|
15
|
+
start_at_tweet_id = lambda {
|
16
|
+
begin
|
17
|
+
File.open(tid_file, "r") { |io| io.gets.to_i }
|
18
|
+
rescue Errno::ENOENT => e
|
19
|
+
$stderr.puts "#{e} - we use the value from the configuration file"
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
}.call
|
23
|
+
config = YAML.load_file(config_file)
|
24
|
+
config['start_at_tweet_id'] = start_at_tweet_id || config['start_at_tweet_id'] || config['twitter_timestamp'] #check the latter for backwards compability
|
25
|
+
|
26
|
+
@tweetlr_config = prepare_tweetlr_config config
|
27
|
+
rescue SystemCallError
|
28
|
+
$stderr.puts "Ooops - looks like there is no ./config/tweetlr.yml found. I'm affraid tweetlr won't work properly until you introduced that configuration file."
|
29
|
+
exit(1)
|
30
|
+
end
|
24
31
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
32
|
+
Daemons.run_proc('tweetlr', :dir_mode => :script, :dir => './', :backtrace => true, :log_output => true) do
|
33
|
+
@log = Logger.new(STDOUT)
|
34
|
+
@log.info "starting tweetlr daemon..."
|
35
|
+
@log.info "creating a new tweetlr instance using this config: #{@tweetlr_config.inspect}"
|
36
|
+
EventMachine::run do
|
37
|
+
EventMachine::add_periodic_timer( @tweetlr_config[:update_period] ) do
|
38
|
+
response = Tweetlr::Core.crawl(@tweetlr_config)
|
39
|
+
File.open(tid_file, "w+") { |io| io.write(response[:since_id]) }
|
40
|
+
@tweetlr_config.merge! response
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
30
45
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
46
|
+
def self.prepare_tweetlr_config(config)
|
47
|
+
{
|
48
|
+
:tumblr_blog_hostname => config['tumblr_blog_hostname'] || config['group'],
|
49
|
+
:tumblr_oauth_api_key => config['tumblr_oauth_api_key'],
|
50
|
+
:tumblr_oauth_api_secret => config['tumblr_oauth_api_secret'],
|
51
|
+
:tumblr_blog_hostname => config['tumblr_blog_hostname'],
|
52
|
+
:tumblr_oauth_access_token_key => config['tumblr_oauth_access_token_key'],
|
53
|
+
:tumblr_oauth_access_token_secret => config['tumblr_oauth_access_token_secret'],
|
54
|
+
:whitelist => config['whitelist'],
|
55
|
+
:shouts => config['shouts'],
|
56
|
+
:since_id => config['start_at_tweet_id'] ,
|
57
|
+
:terms => config['search_term'],
|
58
|
+
:loglevel => config['loglevel'],
|
59
|
+
:update_period => config['update_period'],
|
60
|
+
:api_endpoint_tumblr => config['api_endpoint_tumblr'],
|
61
|
+
:api_endpoint_twitter => config['api_endpoint_twitter'],
|
62
|
+
:results_per_page => config['results_per_page'],
|
63
|
+
:result_type => config['result_type'],
|
64
|
+
:embedly_key => config['embedly_key']
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
42
68
|
end
|
43
69
|
|
44
|
-
|
45
|
-
{
|
46
|
-
:tumblr_blog_hostname => config['tumblr_blog_hostname'] || config['group'],
|
47
|
-
:tumblr_oauth_api_key => config['tumblr_oauth_api_key'],
|
48
|
-
:tumblr_oauth_api_secret => config['tumblr_oauth_api_secret'],
|
49
|
-
:tumblr_blog_hostname => config['tumblr_blog_hostname'],
|
50
|
-
:tumblr_oauth_access_token_key => config['tumblr_oauth_access_token_key'],
|
51
|
-
:tumblr_oauth_access_token_secret => config['tumblr_oauth_access_token_secret'],
|
52
|
-
:whitelist => config['whitelist'],
|
53
|
-
:shouts => config['shouts'],
|
54
|
-
:since_id => config['start_at_tweet_id'] ,
|
55
|
-
:terms => config['search_term'],
|
56
|
-
:loglevel => config['loglevel'],
|
57
|
-
:update_period => UPDATE_PERIOD,
|
58
|
-
:api_endpoint_tumblr => config['api_endpoint_tumblr'],
|
59
|
-
:api_endpoint_twitter => config['api_endpoint_twitter'],
|
60
|
-
:results_per_page => config['results_per_page'],
|
61
|
-
:result_type => config['result_type'],
|
62
|
-
:embedly_key => config['embedly_key']
|
63
|
-
}
|
64
|
-
end
|
70
|
+
Tweetlr::Runner.run
|
data/config/tweetlr.yml
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
results_per_page: 100
|
2
2
|
result_type: recent
|
3
|
-
search_term: '
|
3
|
+
search_term: 'cat+dog+unicorn' #find tweets containing any of these terms
|
4
4
|
start_at_tweet_id: 61847783463854082 # the tweet id to start searching at
|
5
5
|
api_endpoint_twitter: 'http://search.twitter.com/search.json'
|
6
6
|
api_endpoint_tumblr: 'http://www.tumblr.com'
|
7
|
-
tumblr_oauth_api_key:
|
8
|
-
tumblr_oauth_api_secret:
|
9
|
-
tumblr_oauth_access_token_key:
|
10
|
-
tumblr_oauth_access_token_secret:
|
11
|
-
tumblr_blog_hostname:
|
12
|
-
embedly_key: '
|
13
|
-
update_period:
|
7
|
+
tumblr_oauth_api_key: YOUR APPS TUMBLR API TOKEN
|
8
|
+
tumblr_oauth_api_secret: YOUR APPS TUMBLR API SECRET
|
9
|
+
tumblr_oauth_access_token_key: YOUR BLOGS OAUTH ACCESS TOKEN KEY
|
10
|
+
tumblr_oauth_access_token_secret: YOUR BLOGS OAUTH ACCESS TOKEN SECRE
|
11
|
+
tumblr_blog_hostname: YOUR BLOGS HOSTNAME #e.g. myblog.tumblr.com
|
12
|
+
embedly_key: '' #tweetlr uses http://embedly.com for link processing. a free plan containing an api key is available & recommended to use in order to ensure full support
|
13
|
+
update_period: 300 #check for updates every 300 secs = 5 minutes
|
14
14
|
shouts: 'says' # will be concatenated after the username, before the message: @mr_x says: awesome things on a photo!
|
15
15
|
loglevel: 1 # 0: debug, 1: info (default), 2: warn, 3: error, 5: fatal
|
16
16
|
whitelist: #twitter accounts in that list will have their tweets published immediately. post from others will be saved as drafts. blank list will publish all tweets immediately
|
17
17
|
- whitey_mc_whitelist
|
18
|
-
- sven_kr
|
18
|
+
- sven_kr
|
data/lib/tweetlr/core.rb
CHANGED
@@ -45,8 +45,19 @@ class Tweetlr::Core
|
|
45
45
|
response = {}
|
46
46
|
response = Tweetlr::Processors::Twitter::lazy_search(twitter_config)
|
47
47
|
if response
|
48
|
-
|
49
|
-
|
48
|
+
process_response response, config, tumblr_config
|
49
|
+
# store the highest tweet id
|
50
|
+
config[:since_id] = response['max_id']
|
51
|
+
else
|
52
|
+
log.error "twitter search returned no response. hail the failwhale!"
|
53
|
+
end
|
54
|
+
log.info "finished tweetlr crawl."
|
55
|
+
return config
|
56
|
+
end
|
57
|
+
private
|
58
|
+
def self.process_response(response, config, tumblr_config)
|
59
|
+
tweets = response['results']
|
60
|
+
if tweets
|
50
61
|
tweets.each do |tweet|
|
51
62
|
tumblr_post = Tweetlr::Combinators::TwitterTumblr::generate_photo_post_from_tweet(tweet, {:whitelist => config[:whitelist], :embedly_key => config[:embedly_key], :group => config[:group]})
|
52
63
|
if tumblr_post.nil? || tumblr_post[:source].nil?
|
@@ -55,23 +66,17 @@ class Tweetlr::Core
|
|
55
66
|
log.debug "tumblr post: #{tumblr_post}"
|
56
67
|
res = Tweetlr::Processors::Tumblr.post tumblr_post.merge(tumblr_config)
|
57
68
|
log.debug "tumblr response: #{res}"
|
58
|
-
if res.code == "201"
|
69
|
+
if res && res.code == "201"
|
59
70
|
log.info "tumblr post created (tumblr response: #{res.header} #{res.body}"
|
60
|
-
|
71
|
+
elsif res
|
61
72
|
log.warn "tumblr response: #{res.header} #{res.body}"
|
73
|
+
else
|
74
|
+
log.warn "there was no tumblr post response - most probably due to a missing oauth authorization"
|
62
75
|
end
|
63
76
|
end
|
64
|
-
end
|
65
|
-
# store the highest tweet id
|
66
|
-
config[:since_id] = response['max_id']
|
67
77
|
end
|
68
|
-
else
|
69
|
-
log.error "twitter search returned no response. hail the failwhale!"
|
70
78
|
end
|
71
|
-
log.info "finished tweetlr crawl."
|
72
|
-
return config
|
73
79
|
end
|
74
|
-
private
|
75
80
|
def self.prepare_twitter_config(config)
|
76
81
|
{
|
77
82
|
:since_id => config[:since_id] || config[:start_at_tweet_id],
|
data/lib/tweetlr.rb
CHANGED
data/tweetlr.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tweetlr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.19
|
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: 2012-09-
|
12
|
+
date: 2012-09-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: daemons
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152354160 !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: *
|
24
|
+
version_requirements: *2152354160
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: eventmachine
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152353320 !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: *
|
35
|
+
version_requirements: *2152353320
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: curb
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152352860 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152352860
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: json
|
49
|
-
requirement: &
|
49
|
+
requirement: &2152352400 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2152352400
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: nokogiri
|
60
|
-
requirement: &
|
60
|
+
requirement: &2152351700 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2152351700
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: oauth
|
71
|
-
requirement: &
|
71
|
+
requirement: &2152351020 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2152351020
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rake
|
82
|
-
requirement: &
|
82
|
+
requirement: &2152350500 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2152350500
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rspec
|
93
|
-
requirement: &
|
93
|
+
requirement: &2152350080 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *2152350080
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: rdoc
|
104
|
-
requirement: &
|
104
|
+
requirement: &2152349660 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *2152349660
|
113
113
|
description: tweetlr crawls twitter for a given term, extracts photos out of the collected
|
114
114
|
tweets' short urls and posts the images to tumblr.
|
115
115
|
email: sven.kraeuter@gmail.com
|