Skip to content

Daily del.icio.us Links Script for Wordpress

I’ve been using this PHP script to generate the daily “Links” posts from my del.icio.us links. Although the script works, it has some annoying bugs. For example, if there are no links for the day, it’ll still make a post which I have to manually delete. Furthermore, it’s written in PHP, a language I haven’t gotten around to learning, so I can’t fix or maintain it.

I decided to re-write the script in Perl, a language that I’m much more comfortable using. And so, I present my Daily del.icio.us Links Script for Wordpress. The code is pretty self-explanatory, and there are a few variables you’ll have to set.

Once the configuration variables are set, just add the script to your crontab — it should run once a day, around midnight, GMT time. It will use Net::Delicious to get a list of your del.icio.us links, filter out the links that don’t match the current date, create a nifty HTML version of your links, and post them to your Wordpress blog. If you’d like to see a sample of the output, click here.

Enjoy.

Note: It has come to my attention that del.icio.us now offers a service that does pretty much the same thing as my script, automatically. Natalie Downe has posted instructions on her blog for how to get the service to work with Wordpress blogs. If you want more control over your posts, though, I still recommend my script (OK, and maybe I’m a bit biased ;) ).

Wordpress 2.3 Support: Thanks to everyone for bringing the WordPress 2.3 incompatibility to my attention. I am no longer an active user of del.icio.us. However, I do plan on releasing an update to my script that will provide support for the latest version of WordPress sometime during my Thanksgiving break. In the mean time, Edward de Leau has modified my script to support WordPress 2.3 and added some other nifty features.

Features:

  • Completely self-contained, designed to run as a cronjob.
  • Automatically filters out links not matching the current date.
  • Adds links to tags used.
  • Users may specify post slug, post title, and trackback/comment status.
  • Uses Net::Delicious to maintain future compatibility with any del.icio.us API changes.

Changelog:

  • 10/29/2005: Modified code to use Net::Delicious and DateTime Perl modules to maintain compatibility with future del.icio.us API changes and resolve timezone issues.
  • 8/29/2005: Fixed reversal of gmtime and localtime. Thanks squish!
  • 5/9/2005: I’ve cleaned up the code and added the ability to add links back to the tags you used for a link.

Versions:

{ 34 } Comments

  1. Ken MacGray | 7/22/2005 at 3:16 am | Permalink

    This sounds like the perfect solution for what I’m looking for, thanks for whipping this up! One question though… Where should this script live? In the same directory as my Wordpress install? In doing so, I received the following error from the server:

    usr/home/kmacgray/public_html/kmorg/notes/delicious_links.0_4.pl: not found

  2. Stephen | 7/22/2005 at 9:08 am | Permalink

    You can place this script anywhere you’d like, but I recommend placing it in a directory that is not publically accessible, since the script will contain your Wordpress database login information.

    Assuming that you’re calling the script from crontab and are using the absolute path to the script, it seems that you’ve missed a preceding forward slash - in your case, your path would be /usr/home/kmacgray/public_html/kmorg/notes/delicious_links.0_4.pl instead of just usr/home/kmacgray/public_html/kmorg/notes/delicious_links.0_4.pl.

    If that fails and you have shell access to your host, considering navigating your file structure until you’re at the directory which contains the script. The command “pwd” will give you the absolute path to that directory, and you can append the name of the script to that.

  3. Ken MacGray | 7/22/2005 at 3:29 pm | Permalink

    Stephen, thanks for the assistance. I’ll give your suggestions a try.

  4. Ken MacGray | 7/25/2005 at 3:06 am | Permalink

    Still having some trouble, I’m afraid:

    Couldn’t connect to database: Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2) at /usr/home/kmacgray/deliciouslinks04.pl line 42.

    Is there a variable to specify the database host? How does the script know which database server to connect to?

  5. Stephen | 7/26/2005 at 1:23 am | Permalink

    I’ve uploaded a new test version of the script that supports setting a remote database host. You may find the revised script here. I’ve introduced a new user-configurable variable, $db_host.

  6. Ken MacGray | 7/26/2005 at 11:47 am | Permalink

    Stephen, thanks… I’ll give it a go and let you know.

  7. Ken MacGray | 7/26/2005 at 1:26 pm | Permalink

    Here’s what I’m getting using the newest version of the script:

    DBD::mysql::st execute failed: Table ‘kmacgray_blog.wp__posts’ doesn’t exist at /usr/home/kmacgray/deliciouslinks04.pl line 92.

    DBD::mysql::st execute failed: Table ‘kmacgray_blog.wp__posts’ doesn’t exist at /usr/home/kmacgray/deliciouslinks04.pl line 100.

    DBD::mysql::st fetchrow_array failed: fetch() without execute() at /usr/home/kmacgray/deliciouslinks04.pl line 101.

    DBD::mysql::st execute failed: Table ‘kmacgray_blog.wp__post2cat’ doesn’t exist at /usr/home/kmacgray/deliciouslinks04.pl line 105.

    (Can I get your email to discuss this privately, unless you don’t mind going back and forth in the comments here…)

  8. niepi | 8/10/2005 at 11:14 am | Permalink

    doesn’t work for me. the script misses to enter the guid value in the wp_posts table. the post will be created but never displayed

    is this maybe a permalink problem ?

    niepi

  9. Stephen | 8/10/2005 at 11:21 am | Permalink

    Well, my script does not create a guid value, since that’s highly dependent on your Wordpress configuration. However, as far as I can tell, posts do not need a guid value to be displayed. The ‘Links’ post on my blog are generated using my script, and they seem to work just fine without a guid value.

    Perhaps something else is going wrong? Does the script produce any errors when executed?

  10. squish | 8/29/2005 at 11:31 am | Permalink

    there is an error in the script - gmtime and localtime are switched around - once this is fixed the script works. thanks for the script.

  11. Stephen | 8/29/2005 at 12:07 pm | Permalink

    Thanks for finding the bug! I’ll post an updated version sometime later today.

  12. Scott | 8/29/2005 at 4:02 pm | Permalink

    ahhhh that’s what it is. Great script by the way!

  13. Lee | 11/5/2005 at 2:43 pm | Permalink

    I seem to be having the same problem Ken MacGray had. Can you let us know what the solution was? At least I’m gettting the same 4 error messages, only with different line numbers referenced.

  14. Stephen | 11/5/2005 at 3:07 pm | Permalink

    Check your settings for the $prefix variable. You might need to remove the underscore — that is, the line should read:

    my $prefix = “wp”;

    Hope that works.

  15. Lee | 11/5/2005 at 3:20 pm | Permalink

    Thanks, that did it. Also thanks for the plugin.

  16. Lee | 11/6/2005 at 11:21 am | Permalink

    Sorry, one last issue. I’m not quite clear on the best time-related settings. When should I set the cron job for. I’m on the east coast and my server is on the west coast. Should I set $wp_timezone to be “US/Western”. Does del.icio.us time stamp entries based on GMT?

  17. Stephen | 11/6/2005 at 12:16 pm | Permalink

    del.icio.us stamps entries based upon GMT. Consequently, I recommend setting crontab to execute the script just before midnight GMT. Assuming that the server’s timezone is set to “US/Pacific”, you should tell crontab to run the script around 15:50.

    $wp_timezone should reflect the timezone you have set in your WordPress installation. Since you’re on the East coast, I presume that would be “US/Eastern”.

  18. Lee | 11/6/2005 at 1:15 pm | Permalink

    Thanks again!

  19. mark | 11/30/2005 at 7:37 pm | Permalink

    stephen, thanks for writing this script! i’m running into an interesting issue.. after some perl module install issues with my hosting company, i got the script to work.. once: http://blog.underafter.com/2005/11/26/daily-links/

    i know it’s running because i added a line to the script to output a message when the cron job is called (7:55pm eastern time). but now, it’s been a few days, i have del.icio.us entries, i get output messages every day at 7:55pm, but no blog entries!

    any insight would be thoroughly appreciated!! it’s so close to working…

  20. Stephen | 11/30/2005 at 8:00 pm | Permalink

    I just tested the script to see if del.icio.us made a sudden change in their API, but the script worked, so something must be wrong on your end.

    To help me figure out what went wrong, please add a line that reads “use Data::Dumper;” after the line that reads “use DBI;” and add another line that reads “print Dumper(@posts);” after the line that reads “my @posts = $del->posts( { dt => $time_gmt_day } );”.

    Please reply with the output of the script when you manually execute it.

  21. Brian | 2/10/2006 at 9:37 pm | Permalink

    Has this been abandonaed? I get an error when I try to download the script

  22. Stephen | 2/10/2006 at 9:49 pm | Permalink

    The project has not been abandoned. I incorrectly set something on my webserver, making the file inaccessible. I’ve fixed it now. Thanks for noticing.

  23. cogmios | 9/6/2006 at 12:16 pm | Permalink

    Thank you for the great plugin, i had to man crontab but finally found out i should save my windows edited files in unix format…

    I´m now going to try if i can backtrack through time: so that it grabs all previous del.iciou.us links and inserts them as posts in Wordpress.

  24. Cogmios | 9/10/2006 at 9:37 am | Permalink

    I read “Assuming that the server’s timezone is set to “US/Pacific”, you should tell crontab to run the script around 15:50.”

    I have 2 questions: where can i find a list of possible timezones to set and the corresponding best crontab time settings? I live in Amsterdam, Netherlands, what would be the settings for the timezone and the best crontab time settings?

    Can anybody help me with this?

  25. Cogmios | 9/10/2006 at 9:48 am | Permalink

    I find it difficult to find the correct times, and probably thats why part of my postings for the day are missing in the final output on my blog.

    E.g. (now):
    - my dreamhost server datetime: Sun Sep 10 10:41:25 PDT 2006
    - my wordpress UTC time is 2006-09-10 5:43:56 pm
    - time in wordpress blogpostings differ +2 hours
    - my crontab scripts runs at 23.59

    Hmm….

  26. Cogmios | 9/10/2006 at 9:58 am | Permalink

    Let me change my crontab to 15:50 and see what happens

  27. Sean | 9/11/2006 at 8:38 am | Permalink

    This soution worked well for a customer of mine.

  28. Miguel Iglesias Marques | 11/10/2006 at 9:40 am | Permalink

    There is a 404 error when trying to download the “Latest” file :(
    I managed to download it using Google Cache but I don’t think that it is your idea.

    Cheers!

  29. David | 1/6/2007 at 12:40 am | Permalink

    Downloading is not possible

  30. TWB | 1/16/2007 at 8:35 pm | Permalink

    Try looking here for the most recent file.

  31. Cogmios | 11/12/2007 at 3:55 pm | Permalink

    Some time ago, I installed (I found myself in the comments) but now I moved to MediaTemple. I now get an error as shown here: http://edward.de.leau.net/the-boomerang-perl-error-20071112.html

    Does anybody have a clue what went wrong / what to do? I also asked this here: http://www.tek-tips.com/viewthread.cfm?qid=1426240&page=1

  32. Cogmios | 11/12/2007 at 5:11 pm | Permalink

    Ok I found the problem I had to MAKE Config::Simple first! Now another problem: since Wordpress 2.3 the table wp_post2cat has been deprecated, so the perl script gives an error here :(

  33. Cogmios | 11/13/2007 at 2:09 pm | Permalink

    I believe the following has to be changed from the original script to make it work with the category again AND to include the tags:

    (for each tag)

    1. Look for tag in wp_terms table

    2. If it does not exist:

    Add a new terms record

    3. Retrieve ID ($retrieved_term_id)

    4. Look in wp_tag_taxonomy table for $retrieved_term_id+”post_tag”

    5. If it does not exist:

    Add a new taxonomy record to the wp_term_taxonomy table

    6. Retrieve ID ($retrieved_term_taxonomy_id)

    7. Do a count++ on the count field where term_taxonomy_id = $retrieved_term_taxonomy_id

    8. Add to the wp_terms_relationships table the object_id and the $retrieved_term_taxonomy_id

    (only once)

    Add to the wp_terms_relationships table the object_id and the term_taxonomy_id which the user indicated in the perl script.

  34. Cogmios | 11/14/2007 at 5:26 pm | Permalink

    I have made an update to your script to let it work with WordPress 2.3 and made some enhancements: either 1 post or multiple posts and synchronization with WordPress’s tagging system, here: http://edward.de.leau.net/wordpress-23-compatible-wordpress-delicious-daily-synchronization-script-20071114.html

{ 17 } Trackbacks

  1. [...] I’ve released a new version of my Daily del.icio.us Links Script for Wordpress. This new version introduces the use of the Net::Delicious and DateTime Perl modules to parse del.icio.us links and handle timezone differences between GMT and WordPress. As all known issues have been resolved and all basic functionality implemented, I am tagging this release version 1.0. Please refer to the latest “Links” post to see an example of the new version’s output. [...]

  2. [...] Daily del.icio.us Links Script for Wordpress - 看了一下,Net::Delicious 需要太多的 perl module 了,安裝麻煩,還是先擱著。 [...]

  3. [...] Da der daily link post von del.icio.us in den letzten Tagen auch keine Lust mehr hatte, läuft er jetzt von einem lokalen Perl-Skript aus. Das lässt sich auch viel leichter anpassen, sodass ich mir die Handarbeit (Titel der Einträge umbenennen) sparen kann. Demnächst läuft Ghazzog the Horrible dann also ganz ohne mein Zutun… 0 Minuten alt [...]

  4. [...] I’ve released a new version of my Daily del.icio.us Links Script for Wordpress. This new version introduces a code cleanup and the ability to show the tags associated with a link as well as links to your del.icio.us page of those tags. Please refer to the latest “Links” post (see below) to see an example of the new version’s output. [...]

  5. [...] Напоследок предлагаю вашему вниманию набор плагинов по работе с del.icio.us для Wordpress, в частности весьма занимательным выглядит плагин Daily del.icio.us Perl Script, который автоматически добавляет новый пост, содержащий свежедобавленные вами ссылки в ваш же блог. Если кто – нибудь еге попробуйте – пожалуйста сообщите о результатах. [...]

  6. [...] Напоследок предлагаю вашему вниманию набор плагинов по работе с del.icio.us для Wordpress, в частности весьма занимательным выглядит плагин Daily del.icio.us Perl Script, который автоматически добавляет новый пост, содержащий свежедобавленные вами ссылки в ваш же блог. Если кто – нибудь еге попробуйте – пожалуйста сообщите о результатах. [...]

  7. [...] Vaikka tämä onkin varsinaisesti podcast, niin ajattelimme tarjoilla myös linkkejä. Keräämme joka ilta päivittäin del.icio.us-palveluun lykätyt linkit ja taiomme ne tänne pienellä perl-magialla. [...]

  8. [...] I have spent a considerable amount of time this weekend adding content to the side column of my blog - my next step is to start on my wiki (so proud of myself that I was able to install mediawiki on my web space).  I am always on the look out for new features to add for my blog and started to notice a links generator popping up on some of the sites that I visit.  Check out the NMC Campus Observer and Managing the Grey (CC. Chapman’s Blog) for an example.  After a bit of investigation I found the code for this on a blog authored by a Berkeley student - Trapped at Berkeley.  I have to give it a try as soon as I have time to figure out what the whole crontab thing - probably not as hard as it seems. [...]

  9. Inscrições » Mudanças | 11/10/2006 at 4:02 pm | Permalink

    [...] Daily Del.ici.ous Links [...]

  10. [...] Despite the dearth of posts here, I have been generally fulfilling my self-imposed obligation to write every day and share the results with you. I just haven’t been sharing the results with you. The deal is, most of the stuff I’ve been writing has been just too long to be posted to del.icio.us, where I do, arguably, the bulk of what can be considered my blogging.  (You could be forgiven for not knowing that, but now I think I’ve now hooked it up so that every day a script will automatically post my daily activity as a blog entry here on the main page along with commentary and tags.)  As it was just too short to get onto del.icio.us in some way, most of it didn’t seem long enough to warrant a full blog post.  As you can tell, looking downscreen or into the archives, my posts tend to be a bit long.  The more I went over what I was writing, though, the thoughts got more substantial and now, I think, it’s time to publish.  So there ya go. [...]

  11. [...] Trapped at Berkeley » Blog Archive » Daily del.icio.us Links Script for Wordpress - The Rants of a UC Berkeley Student (tags: wordpress web tools howto) [...]

  12. [...] Rather than re-invent the wheel, I decided to investigate Wordpress plugins, many of which are listed on the Wordpress site. I wasn’t interested in ones that displayed the links in the sidebar or ones which post on a link by link basis. My favourite was the Perl script that runs on a daily basis as a crontab, it produces the right output but unfortunately the link to download the latest version was a 404. [...]

  13. [...] Zoals ik vorige maand al aangaf, een aantal testgerelateerde blogs zal ik in de categorie Testlinks plaatsen. De makkelijkste oplossing zou zijn dat ik hiervoor het Del.icio.us script gebruik, maar die automatische posts ben ik een beetje van teruggekomen. Bovendien is de titel van zo’n post totaal niet relevant, al zou het zou nog wel helpen als je de moeite neemt een (uitgebreide) toelichting bij iedere toevoeging op te nemen. [...]

  14. [...] de.licio.us also has a function that will auto post bookmarked links to a blog. After a bit of searching and ran across an explanation of it on Natalie Downe’s blog (via this post on Trapped at Berkeley). [...]

  15. [...] Daily del.icio.us Links Script for Wordpress A Perl script for posting del.icio.us links to your wordpress blog on a regular basis. I’ll look at the code later to see if it is any better than the service Delicious provides. (tags: perl webdev blog blogging delicious wordpress) [...]

  16. [...] scripts folder and *presto* it worked. Well… now just a bug remains which is partly because it can not write to table wp_post2cat, which has recently been depricated by WordPress [...]

  17. [...] had been running the synchronization script from Stephen from Trapped At Berkley for a while but noticed it was not upgraded to make use of WordPress 2.3’s tagging system and [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *