]> khamidou — GitHub mirrors - fh.git/commitdiff
ported fh-inc to python
authorkhamidou <karim@lambda-expr.org>
Tue, 3 Feb 2009 13:38:44 +0000 (14:38 +0100)
committerkhamidou <karim@lambda-expr.org>
Tue, 3 Feb 2009 13:38:44 +0000 (14:38 +0100)
fh-fetch
fh-inc

index e013676ef19ac76dab46b237752f1194bc5e6cb8..4f9b0d8333c412fef3759dd4b5ab901c2a4aa102 100755 (executable)
--- 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 1d2fa4c1127cd30c47f5ded687a283996347789c..3be0d944a03b496d17458df61de8123485b2ab6d 100755 (executable)
--- 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)"