/usr/share/amsn/plugins/jake/google.tcl is in amsn-data 0.98.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | proc googleparseArgs { string_text } {
#element 0 from list = text to search
#element 1 from list = number of results to show
#element 2 from list = status (ok if everything is ok, else err)
#if string starts with " and ends with " there are no other args
#elseif string starts with " and has at least one more ". We might have aditional args!
#else string isn't well formatted.
if { [regexp -- {^".*"$} $string_text] } {
#remove first char
set string_text [string range $string_text 1 end]
#remove last char
set string_text [string range $string_text 0 [expr [string length $string_text] - 2]]
set arguments [list $string_text $::jake::config(nresultsgoogle) "ok"]
} elseif { [regexp -- {^".*"} $string_text] } {
#search for the first index of "
set first_index [string first \" $string_text]
#search for the last index of "
set last_index [string last \" $string_text]
#get the number of results to show and remove spaces
set number_of_results [string range $string_text [expr $last_index + 1] [string length $string_text]]
regsub -all { +} $number_of_results {} number_of_results
#get the string between "
set string_text [string range $string_text 1 [expr $last_index - 1]]
#check if the string containing the number of results is integer
if { [string is integer -strict $number_of_results] } {
set arguments [list $string_text $number_of_results "ok"]
} else {
set arguments [list "" 0 "err"]
}
} else {
set arguments [list "" 0 "err"]
}
return $arguments
}
proc googlesearchText { string_text number_of_results language} {
#we need this
package require http
set count 0
set page 0
set ncode 0
catch {
while { $count <= $number_of_results } {
if { $ncode == 403 } {
::http::config -useragent "Jake searcher 0.8 BETA"
set page 0
}
set query [httpformatQuery hl $language num 10 q $string_text start $page]
set token [::http::geturl http://www.google.com/search?$query -timeout 8000]
set ncode [::http::ncode $token]
set data [::http::data $token]
::http::cleanup $token
set spellcheck [regexp -all -inline {class=spell><b><i>.*?</i></b></a>} $data]
if { $spellcheck != "" } {
regexp {class=spell><b><i>(.*?)</i></b></a>} $spellcheck -> spellcheck
append results "[trans txtmaybe]" " " $spellcheck \n\n
}
set matches [regexp -all -inline {<li class=g><h3 class=r><a href=.*?</a></h3>} $data]
foreach match $matches {
if { $spellcheck == "" } {
regexp {<a href=.(.*?). class=l>(.*?)</a></h3>} $match => url title
if { [info exists title] == 1 } {
incr count
}
} else {
regexp {<a href=.(.*?).>(.*?)</a></h3>} $match => url title
if { [info exists title] == 1 } {
incr count
}
}
if { $count <= $number_of_results && [info exists title] == 1 && [info exists url] == 1 } {
append results $count.\ $title " - " $url \n\n
} else {
if { [info exists results] == 0 } {
set results noresults
} else {
#remove the last \n\n
set results [string range $results 0 [expr [string length $results] - 3]]
#remove the <em></em> thing
regsub -all {<em>} $results "" results
regsub -all {</em>} $results "" results
}
return $results
}
}
set page [expr $page + 10]
}
}
return $results
}
proc googledefineText { string_text number_of_results language} {
#we need this
package require http
set query [httpformatQuery hl $language q define:$string_text]
set token [::http::geturl http://www.google.com/search?$query -timeout 8000]
set ncode [::http::ncode $token]
set data [::http::data $token]
::http::cleanup $token
set matches [regexp -all -inline {<li>.*?</font></a>} $data]
set count 0
foreach match $matches {
regexp {<li>(.*?)<br>(.*?)</a>} $match => title url
regexp {<a href=\"(.*?)\"><font color=.......>(.*?)</font>} $url => garbage url
if { [info exists title] == 1 } {
incr count
}
if { $count <= $number_of_results && [info exists title] == 1 && [info exists url] == 1 } {
append results $count.\ $title " - " $url \n\n
} else {
if { [info exists results] == 0 } {
set results noresults
}
}
}
if { [info exists results] == 0 } {
set results noresults
} else {
#remove the last \n\n
set results [string range $results 0 [expr [string length $results] - 3]]
#remove the <em></em> thing
regsub -all {<em>} $results "" results
regsub -all {</em>} $results "" results
}
return $results
}
|