Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
34 lines (21 sloc) 1.03 KB
var url = [NSURL URLWithString:"http://api.flickr.com/services/feeds/photos_public.gne?id=87865690@N00&lang=en-us&format=rss_200"];
var xmlDoc = [[[NSXMLDocument alloc] initWithContentsOfURL:url options:null error:null] autorelease];
var root = [xmlDoc rootElement];
var tmpDir = NSTemporaryDirectory() + "ccgus/";
[[NSFileManager defaultManager] createDirectoryAtPath:tmpDir attributes:nil];
var ar = [root nodesForXPath:"channel/item/description/." error:null];
for (i=0; i < [ar count]; i++) {
var s = ar[i] + ""; // coerce this into a js string
urlstart = s.search('src="http') + 5;
s = s.substr(urlstart);
urlend = s.search('"');
s = s.substr(0, urlend);
var imgURL = [NSURL URLWithString:s];
var fileName = [[imgURL path] lastPathComponent];
var imageData = [NSData dataWithContentsOfURL: imgURL];
if (imageData) {
// writeToFile is defined in JSTExtras
[imageData writeToFile: tmpDir + fileName];
}
}
[[NSWorkspace sharedWorkspace] openFile: tmpDir];
Something went wrong with that request. Please try again.