Commits

Dan Connolly committed 96fd0b2 Draft

- allow selection of posts to convert
- add punctuation to date published syntax
- add vcard markup to author stuff

  • Participants
  • Parent commits 6594c4f

Comments (0)

Files changed (1)

         download(b, indexfp, destdir)
     elif '--convert' in argv:
         indexf, srcdir = argv[2:4]
+        ids = argv[4:]
         posts = pickle.load(open(indexf))
-        print_hatom(posts, srcdir)
+        print_hatom(posts, srcdir, ids)
     else:
         raise ValueError, argv
 
             pickle.dump(e, open(os.path.join(destdir, entry['postid']), 'w'))
 
 
-def print_hatom(posts, srcdir):
+def print_hatom(posts, srcdir, ids):
+    if ids:
+        posts = [post for post in posts
+                 if post['postid'] in ids]
+
     print "<!DOCTYPE html><html>"
     print "<head><meta charset='utf-8'/><title>blog title?</title></head>"
     print "<body>"
     print "</ul>"
     print "</div>"
 
-    print "<div class='hfeed'><h2>Full Text</h2>"
+    print "<div id='drupalbak' class='hfeed'><h2>Full Text</h2>"
     for entry in posts:
         e = pickle.load(open(os.path.join(srcdir, entry['postid'])))
 
         <cite class="entry-title">
           <a href="#post_%(postid)s">%(title)s</a>
         </cite>
-        <br /><em class="published">%(dateCreated)s</em> by
-        <strong class="author vcard"><span class="fn">%(userid)s</span></strong>
+        <br /><em>%(dateCreated)s</em> by
+        <strong>%(userid)s</strong>
       </span>
       '''
     return template % _xmlvals(entry)
       <div class="hentry" id="post_%(postid)s">
         <h3 class="entry-title">%(title)s</h3>
         <a rel="bookmark" class="published" href="%(permaLink)s"
-        >%(dateCreated)s</a> by <strong class="author">%(userid)s</strong>
+        >%(dateCreated)s</a> by
+        <strong class="author vcard"><span class="fn">%(userid)s</span></strong>
         <!--
         %(pprint)s
         -->
     content = entry['content'].replace('&nbsp;', '&#160;')
     if content.strip().startswith('<title>'):
         content = content[content.index('</title>')+len('</title>'):]
-    
+
+    del entry['content']
+    del entry['description']
+    entry = dict(entry, dateCreated=fix_date(entry['dateCreated'].value))
+
     breaks = int(entry.get('mt_convert_breaks', 0))
     if breaks in (1, 3):
         content = '<br />'.join(content.split("\n")) #  todo: optional \r
     else:
         raise ValueError, (entry['postid'], entry['title'], breaks)
 
-    structure = dict([(k, v) for k,v in entry.iteritems()
-                                 if k not in ('content', 'description')])
     return template % dict(dict(_xmlvals(entry)),
                            content=content,
-                           pprint=json.dumps(structure,
-                                             indent=2, cls=DateEncoder))
+                           pprint=json.dumps(entry, indent=2, cls=DateEncoder))
+
+
+def fix_date(d):
+    '''
+    strip time to avoid timezone issues
+    
+    >>> fix_date('20060103T16:32:01')
+    '2006-01-03'
+    '''
+    return '%s-%s-%s' % (d[:4], d[4:6], d[6:8])
+
 
 class DateEncoder(json.JSONEncoder):
     '''