| View previous topic :: View next topic |
| Author |
Message |
holycrap Op
Joined: 21 Jan 2008 Posts: 152
|
Posted: Mon Jan 21, 2008 11:24 pm Post subject: gconvert.tcl Update Please! :) |
|
|
Can someone fix this script? I think Google might have changed something. It is in the TCL Archive, just search for google.
Thanks for the help guys!
Name: gconvert.tcl
Version: 2.1
Author: AkiraX
http://www.egghelp.org/cgi-bin/tcl_archive.tcl?mode=download&id=1312
Last edited by holycrap on Fri Dec 24, 2010 8:57 pm; edited 7 times in total |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Tue Jan 22, 2008 1:18 am Post subject: |
|
|
Google has changed many things. A recent change were onebox results (aka the calculator/converter/etc). Use Incith:google instead (search the forum, both official and unofficial versions exist) which both already do calculations/conversions/etc (among other things). If what you wanted was just the calculations/conversions, simply borrow from the script example. Find the relevant regexp sections from incith:google and apply them to relevant regexp sections of that script.
Last edited by speechles on Tue Jan 22, 2008 1:24 am; edited 1 time in total |
|
| Back to top |
|
 |
holycrap Op
Joined: 21 Jan 2008 Posts: 152
|
Posted: Tue Jan 22, 2008 1:23 am Post subject: |
|
|
I'm a bit retarded when it comes to programming. I just want the !convert and !calc commands. If it's not too much trouble, can you please paste the new codes on here from what you just wrote above?
Thanks for the fast response and your time.  |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Tue Jan 22, 2008 1:45 am Post subject: |
|
|
| holycrap wrote: | I'm a bit retarded when it comes to programming. I just want the !convert and !calc commands. If it's not too much trouble, can you please paste the new codes on here from what you just wrote above?
Thanks for the fast response and your time.  |
This is your example silly. Didn't you notice the author? The code is commented, look for # calculator those are your regexp fixes. Did_you_mean is there as well, clearly commented... Hopefully the author of this can help you out as it's considered bad form to support two google scripts ya know what I mean...
...and to not appear so mean, here is a hint in the code below to fix the calculator/conversion part... find the line below and change it to line below that disregarding the #commented line. | Code: | #change from
regexp {src=/images/calc_img.gif alt=""></td><td> </td><td nowrap>(.*?)</td>} $line match convert(answer) |
| Code: | #change to
regexp -nocase -- {calc_img.+?nowrap>(.+?)</} $line - convert(answer) |
This regexp fix should allow the script to better parse through future html changes. |
|
| Back to top |
|
 |
holycrap Op
Joined: 21 Jan 2008 Posts: 152
|
Posted: Tue Jan 22, 2008 6:29 am Post subject: |
|
|
Just had a chance to test the script. Just wondering why it's showing extra stuff.
<me> !convert usd to aud
<bot> <font size=+1><b>1 foot = 30.48 centimeters
Why is the "<font size=+1><b>" showing?
Thanks for all the help ahead of time.  |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Jan 22, 2008 7:55 am Post subject: |
|
|
| Because no one maintains this script. |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Tue Jan 22, 2008 7:56 am Post subject: |
|
|
| holycrap wrote: | Just had a chance to test the script. Just wondering why it's showing extra stuff.
<me> !convert usd to aud
<bot> <font size=+1><b>1 foot = 30.48 centimeters
Why is the "<font size=+1><b>" showing?
Thanks for all the help ahead of time.  |
More to the point, why is the result a metric measurement and not a currency conversion (as indicated by your post)?  _________________ Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Tue Jan 22, 2008 3:29 pm Post subject: |
|
|
| holycrap wrote: | Just had a chance to test the script. Just wondering why it's showing extra stuff.
<me> !convert usd to aud
<bot> <font size=+1><b>1 foot = 30.48 centimeters
Why is the "<font size=+1><b>" showing?
Thanks for all the help ahead of time.  |
| Code: | #change to
if {[regexp -nocase -- {calc_img.+?nowrap>(.+?)</} $line - convert(answer)]} { regsub -nocase -- {<(.*?)>} $convert(answer) "" convert(answer) } |
This corrects the html cruft, but in the long run I suggest you find an alternative script to use that accomplishes the same thing. Because did_you_mean is broken in this script as well, and I have no intentions on fully fixing this script mind you. Keep rosc2112's comments in mind....
and alchera has an interesting comment as well, why are you querying usd to aud and getting centimeters in feet??! 
Last edited by speechles on Fri Jan 25, 2008 5:34 pm; edited 2 times in total |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Jan 22, 2008 8:00 pm Post subject: |
|
|
| For replacement scripts, I have a convert script for metric/imperial unit conversions and a currency convertor script... Check the archive. |
|
| Back to top |
|
 |
