Sg2.9
Get some data from URL
Recent RSS
Get some data from URL
From:  peko
Date:  28. April 2011, 19:26

I want to get some data from an URL.
There is the way to do this?

I want to request an site for images witch contain certain color.
And then replace some items with requested images.

Thank you!

UPD:
I found an example of it:
http://scriptographer.org/forum/help/placing-images-from-url/
But it is not clear for me, I need to use pure java for such stufs?

Re: Get some data from URL
From:  peko
Date:  28. April 2011, 20:42

This way fork for me:

importPackage(java.net); 
importPackage(java.io); 

var u = new URL('http://labs.ideeinc.com/coloursearch/services/rest/?method=color.search&quantity=50&page=0&colors=3626af&imageset=flickr');
var s = new DataInputStream(u.openStream());
var line;
while ((line = s.readLine()) != null) {
    print(line);
};

Another question, there is an simple way to parse JSON?

Re: Get some data from URL
From:  peko
Date:  28. April 2011, 21:04

Get it!
Version with JSON parsing:

importPackage(java.net); 
importPackage(java.io); 

var u = new URL('http://labs.ideeinc.com/coloursearch/services/rest/?method=color.search&quantity=50&page=0&colors=3626af&imageset=flickr');
var s = new DataInputStream(u.openStream());
var json = '';
var line;
while ((line = s.readLine()) != null) {
    json += line;
};
var d = Json.decode(json);
for (n in d) print(n+": "+d[n]+"n");

It was simple...

Thanks to everyone, problem sovled!

Re: Get some data from URL
From:  peko
Date:  29. April 2011, 16:27

Final results:
http://youtu.be/UfwjYaZYZbw

Scripts can be downloaded here

Re: Get some data from URL
From:  Jordi
Date:  29. April 2011, 19:46

Great job peko
Is possible one implementation for this script with tag research for pictures?

Re: Get some data from URL
From:  Jürg Lehni
Date:  3. May 2011, 12:28

Hi Peko,

That's a great script! Very well executed. Apologies for the silence here, but good to see you already figured it all out.

We have a JS Request object for web requests but it's currently undocumented. We will add documentation about it soon. Internally it also uses the Java stuff.

Would you mind also uploading it to the scripts page on Scriptographer? And maybe we could put it into the Gallery as well?

Re: Get some data from URL
From:  peko
Date:  2. July 2011, 18:26

Oh, it seems I forget switch on "notify", or just missed an email. Sorry.
I revised script, and made some fixes after ideé has changes of its API.
I put new version of script here.

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Sudoku Generator + Solver 03.01.13