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.

regsub problems.

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

regsub problems.

Post by iamdeath »

Hi, I have tried to write a code which will fetch cricket scores from a webpage and will show it to any channel.

The weblink of Score:

Scores

The regsub I am using:

Code: Select all

    regsub -all "\n" $body "" body
    regsub -all -nocase {<br>} $body "<br>\n" body
    regsub -all {<b>} $body "\n\002" body
    regsub -all {</b>} $body "\002" body
    regsub -all {World Cup Warm-up Matches} $body "\00304,01World Cup Warm-up Matches\003" body
    regsub -line {<p class="blueBackHeading">} $body "\n\00304,01" body
    regsub -line {</p>} $body "\003\n" body
    regsub -all {<.+?>} $body "" body
    regsub -all { } $body "" body
    regsub -all {This page automatically refreshes every 60 seconds.} $body "" body
    regsub -all {Scorecard} $body "" body
    regsub -all {Desktop scorecard} $body "" body
    regsub -all {Bulletin} $body "" body
    regsub -all {|  |} $body "" body

    
The Reply I am getting:

Code: Select all

[06:33] <Cricket`->         
[06:33] <Cricket`-> Current time:01:33 GMT, Wed Mar 14, 2007
[06:33] <Cricket`-> 04,01One-Day Internationals
[06:34] <Cricket`-> 1st Match, Group D: West Indies v Pakistan at Kingston - Mar 13, 2007
[06:34] <Cricket`-> West Indies won by 54 runs
[06:34] <Cricket`-> West Indies 241/9 (50 ov); Pakistan 187 (47.2 ov) |  |  |  | Standard Bank Pro20 Series
[06:34] <Cricket`-> Titans v Dolphins at Benoni - Mar 14, 2007
[06:34] <Cricket`-> Match scheduled to begin at 18:00 local time (16:00 GMT)
[06:34] <Cricket`-> Warriors v Lions at East London - Mar 14, 2007
[06:34] <Cricket`-> 


Need help:

1. I want to get rid of pipes " | "
2. You see that " Standard Bank Pro20 Series " is the heading it should come on a different line but it's not coming.
3. At the start and the end there is a blank space
4. The last line from the web the bot did'nt show.

Can you kindly help me out, I've tried to read regsub help alot but can't get outta it. Your help will be appreciated.

Thanks.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Why not use regexp to get the lines you DO want, instead of regsub'ing the junk you don't? Then you can put things into seperate vars, like for the titles and such. And then you can put your color codes into the var strings. You can use string trim to get rid of extra spaces..

Code: Select all

regexp {<span.*?>Current time:</span>.*<span.*?>(.*?)</span>.*?<p class.*?>One-Day Internationals</p><p.*?>(.*?)</p>.*?<p.*?>Standard Bank Pro20 Series</p><p.*?>(.*?)</p>} body match date odiscores sbp20scores
#antiwordwrap---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
That will put the relevant data into the vars called $date $odiscores and $sbp20scores. Then you can use regsub to get rid of \n, <b> and <br> (or use string map, either way you can put color codes in the strings if you want.)

The regexp hasn't been tested but should work. Read the regexp manpage, and notice the () parts are what are going to be put into the variable names. The var $match is the entire string.
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

Post by iamdeath »

Thanks, I'll use and let you know if I have any problems..
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

I just noticed I had 'body' instead of $body in that example, should be

regexp {expression} $body match etc etc etc
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

Post by iamdeath »

Thanks for your kind, actually I have;nt yet got it done.. but I wanted to ask you if I only want to get ride of "|" can i get rid of them through regsub or regexp?..

Thanks
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Yes, regsub would work, but it would have to be escaped, as

regsub -all {\|} $varname {} varname
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

Post by iamdeath »

Thanks alot :)

I am done with the pipes atleast :P
C
CuteBangla
Halfop
Posts: 58
Joined: Mon Feb 27, 2006 10:47 pm
Location: Dhaka, Bangladesh
Contact:

Post by CuteBangla »

iamdeath wrote:Thanks alot :)

I am done with the pipes atleast :P
will you share the working script with us plz
Post Reply