feed2email 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,4 @@
1
1
  *.gem
2
2
  *.yml
3
3
  .bundle
4
- Gemfile.lock
5
4
  pkg/
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ ### 0.1.0
2
+
3
+ * Skip entry if pubDate is in the future
4
+ * Fix feed fetching by accepting compression
5
+ * Fix crashing for missing multi-level directories in config path
6
+ * Accept recipient address as the first command-line argument
7
+ * Append feed2email signature to email body
8
+ * Use full HTTPS address for RubyGems source in Gemfile
9
+ * Add this changelog
10
+
11
+ ### 0.0.1
12
+
13
+ * Initial release
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ feed2email (0.0.2)
5
+ feedzirra
6
+ mail
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (3.1.12)
12
+ multi_json (~> 1.0)
13
+ builder (3.2.0)
14
+ curb (0.7.18)
15
+ feedzirra (0.1.3)
16
+ activesupport (~> 3.1.1)
17
+ builder (>= 2.1.2)
18
+ curb (~> 0.7.15)
19
+ i18n (>= 0.5.0)
20
+ loofah (~> 1.2.0)
21
+ nokogiri (>= 1.4.4)
22
+ rake (>= 0.8.7)
23
+ rdoc (~> 3.8)
24
+ sax-machine (~> 0.1.0)
25
+ i18n (0.6.4)
26
+ json (1.7.7)
27
+ loofah (1.2.1)
28
+ nokogiri (>= 1.4.4)
29
+ mail (2.5.3)
30
+ i18n (>= 0.4.0)
31
+ mime-types (~> 1.16)
32
+ treetop (~> 1.4.8)
33
+ mime-types (1.22)
34
+ multi_json (1.7.2)
35
+ nokogiri (1.5.9)
36
+ polyglot (0.3.3)
37
+ rake (10.0.4)
38
+ rdoc (3.12.2)
39
+ json (~> 1.4)
40
+ sax-machine (0.1.0)
41
+ nokogiri (> 0.0.0)
42
+ treetop (1.4.12)
43
+ polyglot
44
+ polyglot (>= 0.3.1)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ feed2email!
data/README.md CHANGED
@@ -6,7 +6,7 @@ RSS/Atom feed updates in your email
6
6
 
7
7
  I don't like having a separate application for feeds when I'm already checking my email. I also never read a thing when feeds are kept in a separate place.
8
8
 
9
- The script was written primarily as a replacement of the [rss2email][] program which is rather big, slow, bloated and hard to use.
9
+ The script was written primarily as a replacement of [rss2email][] and aims to be simpler, faster, smaller and easier to use.
10
10
 
11
11
  [rss2email]: http://www.allthingsrss.com/rss2email/
12
12
 
@@ -32,24 +32,22 @@ Create `~/.feed2email/feeds.yml` and add the address of each feed you want to su
32
32
  When run for the first time, the script enters "dry run" mode and exits almost immediately. During dry run mode:
33
33
 
34
34
  * No feeds are fetched and, thus, no email is sent (existing feed entries are considered already seen)
35
- * `~/.feed2email/cache.yml` is created containing the timestamp of when each feed was last fetched
35
+ * `~/.feed2email/state.yml` is created containing the timestamp of when each feed was last fetched
36
36
 
37
- If you want to receive existing entries from a specific feed, you can alter the timestamp for that feed in `cache.yml` to a value in the past. Next time you run the script, all entries published past that timestamp will be sent with email.
37
+ If you want to receive existing entries from a specific feed, you can manually alter the timestamp for that feed in `state.yml` to a value in the past. Next time you run the script, all entries published past that timestamp will be sent with email.
38
38
 
39
- Here's how to run the script:
39
+ To run the script:
40
40
 
41
41
  ~~~ sh
42
- $ MAILTO=agorfatagorfdotgr feed2email
42
+ $ feed2email name@example.com
43
43
  ~~~
44
44
 
45
45
  It's also possible to override the path to the [Sendmail][] binary:
46
46
 
47
47
  ~~~ sh
48
- $ SENDMAIL=/path/to/sendmail MAILTO=agorfatagorfdotgr feed2email
48
+ $ SENDMAIL=/path/to/sendmail feed2email name@example.com
49
49
  ~~~
50
50
 
51
- **Note:** Email symbols in the above examples have been replaced with words to avoid spam.
52
-
53
51
  You can use [cron][] to run the script e.g. once every hour.
54
52
 
55
53
  [cron]: http://en.wikipedia.org/wiki/Cron
data/bin/feed2email CHANGED
@@ -1,5 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ if %w{-h --help}.include?(ARGV[0]) || (ARGV[0].nil? && ENV['MAILTO'].nil?)
4
+ $stderr.puts "usage: #{$0} <recipient>"
5
+ exit 1
6
+ end
7
+
3
8
  require 'feed2email'
4
9
 
5
- Feed2Email::Feed.process_all
10
+ Feed2Email::Feed.process_all(:recipient => ARGV[0] || ENV['MAILTO'])
@@ -3,3 +3,9 @@ class String
3
3
  CGI.escapeHTML(self)
4
4
  end
5
5
  end
6
+
7
+ class Time
8
+ def past?
9
+ self < Time.now
10
+ end
11
+ end
@@ -20,21 +20,27 @@ module Feed2Email
20
20
  end
21
21
 
22
22
  def process
23
- to_mail.send if new?
23
+ to_mail.send if to_be_sent?
24
24
  end
