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.

What Pulse script

Help for those learning Tcl or writing their own scripts.
Post Reply
]
]x[
Voice
Posts: 17
Joined: Mon Jan 09, 2006 7:23 pm

What Pulse script

Post by ]x[ »

Trying to get this old Whatpulse script working again with the new web API but i can't seem to be able to fix it. The problem is that the old API was a txt output and the new one is an XML. This is the site where it needs to get the data from :
http://whatpulse.org/api/user.php?UserID=223348

This is the original version of the script -> http://pastebin.com/f35b6b778
Then i fiddled a bit with info from this forum and tutorials. I got it to to read the xml file and output something. But i can't seem to refine the output.

Working script till now -> http://pastebin.com/m34521008
Which outputs this -> http://pastebin.com/m53c44d46
But i can't figure out how i can get the output ^^ in to a nice format so i can deliver it to IRC how i want.

And below here is my try in getting something but that only messed up me script and makes it output errors in DCC instead of some nice output..

Code: Select all

package require http
bind pub - !test pulse_get
proc pulse_get {n u h c t} {
  set x [::http::geturl http://whatpulse.org/api/user.php?UserID=223348] 
  	foreach line [split [::http::data $x] \n] {
    	
    regsub -line {<AccountName>} set $AccountName {} AccountName
    regsub -line {<Country>} set $Country {} Country
    regsub -line {<DateJoined>} set $DateJoined {} DateJoined
    regsub -line {<Homepage>} set $Homepage {} Homepage
    regsub -line {<LastPulse>} set $LastPulse {} LastPulse
    regsub -line {<Pulses>} set $Pulses {} Pulses
    regsub -line {<TotalKeyCount>} set $TotalKeyCount {} TotalKeyCount
    regsub -line {<TotalMouseClicks>} set $TotalMouseClicks {} TotalMouseClicks
    regsub -line {<AvKeysPerPulse>} set $AvKeysPerPulse {} AvKeysPerPulse
    regsub -line {<AvClicksPerPulse>} set $AvClicksPerPulse {} AvClicksPerPulse
    regsub -line {<AvKPS>} set $AvKPS {} AvKPS
    regsub -line {<AvCPS>} set $AvCPS {} AvCPS
    regsub -line {<Rank>} set $Rank {} Rank
    regsub -line {<TeamID>} set $TeamID {} TeamID
    regsub -line {<TeamName>} set $TeamName {} TeamName
    regsub -line {<TeamMembers>} set $TeamMembers {} TeamMembers
    regsub -line {<TeamKeys>} set $TeamKeys {} TeamKeys
    regsub -line {<TeamClicks>} set $TeamClicks {} TeamClicks
    regsub -line {<TeamDescription>} set $TeamDescription {} TeamDescription
    regsub -line {<TeamDateFormed>} set $TeamDateFormed {} TeamDateFormed

    	puthelp "privmsg $c :AccountName"   
    	puthelp "privmsg $c :Country"
    	puthelp "privmsg $c :DateJoined"
    	puthelp "privmsg $c :Homepage"
    	puthelp "privmsg $c :LastPulse"
    	puthelp "privmsg $c :Pulses"
    	puthelp "privmsg $c :TotalKeyCount"
    	puthelp "privmsg $c :TotalMouseClicks"
    	puthelp "privmsg $c :AvKeysPerPulse"
    	puthelp "privmsg $c :AvClicksPerPulse"
    	puthelp "privmsg $c :AvKPS"
    	puthelp "privmsg $c :AvCPS"
    	puthelp "privmsg $c :Rank"
    	puthelp "privmsg $c :TeamID"
    	puthelp "privmsg $c :TeamName"
    	puthelp "privmsg $c :TeamMembers"
    	puthelp "privmsg $c :TeamKeys"
    	puthelp "privmsg $c :TeamClicks"
    	puthelp "privmsg $c :TeamDescription"
    	puthelp "privmsg $c :TeamDateFormed"
  }
}
I'm a total noob and i tried to read on about regsub an regexp the entire day but i still don't get any result so if anyone is able to help me, it would be greatly appreciated. Or gives me a few pointers in the right direction with how to separate each data field into its own variable.

Greetz ]x[
t
tsukeh
Voice
Posts: 31
Joined: Thu Jan 20, 2005 6:22 am

Post by tsukeh »

Code: Select all

package require http
bind pub - !test pulse_get
proc pulse_get {n u h c t} {
  set x [::http::geturl http://whatpulse.org/api/user.php?UserID=223348]
  set data [::http::data $x]

  regexp -- {<AccountName>([^<]+)} $data {} AccountName
  regexp -- {<Country>([^<]+)} $data {} Country
  regexp -- {<DateJoined>([^<]+)} $data {} DateJoined

  puthelp "privmsg $c :AccountName: $AccountName"   
  puthelp "privmsg $c :Country: $Country"
  puthelp "privmsg $c :DateJoined: $DateJoined"
}
]
]x[
Voice
Posts: 17
Joined: Mon Jan 09, 2006 7:23 pm

Post by ]x[ »

OMG its working, thank you really much man. Now i can continue to fiddle and hopefully finish this script :) a bit more.

Thanks again and i really appreciate this.
Post Reply