]> khamidou — GitHub mirrors - fh.git/commitdiff
porting to python
authorkhamidou <karim@lambda-expr.org>
Sun, 25 Jan 2009 13:21:29 +0000 (14:21 +0100)
committerkhamidou <karim@lambda-expr.org>
Sun, 25 Jan 2009 13:21:29 +0000 (14:21 +0100)
fh-fetch.py [new file with mode: 0644]
fh-fetch.rb [deleted file]

diff --git a/fh-fetch.py b/fh-fetch.py
new file mode 100644 (file)
index 0000000..b227a39
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+# Fetch the specified entries.
+# Arguments : fh-fetch         from    date [to date]
+#                      feeds   *feed-name-regexp*
+#                      show    feed-title,entry-title,entry-contents
+
+import os
+import glob
+import feedparser
+
+dir = glob.iglob(os.environ.get("HOME") + "/.fh/feeds/*")
+
+for file in dir:
+        feed = feedparser.parse(file)
+        print feed.feed.subtitle
+
+        for e in feed.entries:
+            print e.title
diff --git a/fh-fetch.rb b/fh-fetch.rb
deleted file mode 100644 (file)
index d65f28b..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/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)