holycrap Op
Joined: 21 Jan 2008 Posts: 152
|
Posted: Tue Jan 22, 2008 8:10 pm Post subject: |
|
|
regexp -nocase -- {calc_img.+?nowrap>(.+?)</} $line - convert(answer)
regsub -nocase -- {<(.*?)>} $convert(answer) "" convert(answer)
The output is still showing:
<me> !convert ft to cm
<bot> <b>1 foot = 30.48 centimeters
Last edited by holycrap on Fri Feb 01, 2008 5:25 am; edited 1 time in total |
|
| Back to top |
|
 |
Sairus88 Voice
Joined: 25 Jan 2008 Posts: 2
|
Posted: Fri Jan 25, 2008 5:20 pm Post subject: |
|
|
| 2 holycrap: Can you paste here modified script pls? |
|
| Back to top |
|
 |
texke Voice
Joined: 22 May 2008 Posts: 3 Location: Eeklo, Belgium
|
Posted: Thu May 22, 2008 5:39 pm Post subject: |
|
|
This version works for me (for now):
| Code: |
if { [regexp {src=/images/calc_img.gif} $line] } {
regexp "calc_img.+?nowrap>(.+?)/h" $line - convert(answer)
regexp "<b>(.*)</b>" $convert(answer) match convert(answer)
set try_again 0
break
}
|
|
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Thu May 22, 2008 6:49 pm Post subject: |
|
|
| Code: | if {[regexp {src=/images/calc_img.gif} $line]} {
# to remove bold, comment the bold line, uncomment the no bold.
regsub -all -- "(?:<b>|</b>)" line "\002" $line ;# bold
#regsub -all -- "(?:<b>|</b>)" line "" $line ;# no bold
if {[regexp -nocase -- {calc_img.+?nowrap><h2.+?>(.+?)</} $line - convert(answer)]} {
regexp -- {^(.+?)</td></tr>} $convert(answer) -> convert(answer)
} else {
set convert(answer) "found calc_img.gif but cannot parse further."
}
set try_again 0
break
} |
This is how it's done within unofficial google script. This way has catches to detect parsing errors as well as embolding.
Also, you can use the code below in full and it will emulate the behavior of the unofficial incith google script. It allows full multi-language (albeit without the encode_strings and such full google script has) using country switches.
!convert .fr tablespoons to cups returns the result of this in French, if there are no results, the error message displayed will be in French (as well you can use the French words for 'tablespoons to cups' and it will work too).
!convert 2+2 one would think !math would be appropriate for this, but all three triggers now behave using the same proc so this will work and it will default to the language used by ConvertCountry variable in the config which at default is set to "com".
!math feet in inches Once again, this works even tho we are trying to convert using math. Default language given will match what is set for ConvertCountry
These would all be valid, because instead of using separate procedures for each. The parsers can catch all of this within the same proc. | Code: | | Use the code from the post of mine found below, it works! |
Untested at the moment, can't really do that until I get back from work this morning (night shift sux!). If you notice, did incorporate a better url encoder since allowing the freedom to use any regional google server. Side-effect of this is you can also use the convert/math as a spell checker it will display did you means as well. No english words used as parser templates either, all results read directly from page nothing script generated (except two which occur when the parsers template requirements cannot be met, they are "Sorry, didn't work out." and "found calc_img.gif but cannot parse further.") so this should work for any dialect (within reason, keep in mind there is no encode_strings like unofficial google has... this is as close as you get without using the full script) 
Last edited by speechles on Fri May 23, 2008 10:16 am; edited 2 times in total |
|
| Back to top |
|
 |
