I need a script that will download an XML file from a specific URL, compare some of the elements to elements in another (local) XML file, and then move elements from one file over to another.
Both files are KML files that include a list of Placemarks. The first file is a KML history of Foursquare checkins. The second (local) file is a KML file generated by Google Earth, which also includes a LineString placemark that connects all the other Placemarks.
I want to run this script periodically via a Cron to move over the latest Foursquare checkins to the locally-hosted Google Earth KML file and then append the coordinates from each checkin to an existing LineString in the Google Earth KML file, thereby connecting each checkin with the previous.
This script would need to check the published date on the previously inserted Placemarks of the local file to ensure that duplicate placemarks/coordinates are not inserted.
The script also needs to insert all new placemarks after the LineString Placemark called "Path" (i.e., the Path placemark should always be at the top), with the remaining placemarks ordered in reverse chronological order (newest to oldest).
The script should also search for the string "Current Location" in all Placemark descriptions of the local file, remove that string from the description (leaving the remainder of the description intact), and then insert that string into the beginning of the newest Placemark (i.e., the one that comes right after the "Path" placemark).
Finally, since the Foursquare KML doesn't properly encapsulate the content of the Description element in "<![CDATA[ ]]", so this script should also make sure that the Description content always starts with "<![CDATA[" and ends with "]]".
I have attached an example Foursquare KML and Google Earth KML (which includes the "Path" LineString). I'm looking for the script to be written in either PHP <= v5.3 or Python <= v2.4.