From c33d051bd69f528a6a22760c6e431737bd7ec4be Mon Sep 17 00:00:00 2001 From: khamidou Date: Sun, 25 Jan 2009 14:21:29 +0100 Subject: [PATCH] porting to python --- fh-fetch.py | 18 +++++++++++++ fh-fetch.rb | 74 ----------------------------------------------------- 2 files changed, 18 insertions(+), 74 deletions(-) create mode 100644 fh-fetch.py delete mode 100644 fh-fetch.rb diff --git a/fh-fetch.py b/fh-fetch.py new file mode 100644 index 0000000..b227a39 --- /dev/null +++ b/fh-fetch.py @@ -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 index d65f28b..0000000 --- a/fh-fetch.rb +++ /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) -- 2.43.0