tweetlr 0.0.8 → 0.0.9

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/README.md +16 -15
  2. data/Rakefile +1 -1
  3. data/lib/tweetlr.rb +36 -29
  4. metadata +2 -2
data/README.md CHANGED
@@ -10,26 +10,27 @@ Use `gem install tweetlr` if you're using *rubygems* or add the line `gem 'tweet
10
10
 
11
11
  It's essential that you have a directory called `config` in the directory you are starting tweetlr in, which has to contain the configuration file `tweetlr.yml`:
12
12
 
13
- results_per_page: 100
14
- result_type: recent
15
- search_term: <the term you want to search for>
16
- twitter_timestamp: 61847783463854082 # the timestamp you want to start searching at
17
- api_endpoint_twitter: 'http://search.twitter.com/search.json'
18
- api_endpoint_tumblr: 'http://www.tumblr.com'
19
- tumblr_username: <your tumblr username / e-mail address>
20
- tumblr_password: <your tumblr password>
21
- update_period: 300 #check for updates every 300 secs = 5 minutes
22
- shouts: 'says' # will be concatenated after the username, before the message: @mr_x <shouts>: awesome things on a photo!
23
- whitelist: #twitter accounts in that list will have their tweets published immediately. post from others will be saved as drafts
24
- - whitey_mc_whitelist
25
- - sven_kr
26
-
13
+ ```yaml
14
+ results_per_page: 100
15
+ result_type: recent
16
+ search_term: <the term you want to search for>
17
+ twitter_timestamp: 61847783463854082 # the timestamp you want to start searching at
18
+ api_endpoint_twitter: 'http://search.twitter.com/search.json'
19
+ api_endpoint_tumblr: 'http://www.tumblr.com'
20
+ tumblr_username: <your tumblr username / e-mail address>
21
+ tumblr_password: <your tumblr password>
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 <shouts>: awesome things on a photo!
24
+ whitelist: #twitter accounts in that list will have their tweets published immediately. post from others will be saved as drafts
25
+ - whitey_mc_whitelist
26
+ - sven_kr
27
+ ```
27
28
 
28
29
  ## Usage
29
30
 
30
31
  Make sure you put the configuration file in it's proper place as mentioned above, then:
31
32
 
32
- start/stop tweetlr using `tweetlr start`/`tweetlr stop`. Run `tweetlr` without arguments for a list of options concerning the daemon's options.
33
+ start/stop tweetlr using `tweetlr start`/`tweetlr stop`. Run `tweetlr` without arguments for a list of options concerning the daemon's options.
33
34
 
