From 4b6805ea6338feb566fb9db5254ae74a16ac0c39 Mon Sep 17 00:00:00 2001 From: khamidou Date: Tue, 3 Feb 2009 14:38:44 +0100 Subject: [PATCH] ported fh-inc to python --- fh-fetch | 4 +--- fh-inc | 39 ++++++++++++++++++--------------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/fh-fetch b/fh-fetch index e013676..4f9b0d8 100755 --- a/fh-fetch +++ b/fh-fetch @@ -12,8 +12,6 @@ import time, datetime import optparse -fetch_params = { "feed-title": 1, "feed-summary": 1, "feed-link": 1, "entry-title": 1, "entry-subtitle": 1, "entry-link": 1, "entry-content": 1, } - sep = "\t" # the separator used to ...separate each entry of the feed pattern = "*" @@ -80,7 +78,7 @@ def print_field(s): def main(): - global fetch_params, to_date, from_date, pattern + global to_date, from_date, pattern p = optparse.OptionParser() p.add_option("-t", "--feed-title", action="store", dest="feed_title", help="Show feed title", default=1) diff --git a/fh-inc b/fh-inc index 1d2fa4c..3be0d94 100755 --- a/fh-inc +++ b/fh-inc @@ -1,29 +1,26 @@ -#!/usr/bin/ruby +#!/usr/bin/python # -# fh-inc - get data from the feeds refered in ~/.fh/feedlist -require 'net/http' -require 'uri' +import urllib2 +import os -fd = File.new(ENV["HOME"] + "/.fh/feedlist") +fd = open(os.environ.get("HOME") + "/.fh/feedlist", "r") -counter = 0 +if fd == -1: + print "error : unable to find ~/.fh/feedlist. You should probably run fh-setup" + os.exit() -fd.each_line do |line| - line = line.chomp - 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!("/", "-") +i = 0 - File.open(ENV["HOME"] + "/.fh/feeds/" + fname, "w+") do |ff| - ff.write(s) - end +for line in fd.readlines(): + request = urllib2.Request(url = line.rstrip()) + feed = urllib2.urlopen(request).read() - counter += 1 - end -end + fname = line.replace("http://", "") + fname = fname.replace("/", "-") + fname = fname.replace('\n', '') + feedfd = open(os.environ.get("HOME") + "/.fh/feeds/" + fname, "w+") + feedfd.write(feed) + i += 1 -print "Fetched ", counter, " feeds\n" +print "Fetched ", i, " feed(s)" -- 2.43.0