/
FlickrImages.jstalk
33 lines (21 loc) · 1.03 KB
/
FlickrImages.jstalk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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];