]> projects.mako.cc - iron-blogger/blobdiff - import-feeds.py
Punts for 2010-09-20
[iron-blogger] / import-feeds.py
old mode 100644 (file)
new mode 100755 (executable)
index fa370c4..5574167
@@ -1,5 +1,7 @@
+#!/usr/bin/python
 from lxml import html
 import yaml
 from lxml import html
 import yaml
+import sys
 import urllib2
 import urlparse
 
 import urllib2
 import urlparse
 
@@ -17,21 +19,23 @@ def fetch_links(url):
                   'comments' not in l.attrib.get('title','')]
     if candidates:
         return candidates[0].attrib['href']
                   'comments' not in l.attrib.get('title','')]
     if candidates:
         return candidates[0].attrib['href']
-    return links[0].attrib['href']
+    elif links:
+        return links[0].attrib['href']
+    else:
+        print >>sys.stderr, "No link found for %s" % (url,)
+        return None
 
 for (name, u) in users.items():
 
 for (name, u) in users.items():
-    print "[%s]" % name
     for e in u['links']:
         (title, url) = e[0:2]
     for e in u['links']:
         (title, url) = e[0:2]
-        print " - %s:" % title.strip()
         e[0] = e[0].strip()
         if len(e) == 3:
             continue
         link = fetch_links(url)
         e[0] = e[0].strip()
         if len(e) == 3:
             continue
         link = fetch_links(url)
-        if not link.startswith('http:'):
-            link = urlparse.urljoin(url, link)
-        print "   %s" % (link,)
-        e.append(link)
+        if link:
+            if not link.startswith('http:'):
+                link = urlparse.urljoin(url, link)
+            e.append(link)
 
 with open('bloggers.yml', 'w') as f:
     yaml.safe_dump(users, f)
 
 with open('bloggers.yml', 'w') as f:
     yaml.safe_dump(users, f)

Benjamin Mako Hill || Want to submit a patch?