Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

42
LINES

< > TinyBrain | #1007145 - quickVisualize - actually returns the first Google hit now

JavaX fragment (include)

sS quickVisualize_progID = #1007145;

static BufferedImage quickVisualize_fromCache(S query) {
  File f = quickVisualize_imageFile(query);
  if (f.length() != 0) pcall { ret loadPNG(f); }
  null;
}

static S quickVisualize_preprocess(S query) {
  ret toUpper(trim(query));
}

static BufferedImage quickVisualize(S query) {
  query = quickVisualize_preprocess(query);
  if (empty(query)) null;
  BufferedImage img = quickVisualize_fromCache(query);
  if (img != null) ret img;
  File f = quickVisualize_imageFile(query);
  /*L<S> urls = googleImageSearch_multi(query);
  saveTextFile(quickVisualize_urlsFile(query), joinLines(urls));
  if (empty(urls)) null;
  img = loadBufferedImage(first(urls));*/
  img = googleImageSearchFirst(query);
  if (img == null) null;
  savePNG(f, img);
  ret img;
}

static S quickVisualize_imagePath(S query) {
  query = quickVisualize_preprocess(query);
  ret fsI(quickVisualize_progID) + "/" + urlencode(query) + ".png";
}

static File quickVisualize_imageFile(S query) {
  query = quickVisualize_preprocess(query);
  ret prepareProgramFile(quickVisualize_progID, urlencode(query) + ".png");
}

static File quickVisualize_urlsFile(S query) {
  query = quickVisualize_preprocess(query);
  ret prepareProgramFile(quickVisualize_progID, "urls-" + urlencode(query) + ".txt");
}

download  show line numbers  debug dex   

Travelled to 1 computer(s): tvejysmllsmz

No comments. add comment

Snippet ID: #1007145
Snippet name: quickVisualize - actually returns the first Google hit now
Eternal ID of this version: #1007145/11
Text MD5: f132ee3ba84c7952cf995c121fab2c5c
Author: stefan
Category: javax / imaging / networking
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-03-20 13:18:01
Source code size: 1347 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 35 / 3
Version history: 10 change(s)
Referenced in: [show]