mIRC Homepage
Posted By: The_Only $read from an url!? - 16/07/05 06:38 PM
Hi there... is it possible to read a line of a *.txt file from a remote location like an url for example. Or is there a way to read the whole txt file (again from an url) and place it into a dialog's "text" argument using did -a or somehow?

Thanks (again) :P
Posted By: Navid Re: $read from an url!? - 17/07/05 04:23 AM
I've been meaning to ask the same question here smile but since you have it I'll just wait for a reply in here smile
Posted By: DaveC Re: $read from an url!? - 17/07/05 06:25 AM
I assume this is no different than reading any other file from a website, then just reading down to the right line, or saving the whole file, and reading line X

Do a search of the forums for reading a webpage with sockets, would find you some code.
Posted By: ClickHeRe Re: $read from an url!? - 17/07/05 11:37 AM
You can using sockets to download the file and process it afterwards. Look around in scripting sites, there are plenty of examples of how this is done in snippets and addons.
Posted By: SladeKraven Re: $read from an url!? - 17/07/05 01:25 PM
Here's a quick attempt, I've just got in from a 12 hour shift at work and I am knackered...

Code:
dialog web2dlg {
  title "Web 2 Dialog"
  size -1 -1 153 98
  option dbu
  edit "", 1, 2 2 147 93, multi hsbar vsbar
}

alias web2dlg {
  if ($1) set %find $1
  if (!$dialog(web2dlg)) dialog -dm web2dlg web2dlg
  sockopen web2dlg www.some-site-here.com 80
}

on *:sockopen:web2dlg: { 
  sockwrite -n $sockname GET /somefile.txt HTTP/1.1 
  sockwrite -n $sockname Host: www.some-site-here.com $+ $crlf $+ $crlf
}

on *:sockread:web2dlg: {
  if ($sockerr) {
    halt
  }
  else {
    var %w2d
    sockread %w2d
    if (%find) {
      if (%find isin %w2d) {
        did -a web2dlg 1 $strip(%w2d) $crlf
      }
    }
    else {
      did -a web2dlg 1 $strip(%w2d) $crlf
    }  
  }
}
on 1:sockclose:web2dlg: {
  echo -a Connection to Web 2 Dialog closed.
  unset %find
}


Usage:
/w2d - Lists the entire file if no keyword was used.
/w2d <keyword> - Lists all lines in the dialog with that keyword.

You may change the website, and file to whatever and if you know how sockets work you may change that name too.

-Andy
Posted By: Navid Re: $read from an url!? - 17/07/05 10:03 PM
I tried that and I got this problem:
W2D Unknown command
Posted By: MikeChat Re: $read from an url!? - 18/07/05 12:04 AM
I think he was referencing this alias :
Code:
alias  [color:blue]web2dlg [/color] {
  if ($1) set %find $1
  if (!$dialog(web2dlg)) dialog -dm web2dlg web2dlg
  sockopen web2dlg www.some-site-here.com 80
}

so either rename the alias to w2d or use /web2dlg
Posted By: SladeKraven Re: $read from an url!? - 18/07/05 12:05 AM
Yep, oops! Sorry about that, I was soooo tired. frown
Posted By: MikeChat Re: $read from an url!? - 18/07/05 12:08 AM
hows the new job going, they must be working ya hard frown
Posted By: SladeKraven Re: $read from an url!? - 18/07/05 12:11 AM
12 hours buddy, 6pm till 6am. It is hectic. The best part is using the golf carts and my radio (walkie talkie thingy...). smile

-Andy
© mIRC Discussion Forums