tweetlr 0.0.6 → 0.0.7

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 (4) hide show
  1. data/Rakefile +2 -2
  2. data/bin/tweetlr +13 -10
  3. data/lib/tweetlr.rb +35 -21
  4. metadata +3 -3
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.6'
10
+ s.version = '0.0.7'
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.}
@@ -20,7 +20,7 @@ spec = Gem::Specification.new do |s|
20
20
  s.executables = ['tweetlr']
21
21
  s.add_dependency('daemons')
22
22
  s.add_dependency('eventmachine')
23
- s.add_dependency('httparty')
23
+ s.add_dependency('curb')
24
24
  end
25
25
 
26
26
  Rake::GemPackageTask.new(spec) do |p|
data/bin/tweetlr CHANGED
@@ -21,27 +21,30 @@ rescue SystemCallError
21
21
  exit(1)
22
22
  end
23
23
 
24
- Daemons.run_proc('tweetlr') do
25
- @log = Logger.new(@log_file)
26
- @log.info('starting tweetlr daemon...')
27
- @log.info "creating a new tweetlr instance using this config: #{CONFIG.inspect}"
24
+ Daemons.run_proc('tweetlr', :dir_mode => :script, :dir => './', :backtrace => true, :log_output => true) do
25
+ #@log = Logger.new(@log_file)
26
+ puts('starting tweetlr daemon...')
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
- @log.info('starting tweetlr crawl...')
30
+ puts 'starting tweetlr crawl...'
31
31
  response = @tweetlr.lazy_search_twitter
32
- tweets = response.parsed_response['results']
32
+ tweets = response['results']
33
33
  if tweets
34
34
  tweets.each do |tweet|
35
35
  tumblr_post = @tweetlr.generate_tumblr_photo_post tweet
36
36
  if tumblr_post.nil? || tumblr_post[:source].nil?
37
- @log.error "could not get image source: #{tumblr_post.inspect}"
37
+ puts "could not get image source: tweet: #{tweet} --- tumblr post: #{tumblr_post.inspect}"
38
38
  else
39
- @log.debug tumblr_post
40
- @log.debug @tweetlr.post_to_tumblr tumblr_post
39
+ #@log.debug tumblr_post
40
+ #@log.debug @tweetlr.post_to_tumblr tumblr_post
41
+ #puts "tumblr post: #{tumblr_post}"
42
+ res = @tweetlr.post_to_tumblr tumblr_post
43
+ #puts "tumblr response: #{res.header_str} #{res.body_str}"
41
44
  end
42
45
  end
43
46
  end
44
- @log.info('finished tweetlr crawl.')
47
+ puts('finished tweetlr crawl.')
45
48
  }
46
49
  }
47
50
 
data/lib/tweetlr.rb CHANGED
@@ -1,7 +1,7 @@
1
- require 'httparty'
2
1
  require 'logger'
3
2
  require 'yaml'
4
3
  require 'curb'
4
+ require 'json'
5
5
 
6
6
 
7
7
  class Tweetlr
@@ -27,7 +27,7 @@ class Tweetlr
27
27
  @term = term
28
28
  @refresh_url = "#{@api_endpoint_twitter}?q=#{term}&since_id=#{since_id}" if (since_id && term)
29
29
  if !cookie
