Sat, 01 Sep 2007

Recovering a Pyblosxom blog using liferea's RSS cache

My buddy who used to host didn't pay his bills, so his server got taken down last week. What sucks is I that never backed up my Pyblosxom data. What doesn't suck is that thankfully Liferea, my RSS reader, did for me.

Grepping through ~/.liferea_1.2/cache/feeds, I was able to find my blog cached in some XML format. Then I wrote a little bit of code to re-create my Pyblosxom entry structure with the proper filenames and timestamps.

#!/usr/bin/python -tt
 Turns XML into pyblosxom blog entries.

 It parses BLOG_XML pulling out blog entires in the form of:

     <feed version="1.1">

 The file '2007/08/20/bar.txt' will be created in pyblosxom format with
 the appropriate timestamp.  The #mdate is used by the pyblosxom.vim plugin.

     #mdate Aug 20 10:47:48 2007

import os
import time

try: from xml.etree import cElementTree
except ImportError: import cElementTree
iterparse = cElementTree.iterparse

entries = {} # { 'title' : <Element> }

BLOG_XML = 'blog.xml'

def getField(elem, field):
    for child in elem:
        if child.tag == field:
            return child.text

## Pull out all feed items, removing older duplicates
for event, elem in iterparse(BLOG_XML):
    if elem.tag == 'feed':
        for child in elem:
            if child.tag == 'item':
                title = getField(child, 'title')
                if entries.has_key(title):
                    if int(getField(child, 'time')) > \
                       int(getField(entries[title], 'time')):
                        entries[title] = child
                    entries[title] = child

for title, entry in entries.items():
    source = getField(entry, 'source').replace(BLOG_ROOT, '')
    source = source.replace('.html', '.txt')
    if not os.path.isdir(os.path.dirname(source)):
    output = file(source, 'w')
    output.write(title + '\n')
    mtime = time.localtime(int(getField(entry, 'time')))
    mdate = time.strftime("%b %e %H:%M:%S %Y", mtime)
    output.write("#mdate %s\n" % mdate)
    output.write("<p>%s</p>\n" % getField(entry, 'description'))
    timestamp = time.strftime("%y%m%d%H%M", mtime)
    os.system("touch -t %s %s" % (timestamp, source))

It also adds an #mdate tag into each entry, which read by the spiffy pyblosxom mdate vim hack that Jordan Sissel wrote to restore each entries original timestamp after editing. His code only works on FreeBSD at the moment, so I started a pyblosxom.vim plugin that works on Linux (hopefully it will eventually support both, along with a bunch of other handy functions). You can find all of this code in my mercurial repo:

posted at: 16:44 | link | Tags: , , | 37 comments

Posted by heevepsycle at Mon Jul 14 11:10:23 2008

Please come  my new blog

Let's talk about it

Posted by thantymoplaph at Wed Oct 29 20:50:47 2008

Very interesting blog. Be good to my  ticklish  crisis  I have a nice fresh joke for you people)  How many Microsoft employees does it take to screw in a lightbulb? None. We'll just declare darkness the new standard.

Posted by buzi at Fri Oct 31 10:27:53 2008

Hi! I found a nice online pharmacy! Viagra 10 pills x 25 mg

Posted by bob at Sat Jan 3 11:44:22 2009

zfuWVK hi nice site thanx

Posted by bob at Sat Jan 3 11:44:58 2009

zfuWVK hi nice site thanx

Posted by yuvutu at Sun Jan 4 13:06:53 2009

Heather wound her hand around each cock and began pumping them up and down gently <a href=" ">yuvutu mature</a> =) <a href=" ">youtubeporno</a>

Posted by thehun at Sun Jan 4 22:40:43 2009

I agreed quickly as I simply wanted to see the cum squirt from one cock before they were spent <a href=" ">www thehun net</a> ;)) <a href=" ">www spankwire co</a>

Posted by redtub at Sun Jan 4 22:47:49 2009

I teased myself for as long as I could before my hand began to drift down my stomach until my fingers touched my dripping pussy lips <a href=" ">redtub com</a> ;)) <a href=" ">m porntube com</a>

Posted by shufuni at Mon Jan 5 02:53:52 2009

They had each used me twice by the time I agreed. Tim said he thought I was lying so he fucked my tiny asshole while forcing me to eat Staci.
<a href=" ">shufuni com</a> ;) <a href=" ">and sextube</a>

Posted by pornhub at Mon Jan 5 10:15:11 2009

Her cunt felt warm and wet and I slowly eased my way fully into her, then held my finger there, lightly feeling her with the very finger tip <a href=" ">xxx pornhub</a> ;) <a href=" ">pinkworld coom</a>

Posted by erotik at Mon Jan 5 20:51:35 2009

He puts his dick in my mouth. It’s so big that it barely fits my mouth. I begin to suck him.  <a href=" ">privat erotik</a> ))) <a href=" ">efukt shake</a>

