Hacking del.icio.us with Python
I wrote this a few weeks ago, it’s a hack for del.icio.us to scratch an itch that I had. At work we have a communal del.icio.us account so that if one of us finds a link we think might be interesting or informative to the others we can post it, together with our name as a tag to the account.
This is great if you don’t also have a personal delicious account, you just stay logged into delicious and use the ‘post to delicious’ bookmarklet, dandy. The problem for me at least was that I wanted to post to my del.icious, and only occasionally if I found something really interesting, post it to the Torchbox delicious account. In order to do that however, I had to be logged in to my account to use the bookmarklet to post to my delicious, then go to the delicious site log out and then back in again with the Torchbox details in order to use the bookmarklet again. Not optimal!
To scratch the itch I wrote a Python script that runs every 20 minutes from the crontab. I wanted the script to look at my account for link posts I had specified with a particular tag (’fortorchbox’ in my case) and to take these and post to the communal account.
Realising other Torchbox-ers would likely want to use this too, I set up the script to read from a configuration file to know what user names and corresponding tags to look for. Given that all delicious api requests are done over https and require HTTP-Auth, getting the delicious user names and passwords for the accounts of my colleagues was not really a good plan. Instead, the script sucks in and parses the public RSS feed for the user it is looking at. This now means that that the only password you need is that of the communal account.
Instead of the hassle of logging out and in again, all I or any of my colleagues covered by the script have to do is post a link to delicious with the pre-agreed tag. This can be different for each user - mine is ‘fortorchbox’. The script then posts this to the communal account together with a tag of the user who submitted it.
If you suffer from a similar problem of communal link sharing, to use my solution all you need is the python script - which in true modern style losing vowels in proximity to an ‘r’, I called snaflr - the configuration file with the names etc, and the following line in your crontab (which you can run anywhere in your server by typing crontab -e)
0,20,40 * * * * /usr/bin/python /home/natbat/applications/snafflr/sync.py
This then runs every 20 minutes. The first path is the full path to your python (you can get this by typing which python) and the second is where you have put the script - once copied dont forget to rename the file from sync.txt to sync.py, the config file remains as .txt.
I put the script and configuration file outside of my public html directories for privacy as it contains login details for the communal account.
The configuration file is then in the following format:
#Username - tag prefix - tag to look for - mainusername, mainpw username1, realNameToTag1, tagToLookFor1 username2, realNameToTag2, tagToLookFor2 username3, realNameToTag3, tagToLookFor3 username4, realNameToTag4, tagToLookFor4 ...
Each user has their own line, lines starting ‘#’ are comments, and the line starting ‘-’ is the login information for the communal account.
Feel free to take this script and improve it as you like, it is released under the MIT License.
Hi
I am curious as to why the for:xyz tagging that delicious provides does obviously not solve all of your needs.
What part am I not seeing ;]]
cheers,tim
betatim - March 6th, 2007 at 11:51 pmBrilliant! Just what I need. Thanks, Nat!
Drew McLellan - March 7th, 2007 at 12:43 amHey Nat,
This is very cool and one of the reasons I love python, the ability to iteratively concoct a script which scratches one particular itch pretty well.
Are you aware of delicious’ network feature which allows you to bookmark a URL and specify it’s intended for someone in your network. You could add the torchbox account to your network and do away with the need for a script completely.
o2
Otu Ekanem - March 7th, 2007 at 12:53 amThe del.icio.us network feature has the ability to add other accounts to your network, posting then gives you the opportunity to privately links to the people on your network. This didn’t really solve my problem because in order to see the recommended links you have to be logged in to that account. I needed to have any links added to be publicly accessible to avoid the hassle of logging out and back in again, both to post and see what others had posted.
natbat - March 7th, 2007 at 8:25 amThis is great thanks: I’ve been struggling with the same problem.
I ended up using Pukka on my iBook to post to different accounts, which is almost there, but as far as I can tell there’s nothing similar for the Windows box I use at work.
stevepaperjam - March 7th, 2007 at 10:35 amAha! I see why now.
Otu Ekanem - March 7th, 2007 at 12:36 pm“in order to see the recommended links you have to be logged in”
del.icio.us gives you an rss feed for the for:user page so in about five minutes you could write a PHP/Perl/Python/whatever page which just merges the feeds from the torchbox account and the for:torchbox page
That would seem like a more elegant solution.
Phil Wilson - March 7th, 2007 at 1:49 pm[…] Hacking del.icio.us with Python python script to maintain a commonal del.icio.us account from several individual accounts (tags: del.icio.us python collaboration script folksonomy tags) […]
links for 2007-03-08 at maven - March 8th, 2007 at 2:26 am[…] So I was very pleased to discover (via Simon Willison, and a twitter post from Drew) Nat Downe’s snafflr script, which will check a specified list of delicious accounts and post links with a certain tag to another account. And so it is that so long as I tag items correctly, a cron job will find the links I want to add to this blog, and once a day they’ll be posted for me using delicious’ own blogging support. […]
a work on process » Link blogging - March 8th, 2007 at 10:39 pm[…] Thanks to Simon Willison I came across Snafflr and liked the idea, but I wanted to implement it using del.icio.us’s native “for:” tag. — […]
ProgProg : Shared Del.icio.us Accounts with Python - November 1st, 2007 at 1:02 am