25
25
 
26
26
  def title
27
27
  @data.title
28
28
  end
29
29
 
30
- def url
30
+ def uri
31
31
  @data.url
32
32
  end
33
33
 
34
34
  private
35
35
 
36
- def new?
37
- @data.published > @feed.fetch_time
36
+ def published_at
37
+ @data.published
38
+ end
39
+
40
+ def to_be_sent?
41
+ published_at &&
42
+ published_at.past? && # respect entry future pubDate
43
+ published_at > @feed.fetch_time
38
44
  end
39
45
 
40
46
  def to_mail
@@ -1,26 +1,29 @@
1
1
  module Feed2Email
2
2
  FEEDS_FILE = File.expand_path('~/.feed2email/feeds.yml')
3
- CACHE_FILE = File.expand_path('~/.feed2email/cache.yml')
3
+ STATE_FILE = File.expand_path('~/.feed2email/state.yml')
4
4
  USER_AGENT = "feed2email/#{VERSION}"
5
5
 
6
6
  class Feed
7
- def self.process(uri)
8
- Feed.new(uri).process
7
+ def self.process(uri, options)
8
+ Feed.new(uri, options).process
9
9
  end
10
10
 
11
- def self.process_all
12
- Dir.mkdir(File.dirname(CACHE_FILE)) rescue nil
11
+ def self.process_all(options)
12
+ FileUtils.mkdir_p(File.dirname(STATE_FILE)) rescue nil
13
13
 
14
- @@fetch_times = YAML.load(open(CACHE_FILE)) rescue {}
14
+ @@fetch_times = YAML.load(open(STATE_FILE)) rescue {}
15
15
 
16
16
  feed_uris = YAML.load(open(FEEDS_FILE)) rescue []
17
- feed_uris.each {|uri| Feed.process(uri) }
17
+ feed_uris.each {|uri| Feed.process(uri, options) }
18
18
 
19
- open(CACHE_FILE, 'w') {|f| f.write(@@fetch_times.to_yaml) }
19
+ open(STATE_FILE, 'w') {|f| f.write(@@fetch_times.to_yaml) }
20
20
  end
21
21
 
22
- def initialize(uri)
22
+ attr_reader :options
23
+
24
+ def initialize(uri, options)
23
25
  @uri = uri
26
+ @options = options
24
27
  end
25
28
 
26
29
  def fetch_time
@@ -40,7 +43,8 @@ module Feed2Email
40
43
 
41
44
  def data
42
45
  @fetched_at ||= Time.now
43
- @data ||= Feedzirra::Feed.fetch_and_parse(@uri, :user_agent => USER_AGENT)
46
+ fetch_opts = { :user_agent => USER_AGENT, :compress => true }
47
+ @data ||= Feedzirra::Feed.fetch_and_parse(@uri, fetch_opts)
44
48
  end
45
49
 
46
50
  def entries
@@ -52,7 +56,7 @@ module Feed2Email
52
56
  end
53
57
 
54
58
  def have_entries?
55
- data.entries.any?
59
+ entries.any?
56
60
  end
57
61
 
58
62
  def process_entries
@@ -1,6 +1,5 @@
1
1
  module Feed2Email
2
2
  SENDMAIL = ENV['SENDMAIL'] || '/usr/sbin/sendmail'
3
- MAILTO = ENV['MAILTO'] || ENV['USER']
4
3
 
5
4
  class Mail
6
5
  def initialize(entry)
@@ -9,16 +8,19 @@ module Feed2Email
9
8
 
10
9
  def body
11
10
  body_data = {
12
- :url => @entry.url.escape_html,
11
+ :uri => @entry.uri.escape_html,
13
12
  :title => @entry.title.escape_html,
14
13
  :content => @entry.content,
15
14
  }
16
15
  %{
17
16
  <html>
18
17
  <body>
19
- <h1><a href="%{url}">%{title}</a></h1>
18
+ <h1><a href="%{uri}">%{title}</a></h1>
20
19
  %{content}
21
- <p><a href="%{url}">%{url}</a></p>
20
+ <p><a href="%{uri}">%{uri}</a></p>
21
+ <p>--<br>
22
+ Sent by <a href="https://github.com/agorf/feed2email">feed2email
23
+ #{VERSION}</a> at #{Time.now}</p>
22
24
  </body>
23
25
  </html>
24
26
  }.gsub(/^\s+/, '') % body_data
@@ -64,7 +66,7 @@ module Feed2Email
64
66
  end
65
67
 
66
68
  def to
67
- MAILTO
69
+ @entry.feed.options[:recipient]
68
70
  end
69
71
  end
70
72
  end
@@ -1,3 +1,3 @@
1
1
  module Feed2Email
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/feed2email.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'cgi'
2
2
  require 'feedzirra'
3
+ require 'fileutils'
3
4
  require 'mail'
4
5
  require 'yaml'
5
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feed2email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-24 00:00:00.000000000 Z
12
+ date: 2013-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: feedzirra
@@ -52,7 +52,9 @@ extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
54
  - .gitignore
55
+ - CHANGELOG.md
55
56
  - Gemfile
57
+ - Gemfile.lock
56
58
  - LICENSE.txt
57
59
  - README.md
58
60
  - Rakefile
@@ -90,3 +92,4 @@ signing_key:
90
92
  specification_version: 3
91
93
  summary: RSS/Atom feed updates in your email
92
94
  test_files: []
95
+ has_rdoc: