]> khamidou — GitHub mirrors - fh.git/commitdiff
First commit
authorkhamidou <karim@lambda-expr.org>
Fri, 23 Jan 2009 18:53:26 +0000 (19:53 +0100)
committerkhamidou <karim@lambda-expr.org>
Fri, 23 Jan 2009 18:53:26 +0000 (19:53 +0100)
README [new file with mode: 0644]
README~ [new file with mode: 0644]
fh-fetch.rb [new file with mode: 0644]
fh-fetch.rb~ [new file with mode: 0644]
fh-inc.rb [new file with mode: 0644]
fh-inc.rb~ [new file with mode: 0644]
fh-show.rb [new file with mode: 0644]
fh-show.rb~ [new file with mode: 0644]

diff --git a/README b/README
new file mode 100644 (file)
index 0000000..47ec9df
--- /dev/null
+++ b/README
@@ -0,0 +1,90 @@
+fh, the feed handler                    
+
+fh is a feed reader which is designed,
+contrary to the more common feed readers,
+to be used only from the command line.
+It has no proper interface because it is
+a collection of programs that work 
+cooperatively.
+
+fh requires ruby and libfeedreader.
+
+Quick usage guide
+=================
+
+fh is for the moment, composed of three
+programs :
+fh-inc,        which downloads the feeds from
+       the internet
+
+fh-fetch, which selects feeds according
+         to a given pattern
+
+fh-show, which display the feeds on the
+        screen
+
+fh-fetch and fh-show are two different
+programs because I wanted to give to 
+the user the possibility of grepping an
+input feed and still to be able to read
+the whole feed.
+
+The fh-inc takes no arguments.
+And reads a file named ~/.fh/feedlist
+which contains one feed address per line.
+fh-inc fetches the corresponding feed and
+stores it in ~/.fh/feeds.
+
+Here is a list of options that can be used
+with fh-fetch:
+
+fh-fetch from date [to date]
+        => fetches the feeds between two
+           dates. 
+           Note that by default, fh-fetch
+           gets the feeds created between
+           yesterday and today.
+
+fh-fetch feeds "posix-regexp"
+        => selects only the feeds who match
+           posix-regexp
+
+fh-fetch show [comma-separated-values]
+        => display only the elements 
+           corresponding to the specification
+           ex:
+           show feed-title,entry-title
+           will display only the title of each
+           feed and the title of each entry.
+
+           The available values are :
+           feed-title, entry-title, 
+           entry-contents
+
+
+Author
+======
+
+fh was written by Karim Hamidou.
+
+Copying
+=======
+
+Copyright (c) 2009, Karim Hamidou
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 
+      in the documentation and/or other materials provided with the distribution.
+    * Neither the name of Karim Hamidou nor the names of its contributors may be used to endorse or promote products derived from this
+      software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
diff --git a/README~ b/README~
new file mode 100644 (file)
index 0000000..a70541b
--- /dev/null
+++ b/README~
@@ -0,0 +1,28 @@
+fh, the feed handler                    
+
+fh is a feed reader which is designed,
+contrary to the more common feed readers,
+to be used only from the command line.
+It has no proper interface because it is
+a collection of programs that work 
+cooperatively.
+
+Quick usage guide
+=================
+
+fh is for the moment, composed of three
+programs :
+fh-inc,        which downloads the feeds from
+       the internet
+
+fh-fetch, which selects feeds according
+         to a given pattern
+
+fh-show, which display the feeds on the
+        screen
+
+fh-fetch and fh-show are two different
+programs because I wanted to give to 
+the user the possibility of grepping an
+input feed and still to be able to read
+the whole feed.
\ No newline at end of file
diff --git a/fh-fetch.rb b/fh-fetch.rb
new file mode 100644 (file)
index 0000000..d65f28b
--- /dev/null
@@ -0,0 +1,74 @@
+#!/usr/bin/ruby
+#
+# Fetch the specified entries.
+# Arguments : fh-fetch         from    date [to date]
+#                      feeds   *feed-name-regexp*
+#                      show    feed-title,entry-title,entry-contents
+
+require "feedparser"
+
+fh_to = Time.new()
+fh_from = fh_to - 2592000 # It's yesterday
+
+feeds = "*"
+
+# This hash holds what elements we display.
+# By default, only show the titles of the feeds
+show = { "feedtitle" => 1, "entry-title" => 1, "entry-contents" => 0 }
+ 
+cwd = Dir.getwd
+
+# if ARGV.length == 0
+#   puts "fh-fetch from date [to date]"
+#   puts "      feeds *feed-name-regexp*"
+# end
+
+ARGV.length.times do | i |
+  if (ARGV[i] == "from")
+    fh_from = Time.parse(ARGV[i+1])
+    
+  end
+  
+  if (ARGV[i] == "to")
+    fh_to = Time.parse(ARGV[i+1])
+  end
+
+  if (ARGV[i] == "feeds")
+    feeds = ARGV[i+1]
+  end
+  
+  if (ARGV[i] == "show")
+    show = {}
+    ARGV[i+1].split(",").each { | elem |
+      if (elem == "ftitle" || elem == "feed-title")
+        show["feedtitle"] = 1
+      end
+    }
+  end
+end
+
+
+Dir.chdir(ENV["HOME"] + "/.fh/feeds/")
+
+Dir[feeds].each { | file | 
+  if file != "." && file != ".."
+    s = File.read(file)
+    f = FeedParser::Feed::new(s)
+
+    if (show["feed-title"])
+      print f.title, "\t"
+    end
+
+    f.items.each { |e|
+    
+      if (show["entry-title"])
+        print e.title, "\t\t"
+      end
+      if (show["entry-contents"])
+        print e.to_s, "\t\t\t"
+      end
+    }
+  end
+}
+
+Dir.chdir(cwd)
diff --git a/fh-fetch.rb~ b/fh-fetch.rb~
new file mode 100644 (file)
index 0000000..734df31
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/ruby
+#
+# Fetch the specified entries.
+# Arguments : fh-fetch from date [to date]
+#                     feeds *feed-name-regexp*
+# 
+
+require "Time"
+
+fh_to = Time.new()
+fh_from = fh_to - 2592000 # It's yesterday
+
+feeds = "*"
+
+ARGV.length.times do | i |
+  if (ARGV[i] == "from")
+    fh_from = Time.parse(ARGV[i+1])
+    
+  end
+  
+  if (ARGV[i] == "to")
+    fh_to = Time.parse(ARGV[i+1])
+  end
+
+  if (ARGV[i] == "feeds")
+    feeds = ARGV[i+1]
+  end
+  
+end
diff --git a/fh-inc.rb b/fh-inc.rb
new file mode 100644 (file)
index 0000000..c624149
--- /dev/null
+++ b/fh-inc.rb
@@ -0,0 +1,28 @@
+#!/usr/bin/ruby
+#
+# fh-inc - get data from the feeds refered in ~/.fh/feedlist
+
+require 'net/http'
+require 'feedparser'
+require 'uri'
+
+fd = File.new(ENV["HOME"] + "/.fh/feedlist")
+
+counter = 0
+
+fd.each_line do |line|
+  line = line.chomp
+  s = Net::HTTP::get URI::parse(line)
+  
+  # Each file is named according to the url of the feed.
+  fname = line.gsub("http://", "")
+  fname.gsub!("/", "-")
+
+  File.open(ENV["HOME"] + "/.fh/feeds/" + fname, "w+") do |ff|
+    ff.write(s)
+  end
+
+  counter += 1
+end
+
+print "Fetched ", counter, " feeds\n"
diff --git a/fh-inc.rb~ b/fh-inc.rb~
new file mode 100644 (file)
index 0000000..fa5622c
--- /dev/null
@@ -0,0 +1,3 @@
+#!/usr/bin/ruby
+#
+# fh-inc - get data from the feeds refered in ~/.fh/feedlist
diff --git a/fh-show.rb b/fh-show.rb
new file mode 100644 (file)
index 0000000..050f4b9
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/ruby
+#
+# Formats the (piped) output of fh-fetch.
+# Arguments : fh-show 
+# 
+
+
+ARGV.length.times do | i |
+  
+end
+
diff --git a/fh-show.rb~ b/fh-show.rb~
new file mode 100644 (file)
index 0000000..f3d21a2
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/ruby
+#
+# Fetch the specified entries.
+# Arguments : fh-show from date [to date]
+#                     feeds *feed-name-regexp*
+# 
+
+require "Time"
+
+fh_to = Time.new()
+fh_from = fh_to - 2592000 # It's yesterday
+
+feeds = "*"
+
+ARGV.length.times do | i |
+  if (ARGV[i] == "from")
+    fh_from = Time.parse(ARGV[i+1])
+    
+  end
+  
+  if (ARGV[i] == "to")
+    fh_to = Time.parse(ARGV[i+1])
+  end
+
+  if (ARGV[i] == "feeds")
+    feeds = ARGV[i+1]
+  end
+  
+end