]> khamidou — GitHub mirrors - fh.git/commitdiff
Still porting to python
authorkhamidou <karim@lambda-expr.org>
Sat, 31 Jan 2009 06:50:10 +0000 (07:50 +0100)
committerkhamidou <karim@lambda-expr.org>
Sat, 31 Jan 2009 06:50:10 +0000 (07:50 +0100)
README
fh-fetch.py
fh-inc.rb
fh-show.rb

diff --git a/README b/README
index 47ec9df3fbddd54249ebccb7896092b26d646ba9..34c2bd02f03e91006e2041c1fb2212b6f26e47d5 100644 (file)
--- a/README
+++ b/README
@@ -7,7 +7,8 @@ It has no proper interface because it is
 a collection of programs that work 
 cooperatively.
 
-fh requires ruby and libfeedreader.
+fh requires ruby and python. (I'm porting
+it to python because of universal feed parser).
 
 Quick usage guide
 =================
index b227a3996ccb3b118acae9c358c3bdffba3b9b84..4e898606e6ea8ba0f48f3fec156ef81cb70c542f 100644 (file)
@@ -5,14 +5,47 @@
 #                      show    feed-title,entry-title,entry-contents
 
 import os
+import sys
 import glob
 import feedparser
 
-dir = glob.iglob(os.environ.get("HOME") + "/.fh/feeds/*")
+fetch_params = { "show-subtitle": 1, "show-titles": 1, "show-subtitles": 1, "show-content": 1, }
 
-for file in dir:
-        feed = feedparser.parse(file)
-        print feed.feed.subtitle
+# Parses a string of the form arg1,arg2,arg3
+# If an element is present, put its value to one in fetch_params.
+def parse_arg_list(str):
+       for item in sys.argv[i].strip(","):
+               fetch_params[item] = 1
 
-        for e in feed.entries:
-            print e.title
+def main():
+       for i in range(len(sys.argv[1:])):
+               if (sys.argv[i] == "from"):
+                       pass
+
+               if (sys.argv[i] == "show"):
+                       i += 1
+                       parse_arg_list(sys.argv[i])
+                               
+
+       dir = glob.iglob(os.environ.get("HOME") + "/.fh/feeds/*")
+
+       for file in dir:
+               feed = feedparser.parse(file)
+               if fetch_params["show-subtitle"]:
+                       print feed.feed.subtitle
+
+               for e in feed.entries:
+                       if fetch_params["show-subtitles"]:
+                               print e.title
+                               print "\t"
+
+                       if fetch_params["show-content"]:
+                               if feed.feed.has_key("description"):
+                                       print e.description
+                               elif feed.feed.has_key("content"):
+                                       print e.content
+                               print "\t"
+                                       
+                       print "\n"
+if __name__ == "__main__":
+       main()
index c6241494e052a67b6f5c49487a4c522f8b7ec8ac..1d2fa4c1127cd30c47f5ded687a283996347789c 100644 (file)
--- a/fh-inc.rb
+++ b/fh-inc.rb
@@ -3,7 +3,6 @@
 # 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")
@@ -12,17 +11,19 @@ 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!("/", "-")
+  if line != ""
+    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
+    File.open(ENV["HOME"] + "/.fh/feeds/" + fname, "w+") do |ff|
+      ff.write(s)
+    end
 
-  counter += 1
+    counter += 1
+  end
 end
 
 print "Fetched ", counter, " feeds\n"
index 050f4b9679f92d8bc7d23574bf541bd032cb5480..6612b1f9ab69e7bcfab5a84680a2916ca3002bba 100644 (file)
@@ -9,3 +9,10 @@ ARGV.length.times do | i |
   
 end
 
+# Simply replace tabs by linefeeds.
+
+t = STDIN.read
+
+t.gsub("\t\t\t", "\n")
+t.gsub("\t\t", "\n")
+t.gsub("\t", "\n")