34
35
  For further details on the configuration part, check out the [tweetlr_demo](http://github.com/5v3n/tweetlr_demo).
35
36
 
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.8'
10
+ s.version = '0.0.9'
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/lib/tweetlr.rb CHANGED
@@ -42,7 +42,7 @@ class Tweetlr
42
42
  end
43
43
 
44
44
  end
45
-
45
+ #post a tumblr photo entry. required arguments are :type, :date, :source, :caption, :state
46
46
  def post_to_tumblr(options={})
47
47
  if options[:type] && options[:date] && options[:source] && options[:caption] && options[:state]
48
48
  response = Curl::Easy.http_post("#{@api_endpoint_tumblr}/api/write",
@@ -58,6 +58,29 @@ class Tweetlr
58
58
  end
59
59
  response
60
60
  end
61
+
62
+ #generate the data for a tumblr photo entry by parsing a tweet
63
+ def generate_tumblr_photo_post tweet
64
+ tumblr_post = nil
65
+ message = tweet['text']
66
+ if message && !message.index('RT @') #discard retweets
67
+ #@log.debug "tweet: #{tweet}"
68
+ #puts "tweet: #{tweet}"
69
+ tumblr_post = {}
70
+ tumblr_post[:type] = 'photo'
71
+ tumblr_post[:date] = tweet['created_at']
72
+ tumblr_post[:source] = extract_image_url tweet
73
+ user = tweet['from_user']
74
+ if @whitelist.member? user.downcase
75
+ state = 'published'
76
+ else
77
+ state = 'draft'
78
+ end
79
+ tumblr_post[:state] = state
80
+ tumblr_post[:caption] = %?<a href="http://twitter.com/#{user}" alt="#{user}">@#{user}</a> #{@shouts}: #{tweet['text']}? #TODO make this a bigger matter of yml configuration
81
+ end
82
+ tumblr_post
83
+ end
61
84
 
62
85
  #fire a new search
63
86
  def search_twitter()
@@ -108,7 +131,7 @@ class Tweetlr
108
131
  def image_url_instagram(link_url)
109
132
  link_url['instagram.com'] = 'instagr.am' if link_url.index 'instagram.com' #instagram's oembed does not work for .com links
110
133
  response = http_get "http://api.instagram.com/oembed?url=#{link_url}"
111
- response['url']
134
+ response['url'] if response
112
135
  end
113
136
 
114
137
  #find the image's url for a picplz short/longlink
@@ -119,7 +142,7 @@ class Tweetlr
119
142
  #if short url fails, try long url
120
143
  #response = HTTParty.get "http://picplz.com/api/v2/pic.json?longurl_ids=#{id}"
121
144
  #extract url
122
- response['value']['pics'].first['pic_files']['640r']['img_url']
145
+ response['value']['pics'].first['pic_files']['640r']['img_url'] if response
123
146
  end
124
147
  #find the image's url for a twitpic link
125
148
  def image_url_twitpic(link_url)
@@ -128,7 +151,7 @@ class Tweetlr
128
151
  #find the image'S url for a yfrog link
129
152
  def image_url_yfrog(link_url)
130
153
  response = http_get("http://www.yfrog.com/api/oembed?url=#{link_url}")
131
- response['url']
154
+ response['url'] if response
132
155
  end
133
156
  #find the image's url for a img.ly link
134
157
  def image_url_imgly(link_url)
@@ -142,7 +165,7 @@ class Tweetlr
142
165
 
143
166
  def link_url_redirect(short_url, stop_indicator = LOCATION_STOP_INDICATOR)
144
167
  resp = Curl::Easy.http_get(short_url) { |res| res.follow_location = true }
145
- if(resp.header_str.index(LOCATION_START_INDICATOR) && resp.header_str.index(stop_indicator))
168
+ if(resp && resp.header_str.index(LOCATION_START_INDICATOR) && resp.header_str.index(stop_indicator))
146
169
  start = resp.header_str.index(LOCATION_START_INDICATOR) + LOCATION_START_INDICATOR.size
147
170
  stop = resp.header_str.index(stop_indicator, start)
148
171
  resp.header_str[start...stop]
@@ -167,35 +190,19 @@ class Tweetlr
167
190
  end
168
191
  end
169
192
  end
170
-
171
- def generate_tumblr_photo_post tweet
172
- tumblr_post = nil
173
- message = tweet['text']
174
- if message && !message.index('RT @') #discard retweets
175
- #@log.debug "tweet: #{tweet}"
176
- #puts "tweet: #{tweet}"
177
- tumblr_post = {}
178
- tumblr_post[:type] = 'photo'
179
- tumblr_post[:date] = tweet['created_at']
180
- tumblr_post[:source] = extract_image_url tweet
181
- user = tweet['from_user']
182
- if @whitelist.member? user.downcase
183
- state = 'published'
184
- else
185
- state = 'draft'
186
- end
187
- tumblr_post[:state] = state
188
- tumblr_post[:caption] = %?<a href="http://twitter.com/#{user}" alt="#{user}">@#{user}</a> #{@shouts}: #{tweet['text']}? #TODO make this a bigger matter of yml configuration
189
- end
190
- tumblr_post
191
- end
192
193
 
193
194
  private
194
195
 
195
196
  #convenience method for curl http get calls
196
197
  def http_get(request)
197
- res = Curl::Easy.http_get(request)
198
- JSON.parse res.body_str
198
+ begin
199
+ res = Curl::Easy.http_get(request)
200
+ JSON.parse res.body_str
201
+ rescue Curl::Err::ConnectionFailedError => err
202
+ #@log.error "Connection failed: #{err}"
203
+ puts "Connection failed: #{err}"
204
+ nil
205
+ end
199
206
  end
200
207
 
201
208
  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.8
5
+ version: 0.0.9
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 00:00:00 Z
13
+ date: 2011-05-16 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: daemons