egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Trying to convert the FML script to That High

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
notrox
Voice


Joined: 28 May 2007
Posts: 5

PostPosted: Sun Nov 07, 2010 1:58 pm    Post subject: Trying to convert the FML script to That High Reply with quote

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


( For testing purposes I kept the commands the same)

Code:
# 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 {&nbsp;} $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 {&gt;} $html {>} html
     regsub -all {&lt;} $html {<} html
     regsub -all {&amp;} $html {\&} html
     regsub -all {&times;} $html {*} html
     regsub -all {(?:\x91|\x92|||')} $html {'} html
     regsub -all {(?:\x93|\x94|||&quot;)} $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
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Nov 07, 2010 2:16 pm    Post subject: Re: Trying to convert the FML script to That High Reply with quote

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


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

_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
notrox
Voice


Joined: 28 May 2007
Posts: 5

PostPosted: Sun Nov 07, 2010 2:33 pm    Post subject: Re: Trying to convert the FML script to That High Reply with quote

speechles wrote:

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


Thanks but it was a no go.
Back to top
View user's profile Send private message
iRoc
Guest





PostPosted: Mon Nov 08, 2010 5:21 pm    Post subject: Re: Trying to convert the FML script to That High Reply with quote

notrox wrote:
speechles wrote:

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


Thanks but it was a no go.


Code:

 if {[regexp -- {<div class="sc">.*?<a class="storylink" href=".*?">(.*?)</a>.*?</div> $html - fmlq]} {
        set fmlq [string trim $fmlq]
Back to top
Trixar_za
Op


Joined: 18 Nov 2009
Posts: 143
Location: South Africa

PostPosted: Fri Nov 19, 2010 11:32 pm    Post subject: Reply with quote

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:
     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:
     if {[regexp -- {<div class="sc">(.+?)</div>} $html - fmlq]} {
        set fmlq [string trim $fmlq]
     }

_________________
http://www.trixarian.net/Projects
Back to top
View user's profile Send private message Visit poster's website
spithash
Master


Joined: 12 Jul 2007
Posts: 245
Location: DALnet, EFnet & Freenode

PostPosted: Sat Nov 20, 2010 9:51 am    Post subject: Reply with quote

I'm so getting this script when you finish it hehehe Laughing
_________________
DALnet #CodeMasters - EFnet #eggtcl Nick: spithash
Click here for troll.tcl
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
notrox
Voice


Joined: 28 May 2007
Posts: 5

PostPosted: Fri Nov 26, 2010 8:38 pm    Post subject: Reply with quote

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

Thanks again
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber