January 27th, 2007

Making a Blook with WordPress and Pages

For a few months now, I’ve wanted to create a blook (blog + book) from the posts I’ve written in 2006 (something like the Lifehacker book). I’ve been waiting for Blurb to get around to it, but their application can only import wordpress blogs that are hosted on wordpress.com. Since my blog is hosted remotely, that’s a no go. I exchanged a couple emails with somebody at their company who informed me that sometime in 2007 their program would have the ability to import all wordpress blogs, regardless of the hosting situation.

I’m not a patient person.

And so, when I was reminded about my blook desire after reading Ben’s post, I decided to put off the ~10 other things I was supposed to do today (except for attending the temple, of course) and write my own script to do just this.

Here’s what the script does:

  1. At the top you enter the necessary data to connect to your wordpress database as well as a starting and ending date for running the query.
  2. The script will then extract all posts and comments between the given date range.
  3. All links are removed from the posts and comments, leaving just the words that were linked along with a footnote mark. After the post/comment, a list of the links (with their corresponding footnote numbers) is printed.
  4. All embedded youtube and google videos are removed. The script replaces the video with the text {VIDEO: http://urlOfVideo}.
  5. CSS classes are assigned to the post title, date text, links and comment titles, and link list. This allows you to change all global styles in Pages (or a similar app), so that if you want to change all your post titles to red, you can change it once and be done.

Once you’ve configured the script as you want it, upload it somewhere and pull it up in your browser. What you should see is the dump of all the posts/comments in the date range you specified.

I then saved the HTML file to my local machine and opened it up in Pages. I’m sure other programs would work fine as well, but I prefer Pages over Word, and don’t know InDesign all that well.

Opening the file might take a while, depending on the number of posts/comments you extracted. Once the file was open I styled the imported CSS styles as I liked them, applying them globally. To do this, go to View -> Show Styles Drawer. As an example, reformat one of the post titles as you want it, then click on the arrow to the right of the style named “title”. From the drop down, select “Redefine Style From Selection”. This should change all the post titles in the document. Rinse and repeat for other styles as desired.

Pages didn’t import floated elements correctly, so I had to manually format my images so that they floated the text around them.

Once it’s formatted as you want it, simply export it as a PDF and use a service such as Lulu to print!

Download: blook.zip – unzip, remove .txt extension, and upload to your server after configuring.

Enjoy! If you come across any bugs please let me know. Also feel free to modify the script to your heart’s content. It’s license-free. Yum!

UPDATE: This script is now UTF8-compliant and will work for all WordPress blogs, including those that require UTF8. Thanks to Ken.

27 Responses to “Making a Blook with WordPress and Pages”

  1. Connor
    January 27, 2007 at 8:05 pm #

    Hmmm.. Apparently lulu.com has an upper limit of 740 pages for its books. My posts from 2006 (with comments) ended up being 1328 pages long. Drat.

  2. Michael L. Mc Kee
    January 27, 2007 at 9:13 pm #

    Connor

    Your post leaves me absolutely in the dark as I have no idea what you are talking about, and am therefore speechless.

  3. Connor
    January 27, 2007 at 9:21 pm #

    Michael,

    You’ll have to forgive the indulgence of my nerdy side, something I don’t show too often on this blog, as I tend to stick to political/religious topics. I promise it’ll be a long time before I post something technical again. šŸ™‚

  4. mmathson
    January 27, 2007 at 11:06 pm #

    Don’t worry, some of us out here like reading the nerdy stuff šŸ™‚

  5. Carolynn Duncan
    January 29, 2007 at 3:08 pm #

    Connor,

    This is awesome. I’m trying it out. If you don’t mind, I’ll probably send you a tech support question or two. šŸ˜‰ I’m a newbie.

  6. Nathan
    November 22, 2007 at 4:17 pm #

    I just tried to download the script but I’m getting a mysql_connect() error.

    Could you fix this so I can get your script?

    Thanks!

    Nathan

  7. Connor
    November 22, 2007 at 11:40 pm #

    Nathan, the link has been updated to point to a zip file instead. Save that to your computer and that should be usable.

  8. m&m
    January 29, 2008 at 9:59 pm #

    Does this work with Blogger?

  9. Connor
    January 29, 2008 at 10:16 pm #

    M&M,

    As the post notes, this is only for WordPress. šŸ™‚ Hosted blogs (on blogspot.com and wordpress.com) prevent access to the full database, and usually only allow you to export the data in a proprietary format that would have to be parsed through… A project for someone else, perhaps. šŸ™‚

  10. m&m
    January 29, 2008 at 10:47 pm #

    sorry…missed that. Obviously, I’m not a techie. I finally get it, though.

  11. chelle
    February 21, 2008 at 1:39 pm #

    I clinked the link and was sent to a garbled page … is this script still available? I am very interested in trying it out šŸ™‚ Thanks

  12. Connor
    February 21, 2008 at 1:53 pm #

    I’ve updated the link – should be working now.

  13. chelle
    February 21, 2008 at 1:56 pm #

    lol ok, I think I must be doing something wrong … I click and it WORKS! w00t and then I am …. what the … hehe Thanks for updating the link. I look forward to playing around with the script! Seriously thought I was going crazy loco!

  14. Beth
    February 22, 2008 at 2:47 pm #

    I see my husband left a comment above — that was a long time ago now. šŸ™‚

    Just wanted to thank you for the script you wrote! I saw a blook service on a friend’s page but it used Blogger — so I asked around to my technologically-gifted friends and my brother Alex quickly got back to me with this post. My husband (Nathan) then used your script to print out my blog. It was the best birthday present ever — I am so excited! Thanks so much for sharing this!

    Already a few of my blogger-friends with WordPress have asked about it — I am referring them over here. Thanks!

  15. John
    March 3, 2008 at 6:04 pm #

    Thanks for the script… worked like a charm on my wife’s blog. Just submitted a 490 page blook of our family to Lulu.

    Lulu wouldn’t accept the PDF exported by Pages (lulu evidently doesn’t support the Mac 10.4.11 PDF encoding from Pages 08). I re-uploaded as a .doc, and worked fine. Odd.

    I’ve been trying to accomplish this seemingly simple task for about 3 months. Thanks a million!
    John

  16. Karl
    July 11, 2008 at 11:33 pm #

    Thanks so much for posting this!!!!! You saved me a TON of work. You’re great. The only glitch I ran into was that lulu wouldn’t accept a Pages document nor would it accept a PDF that was created from Pages. So, I had to export my Pages document as a Word document and then it worked fine.

  17. Jeff T.
    October 17, 2008 at 9:35 am #

    So, is there an easy way to do this for wordpress.com blogs? Or should I just covert to wordpress.org… since I know I will eventually someday anyways…

  18. jenn
    February 5, 2009 at 3:49 pm #

    Any chance you’ll write up a more step-by-step tutorial on how to use this little gem for those of us who aren’t terribly techie? I’ve got a basic knowledge of CSS, and I *think* I’ve entered the correct info in the script for my personal preferences. But, when you say “upload it somewhere and pull it up in your browser” I get lost (on what should probably be the easiest part!). Can you give me a little more direction on where a good place to upload it is?

  19. coolreddy
    February 12, 2009 at 10:41 pm #

    Awesome! This is a great script. I use my wordpress install as my personal daily diary, and wanted a way to get a report of what I did during a particular week. This works great! Thanks a lot for sharing this. The only problem I see with the script is that it collects all the different revisions of the post. For now I disabled the revision control, but it still dumps 2 versions of the same post. Any ideas? Thanks!

  20. Tobeob
    March 7, 2009 at 6:26 am #

    Fantastic idea! Unfortunatly I am getting the same problem as coolreddy šŸ™

  21. Tobeon
    March 7, 2009 at 6:51 am #

    Ah ha, simple solution. Edit the php file and on line 35 add “and post_status=’publish'”

    e.g.

    $query = “select wp_posts.ID, post_date, post_title, post_author, post_content, display_name from wp_posts left join wp_users on wp_posts.post_author=wp_users.ID where post_date >= ‘$date_start’ and post_date <= ‘$date_end’ and post_status=’publish'”;

    (I add “and post_type=’post'” aswell because I don’t want my pages in there!)

  22. coolreddy
    May 3, 2009 at 11:13 pm #

    Thank you so much Tobeon.. You rock! This works. Now the next question: I have two categories personal and business. I want to add another “and” to the query so that I can fetch only a specified category.

    I tried adding “and post_category=0, but that doesn’t help. Looks like the category name is stored in wp_terms.I tried adding wp_terms.name=’Personal’, but that doesn’t work as well. I am sure it’s an easy one for a MySQL wiz.. Anyone one have any thoughts?

  23. Todd P. Pennington
    February 25, 2011 at 2:57 am #

    Actually, I’ve only heard blook here in your blog but I like the sound of it. Blog book is really a new and innovative concept for me.

Trackbacks/Pingbacks

  1. Novelr.com - Making People Read - » Blook Plugin - January 28, 2007

    […] Boyack has released a pretty good interesting plugin yesterday in his blog. It basically pulls all the posts you have on a stand-alone wordpress install […]

  2. Blooking : Simplicitas | Ken Liu - January 28, 2008

    […] personally recommend Connor Boyack’s blooking script, which extracts posts from a specified date range and wraps the relevant blocks in CSS styles that […]

  3. Daisy Chain » Birthday Present - April 30, 2008

    […] to add the link to Connor Boyack’s post regarding the script — this is actually what we used, though keep in mind that Nathan tweaked the code a bit to […]

  4. O’DonnellWeb - This is not a homeschooling blog » Blog Archive » links for 2008-06-17 - June 17, 2008

    […] Connor’s Conundrums ƂĀ» Making a Blook with WordPress and Pages (tags: blogging books wordpress) […]

Leave a Reply

Leave your opinion here. Please be nice. Your Email address will be kept private.