Sync Delicious with WordPress daily (including tags) script

A Script that will synchronize your delicious Postings and Tags with WordPress Postings and Tags

In 2007 I 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 furthermore broke because the older category table was no longer available. So I added the changes and posted the result here to share this with you.

I added some features in between and at the end of 2010 I added one more filter and a better installation description and WP MU support and a separate config file.

I have been running this script now for over 5 years without any problems and apart from the changes in 2007 without any changes. So… trust me… this is the best solution for one-way syncing delicious bookmarks with WordPress. (see the sidebar on http://edward.de.leau.net)

(you can download it below)

What does it do

The script can be scheduled to daily post either 1 “daily links” posting with your del.icio.us bookmarks from that day or multiple postings with in each posting one del.icio.us bookmark. (see features below).

Why not a WordPress Plugin / why Perl

I believe that sync and ETL tooling should not intermix with the product your are syncing to or from. From an architectural point of view a solution outside of WordPress is much cleaner than a plugin inside WordPress. (e.g. suppose you need to sync your delicious bookmarks to multiple other systems or have more advanced integration needs etc…). The code to put information inside WordPress could however be improved to work on an API level and not on a database level to make the script better resistant against big WordPress upgrades that break the database. Then again, the chance that the API changes instead of the database is higher (since it only happened in 2007) and thus I choose the “on-demand” route if it happens again. And why Perl? Because anyone can understand Perl, hack Perl and it is available on any platform.

Features

  • Fully WordPress 2.x to 3.x compatible
  • Allows you to set a category (like the original)
  • Either 1 daily links posting or multiple postings per del.icio.us bookmark
  • Synchronizes your del.icio.us tags with your WordPress tags (quite handy) *)
  • Still allows you, if you want, to post the links to del.icio.us tags
  • Multiple postings can each have its own slug (added in 2.3.1)
  • Parameter to show private delicious postings (or not) (by Christopher Craig) (added in 2.3.2)
  • UTF8 (added in version 2.3.3) (12 june 2009)
  • *) and since you might forget that you enter spaces between tags in delicious and comma’s between tags in WordPress I added the option to remove comma’s on 29 oktober 2010
  • It’s a standalone Perl script so you can re-use the code to interact with more products all from the same crontabbed script.
  • Uses Net::Delicious to maintain future compatibility with any del.icio.us API changes.
  • Completely self-contained, designed to run as a cronjob.
  • Automatically filters out links not matching the current date.
  • WordPress MU Compatible
  • Separate configuration file for easier maintenance

Requirements

  • Your webserver hosting needs to support perl scripts (if you see “cgi” you are ok also, mostly) (most do)
  • Your webserver hosting needs to support crontab / scheduling of certain scripts
  • An editor (to edit the script and enter your database username / password)
  • Basic knowledge on what a perl script is and how you can schedule scripts

Installation Instructions

  1. Download the files (see below)
  2. Edit the config file “wpds.ini” (see below)
  3. Copy it to your scripts directory (ask your webhost) (with mediatemple it is /data/scripts/) (your webhost will have made one directory where you can place (Perl) scripts.
  4. Make sure you have all the required Perl libraries installed, particularly:
    1. The Net::Delicious library (by Aaron Straup Cope)
    2. The Config::Simple package (by Sherzod B. Ruzmetov)
      (depending on your host it could be that some Perl modules are available and others not so it is hard to give a generic description on what modules are needed, if you are lucky it will work directly because all modules are already available, (if you have questions just use the comment section below) (if some modules are not present you will get an error that a library is missing, it is simple to install missing libraries) (if you are still unsure about what Perl modules / libraries are: there are millions of threads to be found on this basic concept) (don’t be afraid to learn something new)
  5. Schedule your script via a crontab, either by the shell or via your control panel e.g. 15:50 for Dreamhost or Mediatemple. Make sure it runs once a day around midnight. (With most hosting companies you have somewhere in your control panel an icon that lets you schedule scripts, look for it!)

How to test it

Well… just run it! Via the command shell you can simply run “perl wpds.pl” and if anything is wrong (e.g. missing libraries) you will find out because it returns errors. If you are scary of a command shell, then just schedule it to run “now” and e-mail yourself the results. If you find errors send to you, you know what to do. If you don’t look in WordPress if anything showed up.

If you are not running it on the day itself as the bookmarks have been published in delicious then change in the script the gmt day to one day in the past (see the script for instructions) (since it will only grab bookmarks for that particular day).

As said, I have synced hundreds of these things the past 5 years without looking at the scheduled script, except for the big change in 2007 and the minor adjustments I made in the years after. It still runs great, scheduled, auto linklogging away.

What you can configure

There is a lot you can configure in this solution, all the configurable things are in the seperate .ini file for easy maintenance and upgrades. I hope the descriptions in the ini file are enough, else let me know.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
[timezone]
; the timezone you have set in Wordpress
wp_timezone = "US/Pacific"

[delicious]
; your delicious username and password (needed!)
del_username = "XXXXXXXXXXX"
del_password = "XXXXXXXXXXX"
; 1 - show private posts. 0 - don't show private posts.
del_showprivate = 0

[wordpress]
; WordPress host - just look it up in wp-config.php
db_host = "XXXXXXXXXXX"
; WordPress database user
db_user = "XXXXXXXXXXX"
; WordPress database password
db_pass = "XXXXXXXXXXX"
; WordPress database
db_name = "XXXXXXXXXXX"
; WordPress database prefix (if you changed it from default, which you should)
prefix = "wp"
; WordPress default taxonomy type for posts
taxonomy_type = "post_tag"
; taxonomy_term id for the category (look it up in WordPress)
taxonomy_term_id = 14
; default user
wp_userid = 1
; Multisite: Experimental (use it with userid)
; for multisite: enter the blog id if it is higher than 1 else leave it on 1 or 0 for single site
; (since wp3 my table is then (prefix)_(wp_mu_blog_id)_tablename)
wp_mu_blog_id = 0;

[parameters]
; title of post (in the wpds code the date is added after this string)
post_title = "Links for "
; allow comments? (open|closed)
allowcomments = "open"
; allow pings? (open|closed)
allowpings = "open"
; post slug
post_name = "daily-links"
; all in 1 daily post ("single") or multiple posts ("multiple")
post = "multiple"
; string to put before multiple posts title
multipleTitle =  "Eds links for "
; remove comma from tags
remove_comma = 1

Download

http://wordpress.org/extend/plugins/wordpress-23-compatible-wordpress-delicious-daily-synchronization-script/

Happy linklogging!

About cogmios

Blogger
This entry was posted in code and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>