30
- response = HTTParty.post(
30
+ response = Curl::Easy.http_post(
31
31
  "#{@api_endpoint_tumblr}/login",
32
32
  :body => {
33
33
  :email => @email,
@@ -45,32 +45,37 @@ class Tweetlr
45
45
  end
46
46
 
47
47
  def post_to_tumblr(options={})
48
- options[:generator] = GENERATOR
49
- options[:email] = @email #TODO get cookie auth working!
50
- options[:password] = @password
51
- #options[:headers] = {'Cookie' => @cookie}
52
- #arguments=options.collect { |key, value| "#{key}=#{value}" }.join('&')
53
- @log.debug("------------********** post_to_tumblr options: #{options.inspect}")
54
- @log.debug("------------********** post_to_tumblr options: #{{'Cookie' => @cookie}.inspect}")
55
- response = HTTParty.post("#{@api_endpoint_tumblr}/api/write", :body => options, :headers => {'Cookie' => @cookie})
56
- @log.debug("------------********** post_to_tumblr response: #{response.inspect}" )
48
+ if options[:type] && options[:date] && options[:source] && options[:caption] && options[:state]
49
+ response = Curl::Easy.http_post("#{@api_endpoint_tumblr}/api/write",
50
+ Curl::PostField.content('generator', GENERATOR),
51
+ Curl::PostField.content('email', @email),
52
+ Curl::PostField.content('password', @password),
53
+ Curl::PostField.content('type', options[:type]),
54
+ Curl::PostField.content('date', options[:date]),
55
+ Curl::PostField.content('source', options[:source]),
56
+ Curl::PostField.content('caption', options[:caption]),
57
+ Curl::PostField.content('state', options[:state])
58
+ )
59
+ end
57
60
  response
58
61
  end
59
62
 
60
63
  #fire a new search
61
64
  def search_twitter()
62
65
  search_call = "#{@api_endpoint_twitter}?q=#{@search_term}&result_type=#{@result_type}&rpp=#{@results_per_page}"
63
- @response = HTTParty.get(search_call)
66
+ @response = http_get search_call
64
67
  end
65
68
  # lazy update - search for a term or refresh the search if a response is available already
66
69
  def lazy_search_twitter()
67
70
  @refresh_url = "#{@api_endpoint_twitter}#{@response['refresh_url']}" unless (@response.nil? || @response['refresh_url'].nil? || @response['refresh_url'].empty?)
68
71
  if @refresh_url
69
72
  #FIXME persist the refresh url - server restart would be a pain elsewise
70
- @log.info "lazy search using '#{@refresh_url}'"
71
- @response = HTTParty.get(@refresh_url)
73
+ #@log.info "lazy search using '#{@refresh_url}'"
74
+ puts "lazy search using '#{@refresh_url}'" #workaround to get refresh url logged w/ the Daemons gem
75
+ @response = http_get @refresh_url
72
76
  else
73
- @log.debug "regular search using '#{term}'"
77
+ #@log.debug "regular search using '#{term}'"
78
+ puts "regular search using '#{term}'"
74
79
  @response = search_twitter()
75
80
  end
76
81
  end
@@ -92,15 +97,15 @@ class Tweetlr
92
97
  #find the image's url for an instagram link
93
98
  def image_url_instagram(link_url)
94
99
  link_url['instagram.com'] = 'instagr.am' if link_url.index 'instagram.com' #instagram's oembed does not work for .com links
95
- response = HTTParty.get "http://api.instagram.com/oembed?url=#{link_url}"
96
- response.parsed_response['url']
100
+ response = http_get "http://api.instagram.com/oembed?url=#{link_url}"
101
+ response['url']
97
102
  end
98
103
 
99
104
  #find the image's url for a picplz short/longlink
100
105
  def image_url_picplz(link_url)
101
106
  id = extract_id link_url
102
107
  #try short url
103
- response = HTTParty.get "http://picplz.com/api/v2/pic.json?shorturl_ids=#{id}"
108
+ response = http_get "http://picplz.com/api/v2/pic.json?shorturl_ids=#{id}"
104
109
  #if short url fails, try long url
105
110
  #response = HTTParty.get "http://picplz.com/api/v2/pic.json?longurl_ids=#{id}"
106
111
  #extract url
@@ -112,8 +117,8 @@ class Tweetlr
112
117
  end
113
118
  #find the image'S url for a yfrog link
114
119
  def image_url_yfrog(link_url)
115
- response = HTTParty.get("http://www.yfrog.com/api/oembed?url=#{link_url}")
116
- response.parsed_response['url']
120
+ response = http_get("http://www.yfrog.com/api/oembed?url=#{link_url}")
121
+ response['url']
117
122
  end
118
123
  #find the image's url for a img.ly link
119
124
  def image_url_imgly(link_url)
@@ -153,7 +158,8 @@ class Tweetlr
153
158
  tumblr_post = nil
154
159
  message = tweet['text']
155
160
  if message && !message.index('RT @') #discard retweets
156
- @log.debug "tweet: #{tweet}"
161
+ #@log.debug "tweet: #{tweet}"
162
+ #puts "tweet: #{tweet}"
157
163
  tumblr_post = {}
158
164
  tumblr_post[:type] = 'photo'
159
165
  tumblr_post[:date] = tweet['created_at']
@@ -170,6 +176,14 @@ class Tweetlr
170
176
  tumblr_post
171
177
  end
172
178
 
179
+ private
180
+
181
+ #convenience method for curl http get calls
182
+ def http_get(request)
183
+ res = Curl::Easy.http_get(request)
184
+ JSON.parse res.body_str
185
+ end
186
+
173
187
  end
174
188
 
175
189
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: tweetlr
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.6
5
+ version: 0.0.7
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-03 00:00:00 Z
13
+ date: 2011-05-13 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: daemons
@@ -35,7 +35,7 @@ dependencies:
35
35
  type: :runtime
36
36
  version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
38
- name: httparty
38
+ name: curb
39
39
  prerelease: false
40
40
  requirement: &id003 !ruby/object:Gem::Requirement
41
41
  none: false