Lisping Flickr

Flickr provides an API for which there are numerous language bindings. A binding for Lisp was, however, missing, and because I wanted to write an application for automating some tasks in Flickr (more on that later on), I decided some time ago to start by implementing bindings to the Flickr API for Common Lisp, aptly named “Clickr”.

Instead of telling you how great my bindings are I think it’s best if I just demonstrate how they work:

Let’s get my Flickr user first and see what my name is:

CL-USER> (defvar *schani* (user-with-name “schani”))
*SCHANI*
CL-USER> (user-realname *schani*)
“Mark Probst”

How many favorites do I have?

CL-USER> (length (user-favorites *schani*))
1675

Every bit of information that Clickr gets from the API is stored. If you request it again, Clickr will used that stored information instead of making the same API calls again. Also, every Flickr object that Clickr knows about corresponds to exactly one Clickr object. If you get, say, the same photo via two different routes, Clickr will give you the same photo object twice.

Let’s do some more complicated stuff! What’s the number of users whose photos are in my favorites?

CL-USER> (defvar *fav-users* (remove-duplicates (mapcar #’photo-owner (user-favorites *schani*))))
*FAV-USERS*
CL-USER> (length *fav-users*)
805

How many of those have faved at least one of my photos?

CL-USER> (length (remove-if-not #’(lambda (user)
(find-if #’(lambda (photo)
(eq (photo-owner photo) *schani*))
(user-favorites user)))
*fav-users*))
183

This last query makes a huge number of API calls, so try it at your own risk! The second time you do it, though, it’s lightning fast!

Clickr can even provide you with some information not available through the API:

CL-USER> (photo-num-views (first (user-photos *schani*)))
127
CL-USER> (photo-num-faves (first (user-photos *schani*)))
3

I need that information for my little application, and since the Flickr API still doesn’t provide it, Clickr has to fetch the photo page and extract those numbers from the HTML code.

On to my application, which I’ve called “Automatr”! There are lots of groups on Flickr, like top-f or top-v, whose only posting requirements are that your photo fulfills some simple “counting” rule. In the case of top-f the rule is that you can post any image provided that it has at least 25 faves. Being very lazy I wanted a tool that did those posting jobs for me automatically, which is why I wrote Automatr.

Right now Automatr can do five things: Adding and removing tags, adding and removing photos to and from groups and adding photos to sets. Let’s look at the simplest job, adding a tag! Let’s say that I want to add the tag “top-f25″ to all my photos which have at least 25 faves. Here’s the Automatr rule for that:

(add-action ‘add-top-f25-tag
‘(add-tag “top-f25″)
‘(>= (count faves) 25))

The first argument is just the name of the rule and can be anything. The second argument is the action and the third argument is the condition under which the action is to be applied. Of course Automatr is smart enough not to try to add the tag a second time, so it’s not necessary to specify that only photos without that same tag be tagged.

Groups are more complicated in that they need to be declared first. Here’s the declaration of the top-f group:

(defgroup ‘top-f
“23561440@N00″
:max-batch 1)

The main argument here is the ID of the group. The easiest way to get to it that I know of is to look it up in the HTML source of the group page. Yeah, it sucks. Clickr should be able to do that automatically if you provide it with the group URL, but I was too lazy to implement that. Anyway, the “max-batch” argument specifies how many photos Automatr is allowed to add to that group in one batch. In this case it’s one, meaning that even if I had a hundred photos eligible for entry, Automatr would post only one, determined at random. Here’s the rule for posting photos to top-f:

(add-action ‘top-f
‘(add-to-group top-f)
‘(>= (count faves) 25))

Pretty straightforward. Here’s a more complicated group declaration:

(defgroup ‘top-v
“56022122@N00″
:max-batch 1
:max-posted 11)

The “max-posted” argument tells Automatr that at any point in time there can be at most 11 photos posted to that group (by the user in question). If Automatr wants to post an additional photo to the group, it has to delete one of the 11 first. The photo to be deleted is, again, chosen at random.

That’s basically it. If you want to play around with Clickr and Automatr yourself, just download it and follow the README file in the package. If you do something with it, I’d love to hear from you!

About these ads

118 thoughts on “Lisping Flickr

  1. Cool! I’ve been fiddling with an interface to Flickr in Emacs Lisp myself, and I will probably publish that up on EmacsWiki Any Time Soon (TR).

  2. Great! This is one of the most interesting tools for Flickr, and it is done in Lisp, my one and only language! Let me know if you have updates…

  3. Cool. I’m a graphic designer and just had a client contact me about flickr. I had never heard of it. Now, I’m quicly playing catch up on this great image tool.

    I cant’ wait to see how it works or how I can incorporate the website graphics I create or even my photography with it. I’m currently looking for tutorials similar to the video photoshop tutorials on the flickr. Thank you for the information.

  4. Pingback: One Tools ~
  5. Pingback: My Website ~
  6. Pingback: google ~
  7. Pingback: ebay ~
  8. Pingback: yahoo ~
  9. Pingback: youtube ~
  10. Pingback: msn ~
  11. Pingback: tea ~
  12. Pingback: Learn Spanish Online ~
  13. Pingback: Autism Information ~
  14. Pingback: Hearing Aids Help ~
  15. Pingback: Travel ~
  16. Pingback: Loan Guarantees ~
  17. Pingback: PC Upgrade Site ~
  18. Pingback: Technology ~
  19. Pingback: Precious Metals Info ~
  20. Pingback: Laptop Help Desk ~
  21. Pingback: laptopunlimited.info ~
  22. Pingback: pgmortgage.info ~
  23. Pingback: mortgageb.info ~
  24. Pingback: Adoption Help ~
  25. Pingback: Bankruptcy Help ~
  26. Pingback: Dating Help ~
  27. Pingback: Spyware Help ~
  28. Pingback: Teeth Whitening Help ~
  29. Pingback: Airfare Help ~
  30. Pingback: Architect Help ~
  31. Pingback: Wedding Help ~
  32. Pingback: Credit ~
  33. Pingback: Computers ~
  34. Pingback: My Wedding Store ~
  35. Pingback: I The Wed ~
  36. Pingback: Fast Automotive Info ~
  37. Pingback: Fast Carnival Info ~
  38. Pingback: FootStool ~
  39. Pingback: Top-CreditCard ~
  40. Pingback: Fast New-York Info ~
  41. Pingback: All Games Home ~
  42. Pingback: Gaming Site ~
  43. Pingback: Auto Resources ~
  44. Pingback: Car News ~
  45. Pingback: Jewelry ~
  46. Pingback: Financial Resources ~
  47. Pingback: Kayaking Resource ~
  48. Pingback: Wedding ~
  49. Pingback: Computer Info Web ~
  50. My main concern is that you can’t guarantee every page of your website will be included in the SERPs. Considering I’m constantly adding new products to my company’s website, I need to be sure that customers can find them as soon as possible.http://www.seoptimizerz.com

  51. Pingback: Car Lovers Info ~
  52. Pingback: Mortgaged To The Hilt ~
  53. Pingback: Find My Mortgage ~
  54. Pingback: The Mortgage Game ~
  55. Pingback: Mastering Mortgages ~
  56. Pingback: Nationwide Mortgages ~
  57. Pingback: All About Diabetes ~
  58. Hey,

    You have some nice flickr skills up your sleeves.
    Thank you for sharing with us. Looking forward for
    more of your stuff.

    Later,
    Justin

  59. Hi schani..I realise this post is a year old but what it sounds like you’ve created is similar to what I wanted to do with my images. Not being a programmer, is there a “simpler” way to explain your Automatr? Sorry for the noob question.

    Cheers though for what you’ve done, I’ll keep messing around with it

  60. A browsable repository or just the source tree(s) would also be nice. You could read around without downloading the entire thing.

  61. Hello All,

    I was reading around some of the posts here and I found interesting things that you guys talk about, I just made a blog about quitting smoking resources and ideas that you might want to check out.
    If someone is interested in this topic just go to; http://endthehabitnow.blogspot.com and let me know what you think.
    Thanks in advance.

  62. Want to start your private office arms race right now?

    I just got my own USB rocket launcher :-) Awsome thing.

    Plug into your computer and you got a remote controlled office missile launcher with 360 degrees horizontal and 45 degree vertival rotation with a range of more than 6 meters – which gives you a coverage of 113 square meters round your workplace.
    You can get the gadget here: http://tinyurl.com/2qul3c

    Check out the video they have on the page.

    Cheers

    Marko Fando

  63. Nice site,
    Get a top Spyware software program clean your PC with confidence get back all the power and speed that your computer had in the first place. Don’t wait before it’s too late..

    spyware_expert

Comments are closed.