This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

how to parse text from ::HTTP::data

Old posts that have not been replied to for several years.
Locked
T
Taiyaki
Voice
Posts: 15
Joined: Mon Nov 18, 2002 4:39 am

how to parse text from ::HTTP::data

Post by Taiyaki »

ok, i'm using this code to grab text from a remote text file

Code: Select all

package require http 

set cmd "!updates" 
bind pub -|- $cmd test 

proc test {nick uhost hand chan text} {
 
  putquick "NOTICE $nick :let's hope this is faster"

  set tok [::http::geturl "http://www3.telus.net/dekan/newrlsd.txt"]
  set data [::http::data $tok]
  foreach z [split $data \n] {
    putquick "NOTICE $nick :$z"
  }

  ::http::cleanup $tok 
} 
and the text file contains

Code: Select all

11/11/02|Knights of Ramune (DVD)|01|Perfect-Anime|
11/12/02|Asagiri no Miko|07-08|Elite-Fansubs|
11/13/02|Southern Cross (DVD)|13-15|ILA|
11/18/02|Urusei Yatsura (DVD)|1-4|ILA|
i want the bot to parse this output to only display the line if it matches a certain date. like today is 11/18/02, how do i make the bot display only the 11/18/02 line?
T
Taiyaki
Voice
Posts: 15
Joined: Mon Nov 18, 2002 4:39 am

Post by Taiyaki »

ok, never mind, that, lol. i've gotten that solved.

but now i'm at another question:

i have an output of this

Code: Select all

11/18/02|Cooking Master Boy|17|Anime-Keep|
and after i do [split $list |]

i get this

Code: Select all

11/18/02 {Cooking Master Boy} 17 Anime-Keep {}
how do i make it display just 11/18/02 Cooking Master Boy 17 Anime-Keep?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

split is a list command. It operated on strings, and converts them into lists. These brackets are used to designate the begining and end of a item within a list.

As you have done, you have split the string, using |.

You can then use the "join" command to convert from a list, into a string. Again, you need to specify a charater, you use as a joining character. If you where to use a |, it would return your original list (to show how it works). You can use " " (including quotes) to join it with a space.

Notice the {} at the end of the list. This is because you have a | at the end of the string. To get around this, you can use "string trim" to remove the end white space that "join" will generate.
T
Taiyaki
Voice
Posts: 15
Joined: Mon Nov 18, 2002 4:39 am

Post by Taiyaki »

ah, i got it to work! thanks :D
Locked