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
gmtimeandlocaltime. 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:
July 22nd, 2005 at 3:16 am
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
July 22nd, 2005 at 9:08 am
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.
July 22nd, 2005 at 3:29 pm
Stephen, thanks for the assistance. I’ll give your suggestions a try.
July 25th, 2005 at 3:06 am
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?
July 26th, 2005 at 1:23 am
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.
July 26th, 2005 at 11:47 am
Stephen, thanks… I’ll give it a go and let you know.
July 26th, 2005 at 1:26 pm
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…)
August 10th, 2005 at 11:14 am
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
August 10th, 2005 at 11:21 am
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?
August 29th, 2005 at 11:31 am
there is an error in the script – gmtime and localtime are switched around – once this is fixed the script works. thanks for the script.
August 29th, 2005 at 12:07 pm
Thanks for finding the bug! I’ll post an updated version sometime later today.
August 29th, 2005 at 4:02 pm
ahhhh that’s what it is. Great script by the way!
October 29th, 2005 at 6:47 pm
[...] 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. [...]
November 5th, 2005 at 2:43 pm
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.
November 5th, 2005 at 3:07 pm
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.
November 5th, 2005 at 3:20 pm
Thanks, that did it. Also thanks for the plugin.
November 6th, 2005 at 11:21 am
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?
November 6th, 2005 at 12:16 pm
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”.
November 6th, 2005 at 1:15 pm
Thanks again!
November 30th, 2005 at 7:37 pm
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…
November 30th, 2005 at 8:00 pm
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.
December 18th, 2005 at 5:30 pm
[...] Daily del.icio.us Links Script for Wordpress – 看了一下,Net::Delicious 需要太多的 perl module 了,安裝麻煩,還是先擱著。 [...]
December 30th, 2005 at 4:03 am
[...] 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 [...]
February 10th, 2006 at 9:37 pm
Has this been abandonaed? I get an error when I try to download the script
February 10th, 2006 at 9:49 pm
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.
April 23rd, 2006 at 1:08 am
[...] 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. [...]
August 10th, 2006 at 6:47 am
[...] Напоследок предлагаю вашему вниманию набор плагинов по работе с del.icio.us для Wordpress, в частности весьма занимательным выглядит плагин Daily del.icio.us Perl Script, который автоматически добавляет новый пост, содержащий свежедобавленные вами ссылки в ваш же блог. Если кто – нибудь еге попробуйте – пожалуйста сообщите о результатах. [...]
September 6th, 2006 at 12:16 pm
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.
September 8th, 2006 at 1:00 pm
[...] Напоследок предлагаю вашему вниманию набор плагинов по работе с del.icio.us для Wordpress, в частности весьма занимательным выглядит плагин Daily del.icio.us Perl Script, который автоматически добавляет новый пост, содержащий свежедобавленные вами ссылки в ваш же блог. Если кто – нибудь еге попробуйте – пожалуйста сообщите о результатах. [...]
September 9th, 2006 at 9:46 am
[...] 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. [...]
September 10th, 2006 at 9:37 am
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?
September 10th, 2006 at 9:48 am
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….
September 10th, 2006 at 9:58 am
Let me change my crontab to 15:50 and see what happens
September 11th, 2006 at 8:38 am
This soution worked well for a customer of mine.
October 1st, 2006 at 7:33 am
[...] 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. [...]
November 10th, 2006 at 9:40 am
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!
November 10th, 2006 at 4:02 pm
[...] Daily Del.ici.ous Links [...]
December 18th, 2006 at 5:58 pm
[...] 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. [...]
December 24th, 2006 at 10:42 am
[...] 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) [...]
December 24th, 2006 at 4:24 pm
[...] 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. [...]
January 6th, 2007 at 12:40 am
Downloading is not possible
January 6th, 2007 at 5:02 am
[...] 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. [...]
January 16th, 2007 at 8:35 pm
Try looking here for the most recent file.
April 16th, 2007 at 3:21 pm
[...] 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). [...]
June 12th, 2007 at 8:31 pm
[...] 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) [...]
November 12th, 2007 at 3:55 pm
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
November 12th, 2007 at 5:11 pm
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
November 12th, 2007 at 5:16 pm
[...] 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 [...]
November 13th, 2007 at 2:09 pm
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.
November 14th, 2007 at 5:25 pm
[...] 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 [...]
November 14th, 2007 at 5:26 pm
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
August 14th, 2008 at 12:52 am
[...] http://stephen.evilcoder.com/archives/2005/02/27/daily-delicious-links-perl-script [...]
January 30th, 2009 at 2:04 pm
[...] Delicious links is gone, gasp! But don’t worry, they’ll now appear in daily posting via a handy little Perl script (thanks Stephen). I also experienced some social media angst, and merged my egykan delicious [...]