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.

Adding multiple commands to Exec

Help for those learning Tcl or writing their own scripts.
Post Reply
c
cquilliam
Voice
Posts: 2
Joined: Thu Nov 05, 2009 10:49 am

Adding multiple commands to Exec

Post by cquilliam »

I am trying to create a url catcher for my eggdrop that not only stores the url, but also grabs the title of the page. Now, I have been able to achieve this goal by having tcl call an external bash script of the follow:

the tcl part:

Code: Select all

  set fd [open $urllogfile a+]
  set title [exec gettitle.sh $i]
  puts $fd "$i;[ctime [unixtime]];$title;$nick;$chan"
  close $fd
the bash part:

Code: Select all

#!/bin/sh
TITLE=`lynx -source $1 | grep -i "<title>" | awk -F "<title>" '{print $2}' | awk -F "</title>" '{print $1}'`
if [ "$TITLE" = "" ]; then
  echo No Title Found
else
  echo $TITLE
fi
Now, while this is working, it is messy to call an external script like this, so, I was wondering if it was possible to translate this into TCL so its all in the same script?

Thanks in advance for any help or tips.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Re: Adding multiple commands to Exec

Post by speechles »

Code: Select all

#put the line below at the very top of your script
package require http

# then change your code to look like this
   if {![string match "http://*" $i]} { set i "http://$i" }
   catch {set http [::http::geturl "$i" -timeout 5000]} error
   if {![string match -nocase "::http::*" $error]} {
     putserv "privmsg $chan :[string totitle [string map {"\n" " | "} $error]] \( $i \)"
     return 0
   }
   if {![string equal -nocase [::http::status $http] "ok"]} {
     putserv "privmsg $chan :[string totitle [::http::status $http]] \( $i \)"
     return 0
   }
   set html [::http::data $http]
   ::http::cleanup
   if {![regexp -nocase -- {<title>(.*?)<title>} $html - title]} { set title "No Title Found" }
   set fd [open $urllogfile a+]
   puts $fd "$i;[ctime [unixtime]];$title;$nick;$chan"
   close $fd
Post Reply