Posted by Daxickwm at Mon Jan 12 08:09:02 2009

Good crew it's cool :) <a href=" ">sites like porntube</a>  %]]]

Posted by Fxnojabt at Mon Jan 12 08:56:05 2009

Excellent work, Nice Design <a href=" ">lolitateens</a>  tsjnet

Posted by Xottbcno at Tue Jan 13 02:34:26 2009

I love this site <a href=" ">tiny preteen lolitas and boys</a>  341

Posted by Czyzremm at Tue Jan 13 13:01:42 2009

very best job <a href=" ">little lolitas nude porn pics</a>  9204

Posted by Xvjaqeou at Tue Jan 13 19:44:41 2009

Punk not dead  <a href=" ">animal sex movies tube</a>  :O

Posted by Cpfzkszi at Fri Jan 16 05:11:45 2009

It's serious <a href=" ">hardcoretube</a>  0077

Posted by Cpfzkszi at Fri Jan 16 05:11:59 2009

It's serious <a href=" ">hardcoretube</a>  0077

Posted by Atnkpfza at Sat Jan 17 12:54:05 2009

This site is crazy :) <a href=" ">little lolitas nude</a>  75345

Posted by Vdbeqnwu at Sat Jan 17 19:57:10 2009

Best Site good looking <a href=" ">pagina de lolitas little kiss</a>  lduhpq

Posted by Vdbeqnwu at Sat Jan 17 19:57:45 2009

Best Site good looking <a href=" ">pagina de lolitas little kiss</a>  lduhpq

Posted by Rsezttfq at Sun Jan 18 07:18:28 2009

This site is crazy :) <a href=" ">porn yuo tubeporn yutube
</a>  kwhg

Posted by Lrloukwr at Sun Jan 18 16:02:39 2009

I'm happy very good site <a href=" ">animal sex tube 365</a>  yrdh

Posted by Hbgelyae at Fri Jan 23 08:41:54 2009

good post man thx <a href=" ">lolita teens
</a>  =-DDD

Posted by yifguhtf at Thu Jun 18 10:10:29 2009

tfhgvvg tiava hardcore kujgbjvhg thumbzilla pics

Posted by nataly at Mon Jun 22 17:22:55 2009

AZn9bD ghUnxCczpf72ndOqi20g

Posted by Oshrdxyv at Sun Nov 8 21:04:28 2009


Posted by Oshrdxyv at Sun Nov 8 21:05:42 2009


Posted by ViKBLbYpmjwkF at Thu Nov 19 16:29:56 2009


Posted by WsPNdccqY at Thu Nov 19 19:38:02 2009


Posted by NEX-5N at Wed Nov 16 21:55:56 2011

Аз всъщност планира да обсъди вашия блог пост е невероятно реалистично. Да изберат да чуят нещо съвсем ново с това за сметка на наистина предлагат идентични сайт в рамките на моята САЩ по време на този въпрос, така че тази конкретна помощ? И всички много. Аз бях в състояние добър поглед по темата, плюс забелязал голям брой блогове, но в контраст с това. Благодарим ви, че за разкриване на толкова много вътре във вашия уебсайт.

Posted by Tristan at Thu Jan 21 21:27:21 2016

A jiffy bag <a href=" ">nizagara tablets</a>  Basilea has gone through a series of shake-ups this year,including the departure of its chief financial officer just twomonths after that of the firm's founder and chief executive. ($1 = 0.8953 Swiss francs) (Reporting By Katharina Bart; Editing by David Cowell)

Posted by Irving at Thu Jan 21 21:27:30 2016

Is there ? <a href=" ">nizagara 25</a>  Controversial Toronto mayor Rob Ford has publicly admitted to smoking "a lot" of marijuna in the past, amidst allegations that the city leader has some variety of substance abuse problem.

Posted by Josue at Thu Jan 21 21:27:31 2016

No, I'm not particularly sporty <a href=" ">can gp prescribe clomid uk</a>  More than a dozen banks and brokerage firms have beeninvestigated worldwide over alleged Libor manipulation. BarclaysPlc and Royal Bank of Scotland Group Plc havealso reached settlements with authorities.

Posted by Russell at Thu Jan 21 21:27:34 2016

Did you go to university? <a href=" ">25 mg phenergan</a>  The results depict an increasingly acculturated population. Fifty-nine percent of U.S.-born Latinos said they turn exclusively to English-language news sources while 39% said they seek information in English and Spanish. Only 2% of U.S.-born Latinos said they turned to Spanish-language media exclusively for news.

Posted by Lamont at Tue Feb 14 16:51:56 2017

Have you got any ? <a href=" ">trazodone discount coupons</a>  Rousseff, now early into her second four-year term, isunlikely to resign or face the impeachment proceedings calledfor by many opponents
<a href=" ">prednisone dog heavy panting</a>  He could be the most dominant player on the field on many occassions, but he only did that part of the time.

Posted by qnaky2 at Thu Jun 22 04:19:22 2017