2013-03-11
Converting a naïve Python datetime object from one timezone to another
Suppose you have a naïve datetime object (one without associated timezone information) that you know is in, say, Austin localtime, and you want the equivalent in another timezone, say, UTC.
print my_dt import pytz austin = pytz.timezone("America/Chicago") utc_dt = austin.localize(my_dt).astimezone(pytz.utc).replace(tzinfo=None) print utc_dt
localizeis important.my_dt.replace(tzinfo=austin)is not correct during summer time, for instance.
I can tell this is going to be one of those little bits of code I’ll need to refer to.
(Source: tominsam)
2012-12-10
post/37663261996
An image of Asteroids, showing the normally invisible vector lines that join lettering and the centres of the asteroids and spaceships themselves, taken from a 2008 c’t magazine programming contest to program a player for the game.
2012-10-15
2012-07-05
post/26581547183
Perhaps unsurprisingly, given their evidently shaky grasp of social media, the Shard’s inauguration website turns out to have difficulty grasping the concept of timezones.
2012-01-10
post/15603992043
2010-12-24
Flickr API Corners: ID to URL
If you have the URL of a Flickr photo, and want the URL of the page containing that photo, here are two ways, one on the website, and one using the API.
(Why would you want to do this? Well, people seem to be good at breaking the terms of service and not linking back to Flickr with a photo. Perhaps it’s been through ffffound or tumblr, or it’s been used on a blog. If that happens, but you want to find out who posted it, carry on.)
Firstly, using the website. Say your URL is http://farm5.static.flickr.com/4031/4497550401_11d8d708a7_z.jpg. Select up to the number behind the final slash and replace the text with http://flickr.com/photo.gne?id=. You’ll be redirected to a page containing the photo. (It’s possible that the photo will be private, but you’ll still be told who the uploader was.) Note you don’t need to trim things from the end of the URL; Flickr’s smart enough to do that for you.
Secondly, through the API. Open up the API explorer and look at flickr.photos.getInfo. Again, look after the last slash, and copy the number there (in this case, 4497550401) into the “ID” field. Once you call the method, you’ll see a variety of information about the photo, including (at the bottom of the XML) a URL.
It’s possible, if you don’t sign the call, or if the photo’s private, that you’ll need the second (hex) string, in this case 11d8d708a7, in the “secret” field. Providing this grants a little more access to a photo than the ID alone, but you may still find that the photo is private.
There you have it: two ways to get from a Flickr photo ID to the URL of the page containing it.
2010-10-21
post/1368408469
2009-12-31
Crowdsourcing for the Conservatives
The Wisdom of Cameron: Crowdsourcing for the Conservatives
The Conservative Party offered to pay £1m to produce something that can “harness the wisdom” of voters. 6 hours later Tom Scott launches one. He’s rather fast.
I suspect the Tories were hoping for a bit more than a yes or no voting app. Still, I applaud Tom Scott’s work: either it’ll win the money, in which case the prize has been proven to be a bit of a joke, or it won’t, and it’ll force the party to explain a bit more carefully exactly what it is that they do want. After all, a £1m project usually has a better scope document than a BBC News page.

