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.

Trying to convert the FML script to That High

Help for those learning Tcl or writing their own scripts.
Post Reply
n
notrox
Voice
Posts: 5
Joined: Mon May 28, 2007 10:33 pm

Trying to convert the FML script to That High

Post by notrox »

I have been trying to modify Trixar_za's FML Script to pull from http://www.thathigh.com The two sites are very similar in design.

Site source

Code: Select all

<div id="content">
    <!--<div id="top">
    </div>--> 

    <div id="lc">
        
        <div id="stories">
    <div id="s_123" class="story s">
        <div class="sc">
            <a class="storylink" href="/story/93818/">Thought lying was bad so I chewed up my friends fake id.. That high.</a>
        </div>
I am getting stuck at this part. The div's are slightly different from FML, I tried a few different ways and nothing.

Code: Select all

 if {[regexp -- {<div class="sc".+?><p>(.+?)</p>} $html - fmlq]} {
        set fmlq [string trim $fmlq]
( For testing purposes I kept the commands the same)

Code: Select all

# Fmylife.com Script by Trixar_za
# Based on the Twitter script by Warlord v1.0
# Type in partyline: ".chanset #channel +fml" to enable it.

# Sets the logo
set fml(logo) "\002\[FML\]:\002"

# Sets the user agent
set fml(agent) "Mozilla/4.75 (X11; U; Linux 2.2.17; i586; Nav)"

setudef flag fml

if {[catch {package require http 2.5} e] != 0} {
  set fml(noutf8) 1
  package require http
}

bind pub - !fml proc:fml
bind pub - .fml proc:fml

# wordwrap code by speechless
proc msg {type dest data} {
   set len [expr {500-[string len ":$::botname $type $dest :\r\n"]}]
   foreach line [wordwrap $data $len] {
      putserv "$type $dest :$line"
   }
}

proc wordwrap {data len} {
   set out {}
   foreach line [split [string trim $data] \n] {
      set curr {}
      set i 0
      foreach word [split [string trim $line]] {
         if {[incr i [string len $word]]>$len} {
            lappend out [join $curr]
            set curr [list $word]
            set i [string len $word]
         } {
            lappend curr $word
         }
         incr i
      }
      if {[llength $curr]} {
         lappend out [join $curr]
      }
   }
   set out
}

proc proc:fml {nick uhand handle chan input} {
  if {[channel get $chan fml]} {
     global fml

     if {[info exists fml(noutf8)]} {
        set http [::http::config -useragent $fml(agent)]
     } else {
        set http [::http::config -useragent $fml(agent) -urlencoding "utf-8"]
     }

     catch { set http [::http::geturl "http://www.thathigh.com/random/"]}error
 
     if {![string match -nocase "::http::*" $error]} {
        msg "PRIVMSG" $chan "$fml(logo) [string totitle [string map {"\n" " | "} $error]]"
        return 0
     }

     if {![string equal -nocase [::http::status $http] "ok"]} {
        msg "PRIVMSG" $chan "$fml(logo) [string totitle [::http::status $http]]"
        return 0
     }

     set html [::http::data $http]

     # Clean up :P
     regsub -all {\n} $html { } html
     regsub -all {\t} $html { } html
     regsub -all {<br/>} $html { } html
     regsub -all { } $html { } html
     regsub -all {    } $html { } html
     regsub -all {   } $html { } html
     regsub -all {  } $html { } html
     regsub -all {<a.+?>} $html {} html
     regsub -all {</a>} $html {} html
     regsub -all {<strong.+?>} $html {} html
     regsub -all {</strong>} $html {} html
     regsub -all {—} $html {-} html
     regsub -all {>} $html {>} html
     regsub -all {<} $html {<} html
     regsub -all {&} $html {\&} html
     regsub -all {×} $html {*} html
     regsub -all {(?:\x91|\x92|’|‘|')} $html {'} html
     regsub -all {(?:\x93|\x94|“|”|")} $html {"} html
     regsub -all {×} $html {x} html
     regsub -all {(?:<!\[CDATA\[)} $html {} html

     if {[regexp -- {<div class="sc".+?><p>(.+?)</p>} $html - fmlq]} {
        set fmlq [string trim $fmlq]
     }

     if {[info exists fmlq]} {
        msg "PRIVMSG" $chan "$fml(logo) $fmlq"
     } else {
        msg "PRIVMSG" $chan "$fml(logo) Error: Couldn't get a FML quote!"
     }
  }
}

putlog "Fmylife.com Script by Trixar_za Loaded"
Could someone please point me in the right direction.

Thanks
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Re: Trying to convert the FML script to That High

Post by speechles »

notrox wrote:I am getting stuck at this part. The div's are slightly different from FML, I tried a few different ways and nothing.

Code: Select all

 if {[regexp -- {<div class="sc".+?><p>(.+?)</p>} $html - fmlq]} {
        set fmlq [string trim $fmlq]
Try...

Code: Select all

 if {[regexp -- {<div class="sc">.*?<a class="storylink".*?>(.+?)</a>} $html - fmlq]} {
        set fmlq [string trim $fmlq]
n
notrox
Voice
Posts: 5
Joined: Mon May 28, 2007 10:33 pm

Re: Trying to convert the FML script to That High

Post by notrox »

speechles wrote: Try...

Code: Select all

 if {[regexp -- {<div class="sc">.*?<a class="storylink".*?>(.+?)</a>} $html - fmlq]} {
        set fmlq [string trim $fmlq]
Thanks but it was a no go.
i
iRoc

Re: Trying to convert the FML script to That High

Post by iRoc »

notrox wrote:
speechles wrote: Try...

Code: Select all

 if {[regexp -- {<div class="sc">.*?<a class="storylink".*?>(.+?)</a>} $html - fmlq]} {
        set fmlq [string trim $fmlq]
Thanks but it was a no go.

Code: Select all

 if {[regexp -- {<div class="sc">.*?<a class="storylink" href=".*?">(.*?)</a>.*?</div> $html - fmlq]} {
        set fmlq [string trim $fmlq]
User avatar
Trixar_za
Op
Posts: 143
Joined: Wed Nov 18, 2009 1:44 pm
Location: South Africa
Contact:

Post by Trixar_za »

Sorry for the late response, but I normally check out Script Support & Releases rather than here. It's normally simpler to send me a pm to get my attention, because I check my e-mail more than I do here.

Anyway, the problem with the regex is that it's trying to use <a></a> tags to match, while the clean up code ends up removing all of them:

Code: Select all

     regsub -all {<a.+?>} $html {} html
     regsub -all {</a>} $html {} html 
so you could probably try removing them to make the suggested regexes work.

But it would probably be better to preserve that code (for future fml like in-line ad links) and rather use a regex without relying on them:

Code: Select all

     if {[regexp -- {<div class="sc">(.+?)</div>} $html - fmlq]} {
        set fmlq [string trim $fmlq]
     } 
User avatar
spithash
Master
Posts: 249
Joined: Thu Jul 12, 2007 9:21 am
Location: Libera
Contact:

Post by spithash »

I'm so getting this script when you finish it hehehe :lol:
Libera ##rtlsdr & ##re - Nick: spithash
Click here for troll.tcl
n
notrox
Voice
Posts: 5
Joined: Mon May 28, 2007 10:33 pm

Post by notrox »

Thanks! That worked like a charm. I'm sorry for my late response, I wasn't notified of the replies.

Thanks again
Post Reply