From: khamidou Date: Sat, 31 Jan 2009 06:50:10 +0000 (+0100) Subject: Still porting to python X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=5bd04ed3fb85e5eede2633279c58848f49c42f09;p=fh.git Still porting to python --- diff --git a/README b/README index 47ec9df..34c2bd0 100644 --- 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 ================= diff --git a/fh-fetch.py b/fh-fetch.py index b227a39..4e89860 100644 --- a/fh-fetch.py +++ b/fh-fetch.py @@ -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() diff --git a/fh-inc.rb b/fh-inc.rb index c624149..1d2fa4c 100644 --- 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" diff --git a/fh-show.rb b/fh-show.rb index 050f4b9..6612b1f 100644 --- a/fh-show.rb +++ b/fh-show.rb @@ -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")