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 

Updated horoscope pls
Goto page Previous  1, 2
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Dominatez
Voice


Joined: 14 Jan 2019
Posts: 27
Location: United Kingdom

PostPosted: Tue Jul 23, 2019 1:21 pm    Post subject: Reply with quote

Heartbroken,

Firstly. Thank you for fixing this and making it work, which is an amazing job.

Secondly, today it has started spewing this out.

Somethings wrong with <strong class="date">(.*?)</p>

Somethings wrong with <div class="ratings">(.+?)</div>

Somethings wrong with <h3>(.*?)</h3>.+?love\">(.*?)</p>.+?friend\">(.*?)</p>.+?career\">(.*?)</p>

Any ideas ?

This is the full script for the latest eggdrop.
Back to top
View user's profile Send private message
heartbroken
Halfop


Joined: 23 Jun 2011
Posts: 90
Location: somewhere out there

PostPosted: Wed Jul 24, 2019 9:09 am    Post subject: Reply with quote

Updated, Thank you!



This one for Tcl8.6:

Code:
# This script using some of Tcl8.6's commands,also needs Tcl-TLS for https links and tcllib for fixed outputs!
 package require http
 package require htmlparse
 package require tls 1.6.4
 package require textutil::split
 package present Tcl 8.6
 package require eggdrop 1.8

 # to activate on your #channel : .chanset #channel +Horoscope in PartyLine
 setudef flag Horoscope

 namespace eval Horoscope {
     # You can add multiple Horoscope commands with a space between.
    variable HoroCMD ".horo !horo !horoscope"
     
    # Would you like to use this script commands in your bot's pvt?
    # 1 yes , 0 no
    variable HoroEggPM 1
     
    # users able to make horo queries in seconds:times
    variable FludControl 10:3
     
    # eggdrop user flags : general flags|channel flags
    variable HoroCmdFlags -|-
   
    # How many chars would allow to print in a line
    variable HoroCharsInLineLen 312
     
    # daily horo query link
    variable DailyHoroURL {https://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-today.aspx}
     
    # rating stars regexp
    variable HoroStarsRE {star-ratings\">.+?</div>(.+?)</div>}
     
    # daily horoscope regexp
    variable HoroDailyRE {<p><strong>(.*?)</p>}
     
    # matches regexp
    variable HoroMatchesRE {<h3>(.*?)</h3>.+?love.+?>(.*?)</p>.+?friend.+?>(.*?)</p>.+?career.+?>(.*?)</p>}
     
    # for filled star highlight
    variable UnicodeBlackStar \u2605
     
    # for filled star outputs
    variable UnicodeWhiteStar \u2606
     
    # connection timeout time in seconds
    variable TimeOutHoro 12
     
    # ratings title:
    variable MoodRatings "\00314Today's Star Ratings - Your general mood\003"
    # end of settings
     
    foreach CmdSign [split $HoroCMD { }] {
       bind pub $HoroCmdFlags $CmdSign [namespace current]::HorosPubProcName
       if {$HoroEggPM >= 1 && [string length $HoroEggPM]} {
          bind msg $HoroCmdFlags $CmdSign [namespace current]::EggPvtHorosProcName
       }
    };
    putlog "[file tail [info script]] Loaded!"

    namespace path {::http:: ::htmlparse:: ::textutil::split::}
    register https 443 [list tls::socket -ssl2 0 -ssl3 0 -tls1 1]

    proc MainHoroProcName {nick uhost hand chan text} {
       variable FludControl ;
       set TargetHost [lindex [split $uhost @] 1]
       if {![info exists ::HoroFludVar($TargetHost)] && ![info exists ::HoroFludVar($nick)]} {
          array set ::HoroFludVar [list $nick [clock seconds] $TargetHost 0]
       } else {
          incr ::HoroFludVar($TargetHost)
       }
       if {([expr {[clock seconds] - $::HoroFludVar($nick)}] <= [lindex [split $FludControl :] 0]) && ($::HoroFludVar($TargetHost) >= [lindex [split $FludControl :] 1])} {
          putserv "NOTICE $nick :$nick You able to use $::lastbind command [lindex [split $FludControl :] 1] times in [lindex [split $FludControl :] 0] seconds!";
          return 0;
       }
       utimer [lindex [split $FludControl :] 0] [list unset -nocomplain ::HoroFludVar($TargetHost) ::HoroFludVar($nick)]
       set HoroRequest [lindex [split [stripcodes * [string tolower $text]]] 0]
       set ListOfHoros [dict create aries 1 taurus 2 gemini 3 cancer 4 leo 5 virgo 6 libra 7 scorpio 8 sagittarius 9 capricorn 10 aquarius 11 pisces 12]
       if {![llength $HoroRequest]} {
          putserv "NOTICE $nick :Usage: $::lastbind <Horoscope>";
          return 0
       } elseif {$HoroRequest ni [dict keys $ListOfHoros]} {
          putserv "NOTICE $nick :\"$HoroRequest\" is not valid!";
          return
       } else {
          set HoroWhatWeGot [::Horoscope::FetchDisHoros ${Horoscope::DailyHoroURL}?sign=[dict get $ListOfHoros $HoroRequest]]
          if {[regexp -- $Horoscope::HoroDailyRE $HoroWhatWeGot -> TodaysHoro]} {
             ::Horoscope::PrintHoro $chan [::Horoscope::HoroCleanUp $TodaysHoro]
          } else {
             putcmdlog "[file tail [info script]]: Somethings wrong with $Horoscope::HoroDailyRE";
          }
          if {[regexp -- $Horoscope::HoroStarsRE $HoroWhatWeGot -> HiLightStars]} {
             puthelp "PRIVMSG $chan :$Horoscope::MoodRatings : [::Horoscope::HoroCleanUp $HiLightStars]";
          } else {
             putcmdlog "[file tail [info script]]: Somethings wrong with $Horoscope::HoroStarsRE";
          }
          if {[regexp -- $Horoscope::HoroMatchesRE $HoroWhatWeGot -> Matches Love Friend Career]} {
             puthelp "PRIVMSG $chan :[::Horoscope::HoroCleanUp [set AllMatches "\00314$Matches\003: $Love - $Friend - $Career"]]";
          } else {
             putcmdlog "[file tail [info script]]: Somethings wrong with $Horoscope::HoroMatchesRE";
          }
       };
       return 0
    }

    proc HorosPubProcName {nick uhost hand chan arg} {
       if {![channel get $chan Horoscope]} { return 0 };
       ::Horoscope::MainHoroProcName $nick $uhost $hand $chan $arg
    }

    proc EggPvtHorosProcName {nick uhost hand chan arg} {
       ::Horoscope::MainHoroProcName $nick $uhost $hand $nick $arg
    }

    proc PrintHoro {HoroTarget HoroString} {
       lmap HoroLines [splitn $HoroString $Horoscope::HoroCharsInLineLen] { puthelp "PRIVMSG $HoroTarget :[::Horoscope::HoroCleanUp $HoroLines]" }
    }

    proc HoroCleanUp HoroHTMLs {
        regsub -all -- {<i class="icon-star-filled highlight"></i>} $HoroHTMLs \00307$Horoscope::UnicodeBlackStar\003 HoroHTMLs
        regsub -all -- {<i class="icon-star-filled"></i>} $HoroHTMLs \00314$Horoscope::UnicodeWhiteStar\003 HoroHTMLs
        #regsub -all -- {(:?<strong>|</strong>|<b>|</b>)} $HoroHTMLs \002 HoroHTMLs
        regsub -all -- {(:?<h4>|</h4>)} $HoroHTMLs \002 HoroHTMLs
        regsub -all -- {<p>([^\s]*)} $HoroHTMLs \00304\\0\003  HoroHTMLs
        regsub -all -- "<.+?>" $HoroHTMLs {} HoroHTMLs
        regsub -all -- {\s+} $HoroHTMLs " " HoroHTMLs
        return [string trim $HoroHTMLs]
     }

    proc FetchDisHoros Link4Horo {
       try {
          set TokenHoro [geturl $Link4Horo -timeout [expr {round(1000 * $Horoscope::TimeOutHoro)}]]
       } on error { HoroErrorMsg } {
          putcmdlog "[file tail [info script]]: [string map {\n " "} $HoroErrorMsg]"
       } finally {
          if {[status $TokenHoro] eq "ok" && [ncode $TokenHoro] == 200} {
             set TheHoroData [data $TokenHoro]
          } else {
             putcmdlog "[file tail [info script]]: [status $TokenHoro] , [code $TokenHoro]" }; cleanup $TokenHoro
          if {[info exists TheHoroData] && [string length $TheHoroData]} {
             return [mapEscapes $TheHoroData]
          } else {
             putcmdlog "[file tail [info script]]: Got no any data from: $Link4Horo"
          }
       }
    }
 }





And this also works with Tcl8.5:

Code:
 package require http
 package require htmlparse
 package require tls 1.6.4

 setudef flag Horoscope

 namespace eval Horoscope {

    variable HoroCMD ".horo !horo !horoscope"

    variable HoroEggPM 1

    variable FludControl 10:3

    variable HoroCmdFlags -|-

    variable HoroWordsInLineLen 36

    variable DailyHoroURL {https://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-today.aspx}

    variable HoroStarsRE {star-ratings\">.+?</div>(.+?)</div>}

    variable HoroDailyRE {<p><strong>(.*?)</p>}

    variable HoroMatchesRE {<h3>(.*?)</h3>.+?love.+?>(.*?)</p>.+?friend.+?>(.*?)</p>.+?career.+?>(.*?)</p>}

    variable UnicodeBlackStar \u2605

    variable UnicodeWhiteStar \u2606

    variable TimeOutHoro 12

    variable MoodRatings "\00314Today's Star Ratings - Your general mood\003"

    foreach CmdSign [split $HoroCMD { }] {
       bind pub $HoroCmdFlags $CmdSign [namespace current]::HorosPubProcName
       if {$HoroEggPM >= 1 && [string length $HoroEggPM]} {
          bind msg $HoroCmdFlags $CmdSign [namespace current]::EggPvtHorosProcName
       }
    };
    putlog "[file tail [info script]] Loaded!"

    namespace path {::http:: ::htmlparse::}
    register https 443 [list tls::socket -ssl2 0 -ssl3 0 -tls1 1]

    proc MainHoroProcName {nick uhost hand chan text} {
       variable FludControl
       set TargetHost [lindex [split $uhost @] 1]
       if {![info exists ::HoroFludVar($TargetHost)] && ![info exists ::HoroFludVar($nick)]} {
          array set ::HoroFludVar [list $nick [clock seconds] $TargetHost 1]
       } else {
          incr ::HoroFludVar($TargetHost)
       }
       if {([expr {[clock seconds] - $::HoroFludVar($nick)}] < [lindex [split $FludControl :] 0]) && ($::HoroFludVar($TargetHost) > [lindex [split $FludControl :] 1])} {
          putserv "NOTICE $nick :$nick You able to use $::lastbind command [lindex [split $FludControl :] 1] times in [lindex [split $FludControl :] 0] seconds!";
          return 0;
       }
       utimer [lindex [split $FludControl :] 0] [list unset -nocomplain ::HoroFludVar($TargetHost) ::HoroFludVar($nick)]
       set HoroRequest [lindex [split [stripcodes abcgru [string tolower $text]]] 0]
       array set ListOfHoros [list aries 1 taurus 2 gemini 3 cancer 4 leo 5 virgo 6 libra 7 scorpio 8 sagittarius 9 capricorn 10 aquarius 11 pisces 12]
       if {![llength $HoroRequest]} {
          putserv "NOTICE $nick :Usage: $::lastbind <Horoscope>";
          return 0
       } elseif {$HoroRequest ni [array names ListOfHoros]} {
          putserv "NOTICE $nick :\"$HoroRequest\" is not valid!";
          return
       } else {
          set HoroWhatWeGot [::Horoscope::FetchDisHoros ${Horoscope::DailyHoroURL}?sign=$ListOfHoros($HoroRequest)]
          if {[regexp -- $Horoscope::HoroDailyRE $HoroWhatWeGot -> TodaysHoro]} {
             ::Horoscope::PrintHoro $chan [::Horoscope::HoroCleanUp $TodaysHoro]
          } else {
             putcmdlog "[file tail [info script]]: Somethings wrong with $Horoscope::HoroDailyRE";
          }
          if {[regexp -- $Horoscope::HoroStarsRE $HoroWhatWeGot -> HiLightStars]} {
              puthelp "PRIVMSG $chan :$Horoscope::MoodRatings : [::Horoscope::HoroCleanUp $HiLightStars]";
          } else {
             putcmdlog "[file tail [info script]]: Somethings wrong with $Horoscope::HoroStarsRE";
          }
          if {[regexp -- $Horoscope::HoroMatchesRE $HoroWhatWeGot -> Matches Love Friend Career]} {
             puthelp "PRIVMSG $chan :[::Horoscope::HoroCleanUp [set AllMatches "\00314$Matches\003: $Love - $Friend - $Career"]]";
          } else {
             putcmdlog "[file tail [info script]]: Somethings wrong with $Horoscope::HoroMatchesRE";
          }
       };
       return 0
    }

    proc HorosPubProcName {nick uhost hand chan arg} {
       if {![channel get $chan Horoscope]} { return 0 };
       ::Horoscope::MainHoroProcName $nick $uhost $hand $chan $arg
    }

    proc EggPvtHorosProcName {nick uhost hand chan arg} {
       ::Horoscope::MainHoroProcName $nick $uhost $hand $nick $arg
    }

    proc PrintHoro {HoroTarget HoroString} {
       if {[set HoroLineLen [llength [set HoroLenght [split $HoroString]]]] > $Horoscope::HoroWordsInLineLen} {
          for { set i 0 } { $i < $HoroLineLen } { incr i $Horoscope::HoroWordsInLineLen } {
             if {$i == 0} {
                puthelp "PRIVMSG $HoroTarget :[join [lrange $HoroLenght $i [expr {$i + ($Horoscope::HoroWordsInLineLen - 1)}]]]"
             } {
                puthelp "PRIVMSG $HoroTarget :[join [lrange $HoroLenght $i [expr {$i + ($Horoscope::HoroWordsInLineLen - 1)}]]]"
             }
          }
       }
    }

    proc HoroCleanUp HoroHTMLs {
        regsub -all -- {<i class="icon-star-filled highlight"></i>} $HoroHTMLs \00307$Horoscope::UnicodeBlackStar\003 HoroHTMLs
        regsub -all -- {<i class="icon-star-filled"></i>} $HoroHTMLs \00314$Horoscope::UnicodeWhiteStar\003 HoroHTMLs
        #regsub -all -- {(:?<strong>|</strong>|<b>|</b>)} $HoroHTMLs \002 HoroHTMLs
        regsub -all -- {(:?<h4>|</h4>)} $HoroHTMLs \002 HoroHTMLs
        regsub -all -- {<p>([^\s]*)} $HoroHTMLs \00304\\0\003  HoroHTMLs
        regsub -all -- "<.+?>" $HoroHTMLs {} HoroHTMLs
        regsub -all -- {\s+} $HoroHTMLs " " HoroHTMLs
        return [string trim $HoroHTMLs]
     }

    proc FetchDisHoros Link4Horo {
       if {[catch { set TokenHoro [geturl $Link4Horo -timeout [expr {round(1000 * $Horoscope::TimeOutHoro)}]] } HoroErrorMsg]} {
          putcmdlog "[file tail [info script]]: [string map {\n " "} $HoroErrorMsg]"
       }
       if {[string equal -nocase [status $TokenHoro] ok] && [ncode $TokenHoro] == 200} {
          set TheHoroData [data $TokenHoro]
       } else {
          putcmdlog "[file tail [info script]]: [status $TokenHoro] , [code $TokenHoro]"
       };
       cleanup $TokenHoro
       if {[info exists TheHoroData] && [string length $TheHoroData]} {
          return [mapEscapes $TheHoroData]
       } else {
          putcmdlog "[file tail [info script]]: Got no any data from: $Link4Horo"
       }
    }
 }

_________________
Life iS Just a dReaM oN tHE wAy to DeaTh
Back to top
View user's profile Send private message
Arnold_X-P
Op


Joined: 30 Oct 2006
Posts: 188
Location: DALnet - Trinidad - Beni - Bolivia

PostPosted: Fri Jul 26, 2019 12:02 am    Post subject: Reply with quote

it doesn't work on windrop 6.21 tcl 8.5
I load the tcl from htmlparse
and it generates error...

htmlparse 1.0
https://opensource.apple.com/source/tcl/tcl-20/tcl_ext/tcllib/tcllib/modules/htmlparse/htmlparse.tcl.auto.html
or
htmlparse 1.2.2
https://github.com/tcltk/tcllib/blob/master/modules/htmlparse/htmlparse.tcl

which of the two tcl would you use for windrop 6.21 and tcl 8.5
_________________
Very Happy thanks to that they help, that others learn Very Happy
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
heartbroken
Halfop


Joined: 23 Jun 2011
Posts: 90
Location: somewhere out there

PostPosted: Fri Jul 26, 2019 2:02 am    Post subject: Reply with quote

htmlparse using struct::stack and cmdline packages from tcllib .

try to source it like this : http://paste.tclhelp.net/?id=6g75
_________________
Life iS Just a dReaM oN tHE wAy to DeaTh
Back to top
View user's profile Send private message
Dominatez
Voice


Joined: 14 Jan 2019
Posts: 27
Location: United Kingdom

PostPosted: Mon Aug 05, 2019 12:02 am    Post subject: Reply with quote

Thanks Heartbroken,

Confirming that this works like a charm now on the latest eggdrop.
Back to top
View user's profile Send private message
Brut
Voice


Joined: 20 Sep 2019
Posts: 1

PostPosted: Today at 1:14 am    Post subject: TLS & HTTP Package Require Reply with quote

How to install these tls or http packages in eggdrop ??
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 -> Script Requests All times are GMT - 4 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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