holycrap Op
Joined: 21 Jan 2008 Posts: 152
|
Posted: Fri May 23, 2008 4:35 am Post subject: |
|
|
I've tried your script, but it didn't work, speechles.
Thanks for trying though.
Thank you "texke", your mod works! :D
-----------------------
1st portion
-----------------------
if { [regexp {src=/images/calc_img.gif} $line] } {
regexp "calc_img.+?nowrap>(.+?)/h" $line - convert(answer)
regexp "<b>(.*)</b>" $convert(answer) match convert(answer)
set try_again 0
break
}
-----------------------
2nd portion
-----------------------
if { [regexp {src=/images/calc_img.gif} $line] } {
regexp "calc_img.+?nowrap>(.+?)/h" $line - calc(answer)
regexp "<b>(.*)</b>" $calc(answer) match calc(answer)
set try_again 0
break
} |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Fri May 23, 2008 10:08 am Post subject: |
|
|
Haw, I told you I had to work nightshift. No need to use that, instead, use this. | Quote: | <speechles> !calc 873247887asdasdasdasd
<sp33chy> Your search - 873247887asdasdasdasd - did not match any documents.
<speechles> !calc fturama
<sp33chy> Did you mean: futurama?
<speechles> !calc 2+2
<sp33chy> 2 + 2 = 4
<speechles> !calc 2+2 + alphabet stew
<sp33chy> Unable to parse anything meaningful.
<speechles> !calc 100 euro + the answer to life, the universe and everything USD in peso
<sp33chy> (100 Euros) + (the answer to life, the universe and everything U.S. dollars) = 2 041.80411 Mexican pesos
<speechles> !calc 2 bushels in pecks
<sp33chy> 2 US bushels = 8 US pecks |
| Code: | #############################################
# gconvert.tcl v3.1 by speechles #
# -Parsers/Encoders from Unofficial google- #
#############################################
##############
# OLD INFO #
#############################################
# gconvert.tcl v2.0 by AkiraX #
# <#AnimeFiends@EFNet> #
#############################################
####### DESCRIPTION #########################
# Uses the google calculator to perform
# conversions and mathematics
#############################################
####### USAGE ###############################
# .chanset #yourchan +gconvert
# !convert <quantity> to <quantity> : perform conversions
# !math [.country.code] <equation> : perform mathematics
# !calc [.country.code] <equation> : perform calculations
# !spell [.country.code] <something> : perform spell checks
#
# all 4 of the above commands are identical, each can perform the
# actions of the other depending on the template detected when
# querying google and receiving html. If you wish to use only 1
# command to do everything, this is 100% possible and you
# can remove any binds you wish above to do so.
#############################################
####### CHANGELOG ###########################
# v3.1 : Adapted script to fit Google's new redesign.
# v3.0 : fixed functionality, added .chanset #yourchan +gconvert
# added multilanguage, added spell check, added dynamic
# messages, added custom static messages, removed
# redundant socket attempts, condensed procedures to
# one for everything.
# v2.1 : fixed functionality, repaired by Scott Glover
# v2.0 : allow convert code to perform math
# v1.0 : support for google conversions
#############################################
####### LICENSE #############################
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U
#############################################
####### CONFIG #############################
# this is where you can configure default behavior.
# select your default regional google server
# google.* - it can be any valid domain TLD for google.
variable ConvertCountry "com"
# select your default results not found message
variable ConvertMsg1 "Unable to parse anything meaningful."
variable ConvertMsg2 "Found calculator template but cannot parse within."
############################################
package require http
setudef flag gconvert
bind pub -|- !math gconvert:run
bind pub -|- !calc gconvert:run
bind pub -|- !convert gconvert:run
bind pub -|- !spell gconvert:run
proc gconvert:run { nick host handle chan text } {
if {[lsearch -exact [channel info $chan] +gconvert] == -1} {return}
set convert(nick) $nick
set convert(input) $text
regexp -nocase -- {^\.(.+?)\s(.+?)$} $convert(input) - convert(country) convert(input)
if {![info exists convert(country)]} {
set convert(country) "$::ConvertCountry"
}
# create google URL
set token [http::config -useragent "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e"]
set convert(url) "http://www.google.$convert(country)/search?q=[gconvert:webstring $convert(input)]&safe=off&btnG=Search&lr=lang_all&num=10"
# grab the info from google
catch {set token [http::geturl $convert(url) -timeout 15000]} error
if {[string match -nocase "*couldn't open socket*" $error]} {
puthelp "PRIVMSG $chan :Sorry, cannot create a socket to \"$convert(url)\"."
return 0
} elseif {[::http::status $token] == "timeout"} {
puthelp "PRIVMSG $chan :Sorry, your request to \"$convert(url)\" has timed out."
return 0
}
set html [gconvert:clean [http::data $token]]
http::cleanup $token
# find the answer
set convert(answer) ""
if {[string match "*</div><div id=res class=med>*" $html]==1} {
if {[regexp -nocase -- {</div><div id=res class=med><p>(.+?)<a href=.*?>(.+?)</a>} $html {} item did_you_mean]} {
set convert(answer) "${item}${did_you_mean}"
if {[string match "*<img src=/images/calc_img*" $item] == 1} {
regexp -nocase -- {calc_img.+?nowrap.*?>(.+?)</} $item - item
set convert(answer) "${item}"
}
}
regexp -- {(.+?)</td></tr>} $convert(answer) -> convert(answer)
regsub -all -- {<(.+?)>} $convert(answer) "" convert(answer)
} elseif {[regexp {src=/images/calc_img.gif} $html]} {
if {[regexp -nocase -- {calc_img.+?nowrap.*?>(.+?)</td></tr>} $html - convert(answer)]} {
regexp -- {(.+?)</td></tr>} $convert(answer) -> convert(answer)
} else {
set convert(answer) $::ConvertMsg2
}
}
if { $convert(answer) == "" } {
if {![regexp -- {</div><div id=res class=med>(?!<)(.+?)<p style} $html - no_search]} {
set convert(answer) $::ConvertMsg1
} else {
regexp -- {^(.+?)</td></tr>} $no_search - no_search
regsub -- {</a>} $no_search "? " no_search
regsub -all -- {<(.+?)>} $no_search { } no_search
while {[string match "* *" $no_search]} {
regsub -all -- { } $no_search " " no_search
}
set convert(answer) [string trim $no_search]
}
}
puthelp "PRIVMSG $chan :[descdecode $convert(answer)]"
return 1
}
proc gconvert:clean { input } {
regsub -all {(?:\t|\n|\r|\v)} $input "" input
regsub -all "(?:<b>|</b>)" $input "\002" input
regsub -all "(?:\x91|\x92|')" $input {'} input
regsub -all "(?:\x93|\x94|")" $input {"} input
regsub -all " " $input "" input
regsub -all "&" $input {\&} input
regsub -all -nocase {<sup>(.+?)</sup>} $input {^\1} input
regsub -all -nocase {<font.*?>} $input "" input
regsub -all -nocase {</font>} $input "" input
regsub -all -nocase {<span.*?>} $input "" input
regsub -all -nocase {</span>} $input "" input
regsub -all -nocase {<input.*?>} $input "" input
regsub -all -nocase {(?:<i>|</i>)} $input "" input
return $input
}
proc descdecode {text} {
# code below is neccessary to prevent numerous html markups
# from appearing in the output (ie, ", ?, etc)
# stolen (borrowed is a better term) from perplexa's urban
# dictionary script..
if {![string match *&* $text]} {return $text}
set escapes {
\x20 " \x22 & \x26 ' \x27 – \x2D
< \x3C > \x3E ˜ \x7E € \x80 ¡ \xA1
¢ \xA2 £ \xA3 ¤ \xA4 ¥ \xA5 ¦ \xA6
§ \xA7 ¨ \xA8 © \xA9 ª \xAA « \xAB
¬ \xAC ­ \xAD ® \xAE &hibar; \xAF ° \xB0
± \xB1 ² \xB2 ³ \xB3 ´ \xB4 µ \xB5
¶ \xB6 · \xB7 ¸ \xB8 ¹ \xB9 º \xBA
» \xBB ¼ \xBC ½ \xBD ¾ \xBE ¿ \xBF
À \xC0 Á \xC1 Â \xC2 Ã \xC3 Ä \xC4
Å \xC5 Æ \xC6 Ç \xC7 È \xC8 É \xC9
Ê \xCA Ë \xCB Ì \xCC Í \xCD Î \xCE
Ï \xCF Ð \xD0 Ñ \xD1 Ò \xD2 Ó \xD3
Ô \xD4 Õ \xD5 Ö \xD6 × \xD7 Ø \xD8
Ù \xD9 Ú \xDA Û \xDB Ü \xDC Ý \xDD
Þ \xDE ß \xDF à \xE0 á \xE1 â \xE2
ã \xE3 ä \xE4 å \xE5 æ \xE6 ç \xE7
è \xE8 é \xE9 ê \xEA ë \xEB ì \xEC
í \xED î \xEE ï \xEF ð \xF0 ñ \xF1
ò \xF2 ó \xF3 ô \xF4 õ \xF5 ö \xF6
÷ \xF7 ø \xF8 ù \xF9 ú \xFA û \xFB
ü \xFC ý \xFD þ \xFE ÿ \xFF
}
set text [string map $escapes $text]
# tcl filter required because we are using SUBST command below
# this will escape any sequence which could potentially trigger
# the interpreter..
regsub -all -- \\\\ $text \\\\\\\\ text
regsub -all -- \\\[ $text \\\\\[ text
regsub -all -- \\\] $text \\\\\] text
regsub -all -- \\\} $text \\\\\} text
regsub -all -- \\\{ $text \\\\\{ text
regsub -all -- \\\" $text \\\\\" text
regsub -all -- \\\$ $text \\\\\$ text
# end tcl filter
regsub -all -- {&#([[:digit:]]{1,5});} $text {[format %c [string trimleft "\1" "0"]]} text
regsub -all -- {&#x([[:xdigit:]]{1,4});} $text {[format %c [scan "\1" %x]]} text
regsub -all -- {&#?[[:alnum:]]{2,7};} $text "?" text
return [subst $text]
}
proc gconvert:webstring { input } {
set url ""
foreach byte [split [encoding convertto utf-8 $input] ""] {
scan $byte %c i
if {$i < 65 || $i > 122} {
append url [format %%%02X $i]
} else {
append url $byte
}
}
return [string map {%3A : %2D - %2E . %2F / %30 0 %31 1 %32 2 %33 3 %34 4 %35 5 %36 6 %37 7 %38 8 %39 9 \[ %5B \\ %5C \] %5D \^ %5E \_ %5F \` %60} $url]
}
putlog "gconvert.tcl v3.0 by speechles (based upon v2.0 by AkiraX <#AnimeFiends@EFnet>) loaded!" | Works perfectly.........
| this script has transcoding support wrote: | <speechles> !calc 2 + 7 + 99 / 7 *12371267367123
<sp33chy> 2 + 7 + ((99 / 7) * 12 371 267 367 123) = 1.74965067 × 10^14 |
| that other script does not, notice the difference wrote: | <speechles> !calc 2 + 7 + 99 / 7 *12371267367123
<sp33chy> 2 + 7 + ((99 / 7) * 12 371 267 367 123) = 1.74965067 × 10^14 |
For full support of extended character sets and seamless transcoding, use this not that, kthx
::Edit:: on closer inspection, wow, it does do minimal transcoding.. but is this enough? doubtful... heh | Quote: | set input [string map { {<font size=-2> </font>} {,} } $input]
set input [string map { {×} {x} } $input]
set input [string map { {10<sup>} {10^} } $input]
set input [string map { {</sup>} {} } $input] | Cannot use code tags above, it tries to render the html, using quote with markups injected can show the unrendered html.
Quite mediocre, but then mediocrity might suffice for 80% of the queries, if you want 100% there is a a better way....
Edit: corrected per holycrap's request. now works and has been tested. 
Last edited by speechles on Fri Oct 10, 2008 11:25 pm; edited 2 times in total |
|
| Back to top |
|
 |
|
|
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
|
|