Thursday Quote: Kenneth Reitz
“The API is all that matters. Everything else is secondary.”
– Kenneth Reitz
Python for Humans
“The API is all that matters. Everything else is secondary.”
– Kenneth Reitz
Python for Humans
I started trying to lose weight a while back, since we both know I’m a bit heavy and sitting in front of a computer isn’t going to lose the weight for me.
Naturally, it’s important that I incorporate technology into my weight loss somehow, right? So I decided to give the Google Visualizations API a spin.
I worked up a quick data format and a method to pop the data out. Nothing fancy, just a fixed width flat file. This doesn’t deserve a database.
2010-06-30 235.4
2010-06-29 236.8
Easy to read, easy to edit, and easy to consume. Every morning I just hop on the server, add the day’s weight and log off.
Now I just needed to represent it. The API is very object oriented and easy to work with. I wish there was a less verbose way of presenting the data, but you can't have everything.
Actually, there may be a better way, I just didn't come across it while speed reading the docs.
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn( 'string', 'Date' );
data.addColumn( 'number', 'Weight' );
data.addRows( );
data.setValue(
,
0,
''
);
data.setValue(
,
1,
);
var chart_div = document.getElementById( 'chart_div' );
var chart = new google.visualization.LineChart( chart_div );
chart.draw(
data,
{
width: 800,
height: 600,
title: 'Weight Over Time'
}
);
}
And there you have it, fancy charting in no time.
See it in action at http://static.velvetcache.org/weight.php
Get the full source at http://gist.github.com/459148.
I’ve been messing with the Foursquare API and I was getting frustrated by it’s unreadable output. Too much XML, not enough whitespace!
[email protected]:~$ curl -l http://api.foursquare.com/v1/venues?geolat=41.243385\&geolong=-96.017697
170922 Peter Kiewit Institute 79037 College & Education:University University http://foursquare.com/img/categories/education/default.png 1110 South 67th Streetat Pacific St Omaha NE 68182 41.2436984 -96.0146702 0 4025543333 PKI 255 345883 Liv Lounge 79168 Nightlife:Lounge Lounge http://foursquare.com/img/categories/nightlife/lounge.png 2279 S 67th Stat Center St Omaha Nebraska 68106 41.2436984 -96.0146702 0 255 245578 Walmart 79221 Shops:Department Store Department Store http://foursquare.com/img/categories/shops/default.png 1606 S 72nd Stat Pine St Omaha NE 68124 41.2440158 -96.0241158 0 4023939560 541 254875 Aksarben Village 79196 Parks & Outdoors:Plaza / Square Plaza / Square http://foursquare.com/img/categories/parks_outdoors/default.png 6600 Shirley Stat Center St Omaha NE 68106 41.2414632 -96.0120519 0 518 170916 Scott Technology Center 79115 Home / Work / Other:Corporate / Office Corporate / Office http://foursquare.com/img/categories/building/default.png 6825 Pine StreetOmaha NE 68106 41.243385 -96.017697 0 4025026000 0 2468550 Juice Stop 79071 Food:Juice Bar Juice Bar http://foursquare.com/img/categories/food/default.png 2119 S 67th StShirley St Omaha NE 68106 41.2403021 -96.0146607 0 4029343870 427 199022 Scott Conference Center 96353 Home / Work / Other:Event Space Event Space http://foursquare.com/img/categories/building/default.png 6450 Pine StreetOmaha NE 41.244514 -96.013489 0 373 772128 Courtyard Aksarben VIllage 79273 Travel:Hotel Hotel http://foursquare.com/img/categories/travel/hotel.png 1625 S 67th Stat Pine St Omaha NE 68106 41.243304 -96.014349 0 4029514300 280 247344 Wohlner's Market 96359 Shops:Food & Drink:Gourmet Gourmet http://foursquare.com/img/categories/shops/default.png 2289 S 67th Stat Center St Omaha NE 68106 41.23806024488222 -96.0138988494873 0 4025516875 672 2564306 First Data 79115 Home / Work / Other:Corporate / Office Corporate / Office http://foursquare.com/img/categories/building/default.png 6855 Pacific StreetOmaha NE 68106 41.2487029 -96.0192553 0 606
[email protected]:~$
How can we rectify this situation? xmllint! This is part of libxml and should exist on most systems.
[email protected]:~$ curl -l http://api.foursquare.com/v1/venues?geolat=41.243385\&geolong=-96.017697 | xmllint --format -
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
101 5265 101 5265 0 0 13778 0 --:--:-- --:--:-- --:--:-- 29914
170922
Peter Kiewit Institute
79037
College & Education:University
University
http://foursquare.com/img/categories/education/default.png
1110 South 67th Street
at Pacific St
Omaha
NE
68182
41.2436984
-96.0146702
0
4025543333
PKI
255
... snip ...
2564306
First Data
79115
Home / Work / Other:Corporate / Office
Corporate / Office
http://foursquare.com/img/categories/building/default.png
6855 Pacific Street
Omaha
NE
68106
41.2487029
-96.0192553
0
606
[email protected]:~$
So there you go, a handy trick of the day for you.
In case you missed it the short form is:
curl -l [url] | xmllint --format -