Web API to retrieve difficulty changes
http://blockexplorer.com/q/nethash/2016 provides the necessary information and shouldn't be too hard to parse. Every row corresponds to the first block at a given difficulty.