|
Joined: Oct 2005
Posts: 8
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Oct 2005
Posts: 8 |
Is it possible to do $read or $readini an the file is on a website? [I only tried with a .php file.. if that's a problem]
Doing $read(http://sitehere.com/file.php,1) said: /say not enough parameters
Same with using $readini [I made it into ini format..]
|
|
|
|
Joined: Oct 2004
Posts: 31
Ameglian cow
|
Ameglian cow
Joined: Oct 2004
Posts: 31 |
You need to use sockets You can use /help or search the forums for sample socket scripts, I dont have any on me
Bear
|
|
|
|
Joined: Oct 2005
Posts: 8
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Oct 2005
Posts: 8 |
I looked at the help on sockets.. I don't get it. :[
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
do a search on this msg board (see the bottom of the screen when you are looking at the list of topics) for sockets there are a LOT of examples for this topic from very basic to some fairly advanced scripts.
|
|
|
|
Joined: Apr 2003
Posts: 701
Hoopy frood
|
Hoopy frood
Joined: Apr 2003
Posts: 701 |
$read works only on local files, there's no builtin command that lets you read stuff from web pages. Using sockets is possible, but requires a near perfect understanding of sockets, the http protocol, connections, TCP/IP and a decent knowledge and experience in mIRC scripting and it's limitations. Oh, and lots of time too. All needed documentation can be found on the web, but think about wether it's worth the effort.
Maybe it's simpler to just manually save the page to disk, or use wget in your script to download the page for you. Also remember that lines on webpages are NOT lines in the source html file. An entire web page can fit on one line, meaning that $read will fail with a 'line too long' error since mIRC can only handle a bit more that 900 characters without resorting to &binvars.
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Well, basic socketing isn't too difficult (reading a website that doesn't require cookies or login information). As mentioned, there are MANY examples in the forum. Just look for socket or sockread in the search (expand to 1 year or more). It may take a bit of effort to see how things work, but if you try, you'll probably figure it out. The more difficult parts come when trying to deal with cookies and logins and posting data and so on.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Apr 2003
Posts: 701
Hoopy frood
|
Hoopy frood
Joined: Apr 2003
Posts: 701 |
Well, adapting a basic file download script isn't that difficult no, the one below fits on 30 lines. But it doesn't handle frames, redirects, style sheets, images, cookies, error codes, logins, posting information, and probably much more. You don't need that? Note it doesn't handle anything else than the cnn homepage, no other sites, no other pages on the cnn site, just that one page. Ok, then let's look at useful stuff: usually people want to get the headlines or something from that site. Since even this cnn homepage contains lines way longer than 920 bytes, you can't just use %vars. Not that it would matter, there's no real guarantee the headline is on a single CRLF delimited line, HTML doesn't care about those linebreaks. So you have to hope the entire headline (or starting delimiter that uniquely identifies the headline you need) fits in about 500 bytes, then you can keep a 800 byte buffer and update it each tme by deleting the first 200 bytes and reading in the next 200 bytes and then checking again for the presence of that identifier, etc. It's possible yes, but it's more scripting. It hopefully also includes some regex, because else it's gonna be a long script with lotsa iswm or wildtok checks... Also, if the server doesn't want to give you plain text, but uses chunked-encoding, you've got more scripting to do, the kind that isn't fun. And we'll just skip gzip or deflate encoding... So, basically you needed to know about the HTTP protocol, how sockets work, how they work in mIRC (yes that's different), normal %vars and their limitations, &binvars because of those limitations, regex, basic HTML, file commands (/fwrite), custom windows, and some basic mIRC scripting too for reference... Try to use /fopen and /fwrite to write stuff to a file instead of a custom window and notice your browser will still need to get about everything from the site anyways alias cnn {
window @cnn | clear @cnn
sockopen cnn www.cnn.com 80
}
on *:SOCKOPEN:cnn: {
if ($sockerr) return
sockwrite -n $sockname GET / HTTP/1.0
sockwrite -n $sockname Host: www.cnn.com
sockwrite -n $sockname Connection: close
sockwrite $sockname $crlf
}
on *:SOCKREAD:cnn: {
if ($sock($sockname).mark) {
sockread 100 &data
while (($sockbr) && (!$sockerr)) {
echo @cnn $bvar(&data,1,101).text
sockread 100 &data
}
return
}
var %data
sockread %data
while (($sockbr) && (!$sockerr)) {
if (%data == $null) {
sockmark $sockname 1
return
}
sockread %data
}
}
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Lol... let the guy start small. Yes, you can go into the very complex quickly if you want to use various sites. However, you can usually manage to get information with little effort from a majority of sites. Examples: - Looking for dictionary definitions? dictionary.com uses large lines, so unless you know how to work with them, you don't want to deal with them. So, you choose another site that doesn't use long lines and still gives good definitions. I ended up choosing another site just because I really didn't feel like messing with dictionary.com and I ended up with much nicer results in the process.
- Trying to get weather? Many sites give long lines or require you to go through an intermediary page to access the final data. Some also have VERY large pages due to all the extra stuff that you don't care about. Yes, you can use the more advanced sockets concepts to handle this, but why bother? There are many other weather sites out there that can give just as nice of information without the effort.
Now, I agree that sometimes you do need to use a site that isn't nicely formatted. Sometimes there is no choice. So, you then have to use/learn the more advanced socketing techniques. My whole point before was that you CAN get by with very simple socketing in perhaps 90% of what you might want to use sockets for. Well... that percentage would vary considerably depending on the scripter... some need to use specific data from specific sites, or need to post data often, or use sites that require cookies often, or use sites that require logging in. But, I'd say that the majority of scripters can look around for "easy" sites that fit their needs and then can use a basic socket script similar to what you posted. I just want him to understand that you CAN learn the basics without too much difficulty. And, in many cases, that's all you need. Afterwards, he can advance in his knowledge. After reading your post, I have a feeling that anyone considering taking time to learn sockets may choose not to because your post makes it sound daunting, if not impossible.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Oct 2005
Posts: 8
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Oct 2005
Posts: 8 |
I am trying to get and display information from this page: http://tac0.be/now.phpThe only problem I am having is it says: HTTP/1.1 200 OK Date: Tue, 15 Nov 2005 14:33:45 GMT Server: X-Powered-By: PHP/4.4.0 Connection: close Transfer-Encoding: chunked Content-Type: text/html 10 ~No Stream ~ 0 when I display it using this: on *:text:!now:*: {
sockopen radio tac0.be 80
}
on *:sockopen:radio:{
sockwrite -n $sockname GET /now.php HTTP/1.1
sockwrite -n $sockname Host: tac0.be $+ $crlf $+ $crlf
}
on *:sockread:radio:{
if ($sockerr) {
echo -a Error.
halt
}
else {
var %text
sockread %text
say %text
}
} The last thing I tried to do is put ~'s before and after the text it displays so I can use $gettok() but that doesn't work..
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
One of the most useful things I've found for figuring out problems with sockets not working correctly is IEWatch (Firefox has something similar). It lets you see exactly what your browser is sending when viewing a page. Just turn it on and load the page. Then, set up your socket to match that. See if that helps you find your problem. If not, give a yell.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Apr 2003
Posts: 701
Hoopy frood
|
Hoopy frood
Joined: Apr 2003
Posts: 701 |
You said you could handle chunked transfer encoding by telling the server you accept HTTP/1.1 => you don't want that. You /say everything, which seems like a bad idea really. Better is to keep the channel/nick or the whole command in a global %var so you can change window after you issued the command and still have it show in the correct window. And ofcourse, why don't you strip off the headers? I even did that in my example script, just because any HTTP stream will have those headers. Basically everything is a header untill you reach a blank like (2 $crlf right after eachother) You don't need the ~ around your stuff if you only have a single line (a short one) on that text file. You can read the complete line in a %var and then use that for whatever you want it. If you want to generate a complete file list or playlist, you've got a lot more work to do, depending on how they're sent etc. ps: the server should really return Content-Type: text/plain since it's plain text, but most browsers won't care... alias cnn {
window @cnn | clear @cnn
sockopen cnn tac0.be 80
}
on *:SOCKOPEN:cnn: {
if ($sockerr > 0) { return }
sockwrite -n $sockname GET /now.php HTTP/1.0
sockwrite -n $sockname Host: tac0.be
sockwrite -n $sockname Connection: close
sockwrite $sockname $crlf
}
on *:SOCKREAD:cnn: {
var %data
if ($sock($sockname).mark) {
sockread %data
echo 4 @cnn %data
return
}
sockread %data
while (($sockbr) && (!$sockerr)) {
if (%data == $null) {
sockmark $sockname 1
echo @cnn blank line -> now actual content comes
return
}
echo @cnn SKIPPED HEADER: %data
sockread %data
}
}
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
Kelder is taking the time to try to explain to you the concept of sockets, providing a detailed explanation and code examples. There's no point to continue if you're not going to listen or read carefully what's been said. You don't seem to be doing this, because Kelder's code clearly got rid of the header part, whereas in your code it shows all the header information. The solution to your problem was already given, all you needed to do is _read_ it.
Gone.
|
|
|
|
|