Commits

Anonymous committed 3f96464

code built.

Comments (0)

Files changed (2)

Empty file added.
   in
     pup (Xml.children node) 
 
+let save_img id url =
+  let rec save_binary file_descriptor start remain data = 
+    if remain > 0 then
+      let len = Unix.write file_descriptor data start remain in
+	save_binary file_descriptor (start+len) (remain-len) data
+  in
+  let fd =
+    Unix.mkdir id 644;
+    Unix.openfile (Printf.sprintf "data/%s/%s" id (Filename.basename url)) [Unix.O_WRONLY] 644 
+  in
+  let bin = http_get url in
+    save_binary fd 0 (String.length bin) bin;
+    Unix.close fd;;
+
 let get_imgurl list post = (* <post>...<post>.xml -> (id, url) *)
-  (Xml.attrib post "id", 
-   (get_tagged_and_attr_child post "photo-url" "max-width" "1280") )::list ;;
+  let id = Xml.attrib post "id" in
+  let url = get_tagged_and_attr_child post "photo-url" "max-width" "1280" in
+    save_img id url;
+    (id, url)::list ;;
 
 let query username offset = 
   let url_base = api_url_base username in