posts tagged with the keyword ‘xml’


Foursquare I had this idea for Foursquare… I thought it might be cool for a venue to have a screen showing who recently checked in. So I dug into the API a bit to see if that could be done. Here’s what I got.

I fired up FoursquareX and saw that old pal tapps was at MOCT, which happens to be a bar/nightclub. (I know this because I’ve been there once… though it was a paid gig and I was operating a camera.) Anyway… I needed the venue ID (vid) for MOCT, which you can get from the URL: Once I had that, I did this:

curl -u [USERNAME]:[PASSWORD]-o moct.xml ''

(You’ll need to substitute your own Foursquare username for [USERNAME] and your Foursquare password for [PASSWORD]. Also, your username is your email address, not what displays as your name on Foursquare. )

This gave me a file called ‘moct.xml’ containing the data I needed. (Note that this API call requires authentication… without it you’ll get venue info, but not the list of people checked in.)

I won’t show you the entire file, but here’s the first part to look at, the stats:

        <homecity>Milwaukee, WI</homecity>

You can see the important bits are: checkins, herenow, and mayor. The herenow tells you how many people are there right now. (I believe “right now” means, they have checked in within the last 3 hours.)

So here’s the info for tapps:

      <created>Wed, 20 Oct 10 23:17:23 +0000</created>
        <homecity>Milwaukee, WI</homecity>

And here’s a user named “Ty S.” who I do not know…

      <created>Thu, 21 Oct 10 00:20:45 +0000</created>
        <homecity>Milwaukee, WI</homecity>

We can construct the URL to his Foursquare page using the id:, and if the user has a username set, it will redirect to custom URL. (At least, it will if you are logged in with your browser.) We can also see their photo, so you could do something interesting with that as well. (There are no access controls on the images, you should be able to see any of those.) You can also see their homecity and their gender. I’m sure you can come up with an interesting Boys vs. Girls display using that data… And for a nightclub, well, it just seems fitting.

OK, well that’s all the time we have for now, keep on hacking… and if you build anything interesting with this info, please let me know.

Update: I probably should have linked to the API docs as well:


Let’s say you’ve got a file named “file.xml” and want it pretty printed, all indented nice and everything…

For just such an occasion I have a Perl script named “” and I just run my XML file through it like so: cat file.xml | perl

Here’s the code I use:


use XML::Twig;
use XML::Parser;

my $xml = XML::Twig->new(pretty_print => 'indented');



You can even pass it through right as it comes in over the wire: curl | perl

Here’s an example of data from Foursquare without pretty printing. (I used curl to grab the data. Also, I added in some line breaks, just to make it a little more readable.):

<?xml version="1.0" encoding="UTF-8"?>
<created>Mon, 09 Aug 10 00:50:33 +0000</created>
<name>The Kiltie</name><primarycategory><id>79067</id>
<fullpathname>Food:Ice Cream</fullpathname><nodename>Ice Cream</nodename>
<display>Pete P. @ The Kiltie</display></checkin></checkins>

And here’s the same data, again using curl to grab it, and then passing it through the script:

<?xml version="1.0" encoding="UTF-8"?>
    <created>Mon, 09 Aug 10 00:50:33 +0000</created>
      <name>The Kiltie</name>
        <fullpathname>Food:Ice Cream</fullpathname>
        <nodename>Ice Cream</nodename>
    <display>Pete P. @ The Kiltie</display>

I still find Perl extremely useful for this sort of task… I’m sure there are other command line ways to do this, but this one works for me.

(Hat tip to A Curious Programmer where I picked up this Perl code from…)


buy the button:

Buy The Button