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 

Add URL shortener to existing Google script

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


Joined: 10 Feb 2009
Posts: 140

PostPosted: Mon May 13, 2013 10:34 am    Post subject: Add URL shortener to existing Google script Reply with quote

Would it be possible to convert the Google search result urls to short urls using one or multiple URL shorteners?

Code:

set googlecmdchar "!"

proc google {nick host hand chan type search} {
  if {[lsearch -exact [channel info $chan] +google] != -1} {

    set googlectry "en"

    set googlemax "5"

    set googlelogo "\00312G\003\00304o\003\00307o\003\00312g\003\00303l\003\00304e\003"

    set textf ""

    set linkf ""

    set googlesite ajax.googleapis.com
    set googleurl /ajax/services/search/${type}?v=1.0&rsz=large&q=${search}&ql=${googlectry}&lr=lang_${googlectry}
    if {[catch {set googlesock [socket -async $googlesite 80]} sockerr]} {
      putlog "$googlesite $googleurl $sockerr error"
      return 0
      } else {
      puts $googlesock "GET $googleurl HTTP/1.0"
      puts $googlesock "Host: $googlesite"
      puts $googlesock "User-Agent: Opera 9.6"
      puts $googlesock ""
      flush $googlesock
      while {![eof $googlesock]} {
        set googlevar " [gets $googlesock] "
        set googlelink [regexp -all -nocase -inline {\"url\":\"([^\"]*)\"} $googlevar]
        set googledesc [regexp -all -nocase -inline {\"title\":\"([^\"]*)\"} $googlevar]
        if {$googledesc != "" && $googlelink != ""} {
          for {set x 1} {$x <= [expr 2 * $googlemax]} {incr x 2} {
            putquick "PRIVMSG $chan :$googlelogo $textf[dehex [lindex $googledesc $x]] $linkf[dehex [lindex $googlelink $x]]"
          }
        }
      }
      close $googlesock
      return 0
    }
  }
}

proc asc {chr} {
  scan $chr %c asc
  return $asc
}

proc chr {asc} { return [format %c $asc] }

proc hex {decimal} { return [format %x $decimal] }

proc decimal {hex} { return [expr 0x$hex] }

proc dehex {string} {
  regsub -all {^\{|\}$} $string "" string
  set string [subst [regsub -nocase -all {\\u([a-f0-9]{4})} $string {[format %c [decimal \1]]}]]
  set string [subst [regsub -nocase -all {\%([a-f0-9]{2})} $string {[format %c [decimal \1]]}]]
  set string [subst [regsub -nocase -all {\&#([0-9]{2});} $string {[format %c \1]}]]
  set string [string map {&quot; \" &middot; · &amp; & <b> "" </b> ""} $string]
  return $string
}

proc urlencode {string} {
  regsub -all {^\{|\}$} $string "" string
  return [subst [regsub -nocase -all {([^a-z0-9])} $string {%[format %x [scan "\\&" %c]]}]]
}

proc googleweb {nick host hand chan args} { google $nick $host $hand $chan "web" [urlencode $args] }

proc googlelocal {nick host hand chan args} { google $nick $host $hand $chan "local" [urlencode $args] }

proc googlevideo {nick host hand chan args} { google $nick $host $hand $chan "video" [urlencode $args] }

proc googlenews {nick host hand chan args} { google $nick $host $hand $chan "news" [urlencode $args] }

proc googlebook {nick host hand chan args} { google $nick $host $hand $chan "books" [urlencode $args] }

proc googleimage {nick host hand chan args} { google $nick $host $hand $chan "images" [urlencode $args] }

proc googlepatent {nick host hand chan args} { google $nick $host $hand $chan "patent" [urlencode $args] }

bind pub - ${googlecmdchar}google googleweb
bind pub - ${googlecmdchar}glocal googlelocal
bind pub - ${googlecmdchar}gvideo googlevideo
bind pub - ${googlecmdchar}gnews googlenews
bind pub - ${googlecmdchar}gbook googlebook
bind pub - ${googlecmdchar}gimage googleimage
bind pub - ${googlecmdchar}gpatent googlepatent

setudef flag google


The credits for the author are missing, I found this on the web and stripped it. If you are the author or know the author please let me know so that I can add the credits for this script.
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