tweetlr 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -5
- data/Rakefile +1 -1
- data/bin/tweetlr +19 -15
- data/lib/tweetlr.rb +17 -10
- metadata +2 -2
data/README.md
CHANGED
@@ -13,14 +13,14 @@ It's essential that you have a directory called `config` in the directory you ar
|
|
13
13
|
```yaml
|
14
14
|
results_per_page: 100
|
15
15
|
result_type: recent
|
16
|
-
search_term:
|
16
|
+
search_term: 'cat+dog+unicorn' #find tweets containing any of these terms
|
17
17
|
twitter_timestamp: 61847783463854082 # the timestamp you want to start searching at
|
18
18
|
api_endpoint_twitter: 'http://search.twitter.com/search.json'
|
19
19
|
api_endpoint_tumblr: 'http://www.tumblr.com'
|
20
|
-
tumblr_username:
|
21
|
-
tumblr_password:
|
20
|
+
tumblr_username: YOUR_TUMBLR_EMAIL
|
21
|
+
tumblr_password: YOUR_TUMBLR_PW
|
22
22
|
update_period: 300 #check for updates every 300 secs = 5 minutes
|
23
|
-
shouts: 'says' # will be concatenated after the username, before the message: @mr_x
|
23
|
+
shouts: 'says' # will be concatenated after the username, before the message: @mr_x says: awesome things on a photo!
|
24
24
|
whitelist: #twitter accounts in that list will have their tweets published immediately. post from others will be saved as drafts
|
25
25
|
- whitey_mc_whitelist
|
26
26
|
- sven_kr
|
@@ -32,7 +32,7 @@ Make sure you put the configuration file in it's proper place as mentioned above
|
|
32
32
|
|
33
33
|
start/stop tweetlr using `tweetlr start`/`tweetlr stop`. Run `tweetlr` without arguments for a list of options concerning the daemon's options.
|
34
34
|
|
35
|
-
For
|
35
|
+
For a easy to modify working example, check out the [tweetlr_demo](http://github.com/5v3n/tweetlr_demo).
|
36
36
|
|
37
37
|
Enjoy!
|
38
38
|
|
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ require 'rake/testtask'
|
|
7
7
|
|
8
8
|
spec = Gem::Specification.new do |s|
|
9
9
|
s.name = 'tweetlr'
|
10
|
-
s.version = '0.0.
|
10
|
+
s.version = '0.0.10'
|
11
11
|
s.has_rdoc = true
|
12
12
|
s.extra_rdoc_files = ['README.md', 'LICENSE']
|
13
13
|
s.summary = %{tweetlr crawls twitter for a given term, extracts photos out of the collected tweets' short urls and posts the images to tumblr.}
|
data/bin/tweetlr
CHANGED
@@ -23,28 +23,32 @@ end
|
|
23
23
|
|
24
24
|
Daemons.run_proc('tweetlr', :dir_mode => :script, :dir => './', :backtrace => true, :log_output => true) do
|
25
25
|
#@log = Logger.new(@log_file)
|
26
|
-
puts
|
26
|
+
puts "#{Time.now} - starting tweetlr daemon..."
|
27
27
|
puts "creating a new tweetlr instance using this config: #{CONFIG.inspect}"
|
28
28
|
EventMachine::run {
|
29
29
|
EventMachine::add_periodic_timer( UPDATE_PERIOD ) {
|
30
|
-
puts
|
30
|
+
puts "#{Time.now} - starting tweetlr crawl..."
|
31
31
|
response = @tweetlr.lazy_search_twitter
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
if response
|
33
|
+
tweets = response['results']
|
34
|
+
if tweets
|
35
|
+
tweets.each do |tweet|
|
36
|
+
tumblr_post = @tweetlr.generate_tumblr_photo_post tweet
|
37
|
+
if tumblr_post.nil? || tumblr_post[:source].nil?
|
38
|
+
puts "could not get image source: tweet: #{tweet} --- tumblr post: #{tumblr_post.inspect}"
|
39
|
+
else
|
40
|
+
#@log.debug tumblr_post
|
41
|
+
#@log.debug @tweetlr.post_to_tumblr tumblr_post
|
42
|
+
#puts "tumblr post: #{tumblr_post}"
|
43
|
+
res = @tweetlr.post_to_tumblr tumblr_post
|
44
|
+
puts "tumblr response: #{res.header_str} #{res.body_str}" unless res.response_code == 201
|
45
|
+
end
|
44
46
|
end
|
45
47
|
end
|
48
|
+
else
|
49
|
+
puts "#{Time.now} - twitter serach returned no response. Hail the whale!"
|
46
50
|
end
|
47
|
-
puts
|
51
|
+
puts "#{Time.now} - finished tweetlr crawl."
|
48
52
|
}
|
49
53
|
}
|
50
54
|
|
data/lib/tweetlr.rb
CHANGED
@@ -9,7 +9,7 @@ class Tweetlr
|
|
9
9
|
LOCATION_START_INDICATOR = 'Location: '
|
10
10
|
LOCATION_STOP_INDICATOR = "\r\n"
|
11
11
|
|
12
|
-
def initialize(email, password, cookie=nil, since_id=nil,
|
12
|
+
def initialize(email, password, cookie=nil, since_id=nil, terms=nil, config_file) #TODO use a hash or sth more elegant here...
|
13
13
|
@log = Logger.new(File.join( Dir.pwd, 'tweetlr.log'))
|
14
14
|
config = YAML.load_file(config_file)
|
15
15
|
@results_per_page = config['results_per_page']
|
@@ -19,12 +19,11 @@ class Tweetlr
|
|
19
19
|
@whitelist = config['whitelist']
|
20
20
|
@shouts = config['shouts']
|
21
21
|
@since_id = since_id
|
22
|
-
@search_term =
|
22
|
+
@search_term = terms
|
23
23
|
@whitelist.each {|entry| entry.downcase!}
|
24
24
|
@email = email
|
25
25
|
@password = password
|
26
|
-
@
|
27
|
-
@refresh_url = "#{@api_endpoint_twitter}?q=#{term}&since_id=#{since_id}" if (since_id && term)
|
26
|
+
@refresh_url = "#{@api_endpoint_twitter}?ors=#{terms}&since_id=#{since_id}&rpp=#{@results_per_page}&result_type=#{@result_type}" if (since_id && terms)
|
28
27
|
if !cookie
|
29
28
|
response = Curl::Easy.http_post(
|
30
29
|
"#{@api_endpoint_tumblr}/login",
|
@@ -63,7 +62,7 @@ class Tweetlr
|
|
63
62
|
def generate_tumblr_photo_post tweet
|
64
63
|
tumblr_post = nil
|
65
64
|
message = tweet['text']
|
66
|
-
if
|
65
|
+
if !retweet? message
|
67
66
|
#@log.debug "tweet: #{tweet}"
|
68
67
|
#puts "tweet: #{tweet}"
|
69
68
|
tumblr_post = {}
|
@@ -71,20 +70,27 @@ class Tweetlr
|
|
71
70
|
tumblr_post[:date] = tweet['created_at']
|
72
71
|
tumblr_post[:source] = extract_image_url tweet
|
73
72
|
user = tweet['from_user']
|
73
|
+
tweet_id = tweet['id']
|
74
74
|
if @whitelist.member? user.downcase
|
75
75
|
state = 'published'
|
76
76
|
else
|
77
77
|
state = 'draft'
|
78
78
|
end
|
79
79
|
tumblr_post[:state] = state
|
80
|
-
|
80
|
+
shouts = " #{@shouts}" if @shouts
|
81
|
+
tumblr_post[:caption] = %?<a href="http://twitter.com/#{user}/statuses/#{tweet_id}" alt="#{user}">@#{user}</a>#{shouts}: #{tweet['text']}? #TODO make this a bigger matter of yml configuration
|
81
82
|
end
|
82
83
|
tumblr_post
|
83
84
|
end
|
85
|
+
|
86
|
+
#checks if the message is a retweet
|
87
|
+
def retweet?(message)
|
88
|
+
message.index('RT @') || message.index(%{ "@}) || message.index(" \u201c@") #detect retweets
|
89
|
+
end
|
84
90
|
|
85
91
|
#fire a new search
|
86
92
|
def search_twitter()
|
87
|
-
search_call = "#{@api_endpoint_twitter}?
|
93
|
+
search_call = "#{@api_endpoint_twitter}?ors=#{@search_term}&result_type=#{@result_type}&rpp=#{@results_per_page}"
|
88
94
|
@response = http_get search_call
|
89
95
|
end
|
90
96
|
# lazy update - search for a term or refresh the search if a response is available already
|
@@ -93,11 +99,12 @@ class Tweetlr
|
|
93
99
|
if @refresh_url
|
94
100
|
#FIXME persist the refresh url - server restart would be a pain elsewise
|
95
101
|
#@log.info "lazy search using '#{@refresh_url}'"
|
96
|
-
|
97
|
-
|
102
|
+
search_url = "#{@refresh_url}&result_type=#{@result_type}&rpp=#{@results_per_page}"
|
103
|
+
puts "lazy search using '#{search_url}'" #workaround to get refresh url logged w/ the Daemons gem
|
104
|
+
@response = http_get search_url
|
98
105
|
else
|
99
106
|
#@log.debug "regular search using '#{term}'"
|
100
|
-
puts "regular search using '#{
|
107
|
+
puts "regular search using '#{@search_term}'"
|
101
108
|
@response = search_twitter()
|
102
109
|
end
|
103
110
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: tweetlr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sven Kraeuter
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-22 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: daemons
|