AmokHuginnsson / huginn

Programming language with no quirks, so simple every child can master it.
https://huginn.org/
Other
42 stars 2 forks source link

Network print the .get(``url``) #3

Closed noxomix closed 3 years ago

noxomix commented 3 years ago

How can I print a recource wich I get? So I want to print the HTML of a Page wich Ive get("https://url.end"), but what does .get() returns? It is not a string, because I cant print it.

HM

AmokHuginnsson commented 3 years ago

It returns HTTPResponse object. You can test a lot of things with Huginns interactive mode, like so:

[amok@ubiquitous](2/0)~/(work)$ huginn -q
huginn[0]> r = net.get( "https://codestation.org/" )
Class `HTTPResponse` does not have `code` method.
huginn[1]> type( r )
net.HTTPResponse
huginn[2]> //doc Network.HTTPResponse
Network.HTTPResponse - The HTTPResponse class is representing a response to Network.get(...) request
Class Network.HTTPResponse has following members:https://huginn.org/?h-action=bar-hgnref&hgnref=hgnref-network&huginn=huginn-reference&menu=submenu-project&page=projects&project=huginn&z=#sample&
+ filename
+ lastModified
+ mimeType
+ stream
huginn[3]> algo.materialize( r.stream, os.stdout() )
...

Network.HTTPResponse is also described here: https://huginn.org/?h-action=bar-hgnref&hgnref=hgnref-network&huginn=huginn-reference&menu=submenu-project&page=projects&project=huginn&z=#sample&

noxomix commented 3 years ago

Ah yes logic ^^

grafik because this returns grafik

AmokHuginnsson commented 3 years ago

Yes. Interactive mode automatically performs conversion to code() form results of an expression. To do the same inside the script you need this (canonical form) code:

print( "{}\n".format( val ) );

Still, not all Huginn classes have proper interface implemented, so for Network.HTTPResponse it will not work too.

noxomix commented 3 years ago

grafik It works::

grafik

Thank you very much.

noxomix commented 3 years ago

grafik

One other thing: in your documentration the "use" link redirects to "observe" -- so how can I "use" / include other files ?? ^^

noxomix commented 3 years ago

oh, I see my mistake

noxomix commented 3 years ago

Isset normal that after os.exec() my code execution stops? exits?

because I wont to create a sleep() function, that I can create a While-loop wich runs every second 1-times hm...

ahh found it in datetime.sleep .. hard to find ^^

AmokHuginnsson commented 3 years ago

os.exec() has the same semantics as exec() in other programming languages, it replaces process image with executed program. os.spawn() allows running programs concurrently with Huginn script. Yes, DateTime might not be the best place for sleep() function ;)

noxomix commented 3 years ago

Also can I configure in Network.get() a specific Port ?? my webapp is listening on port 3000 for example.

Okay Edit: I don't know why, but the .get() method doesn't accept NodeJS applications (on port 80/443/8080/3000 tested) I don't know why but only apache / nginx sites where displayed.

AmokHuginnsson commented 3 years ago

net.get("https://app.host.net:3000/")

noxomix commented 3 years ago

yes thats doesnt work for me. I dont know why but he's Timing out, (in the last hour Ive create 2 NodeJS servers on different VPS servers :D

AmokHuginnsson commented 3 years ago

If you give me the link I will debug it on Monday. Understanding privacy concerns you can PM at https://gitter.im/codestation_org/huginn

noxomix commented 3 years ago

I'll send you the Link tomorrow thx

noxomix commented 3 years ago

http://109.230.235.150:3000/

AmokHuginnsson commented 3 years ago

Works for me, but I have fixed two bugs (one could be probably related to your issue) yesterday, so you can try apt-get update && apt-get dist-upgrade.

noxomix commented 3 years ago

Nice :)

And one other Question: There isn't a way to create a "POST" to RestAPI/httpRecource right??

AmokHuginnsson commented 3 years ago

You could do it manually with c = net.connect(...); c.write..., but proper solution would be to implement missing functionality in underlying library. I could look into it.

AmokHuginnsson commented 3 years ago

There is a new Huginn function: Network.post(), used like so:

respRaw = net.post("http://httpbin.org/post", {"elems":[1,2,3]});
resp = json.load(respRaw.stream);
noxomix commented 3 years ago

Nice Thank you =)