Beege Posted July 18, 2009 Posted July 18, 2009 (edited) Heres four short and quick functions that use google that might come in handy for some people. Ideas came from Travis and IchBistTod scripts. Can anyone think of any more? expandcollapse popup#include <inet.au3> #include <array.au3> $suggestions = _GoogleSuggestions('autoit s') _ArrayDisplay($suggestions, 'Suggestions') $Definitions = _GoogleDefine("Pulp") _ArrayDisplay($Definitions, 'Pulp ') $Translate = _GoogleTranslate("Hello how are you?") MsgBox(0, 'English to Spanish ', "Hello how are you?" & @CRLF & $Translate) $convert = _GoogleUnitConvert(10, 'gallons', 'liters') MsgBox(0,'Gallons to Liters', '10 Gallons = ' &$convert& ' Liters') Func _GoogleSuggestions($sSuggest); Retruns an Array of Suggestions Local $sSource, $aResults;, $aQueries $sSource = _INetGetSource("http://google.com/complete/search?output=toolbar&q=" & $sSuggest) If @error Then Return SetError(1) $aResults = StringRegExp($sSource, '<CompleteSuggestion><suggestion data="(.*?)"/>', 3) ;~ $sQueries = StringRegExp($source, '"/><num_queries int="(\d{0,})"/>', 3) Return $aResults EndFunc ;==>_GoogleSuggestions Func _GoogleDefine($sKeyWord) Local $aDefintions, $sSource $sSource = _INetGetSource("http://www.google.com/search?q=define%3A" & $sKeyWord) If @error Then Return SetError(1) $aDefintions = StringRegExp($sSource, "<li>(.*?)<br>", 1) Return StringSplit(StringRegExpReplace($aDefintions[0], '(<li>)', '|'), '|') EndFunc ;==>_GoogleDefine Func _GoogleTranslate($sText, $sTo = "es", $sFrom = "en") Local $sTranslation, $sUrl, $sSource $sUrl = StringFormat("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=%s&langpair=%s%%7C%s", $sText, $sFrom, $sTo) $sSource = _INetGetSource($sUrl) $sTranslation = StringRegExp(BinaryToString($sSource, 4), '"translatedText":"([^"]+)"', 1) Return $sTranslation[0] EndFunc ;==>_GoogleTranslate ;~ spanish = es, Albanian = sq, Arabic = ar, Bulgarian = bg,Catalan = ca, Croatian = hr, Czech = cs,Danish = da ;~ dutch = nl,Estonian = et,Filipino = tl, Finnish = fi, French = fr, Galician = gl,German = de,Greek = el ;~ Hebrew = iw,Hindi = hi - no, Hungarian = hu,Indonesian = id, Italian = it, Latvian = lv,Vietnamese = vi ;~ Turkish = tr,Swedish = sv,Russian = ru, Portuguese = pt, English = en Func _GoogleUnitConvert($sValue, $sFrom, $sTo) Local $sSource $sSource = _INetGetSource("http://www.google.com/search?q=" & $sValue & "%20" & StringLower($sFrom) & "%20in%20" & StringLower($sTo)) If @error Then Return SetError(1) $sSource = StringRegExp($sSource, '<h2(.*?)More about calculator.</a>', 1) $sSource = StringRegExp($sSource[0], '=\s(.*?)\s[a-z]*(\s?[a-z]*?)</b>', 1) Return StringReplace($sSource[0], Chr(160), '') EndFunc ;==>_GoogleUnitConvert Edited July 21, 2009 by bchris01 guestscripter 1 Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator
zackrspv Posted July 18, 2009 Posted July 18, 2009 (edited) Haha, nice, there's a few others that I had fun with too, but yours is by far quite eloquent.I decided to have some fun.Very simple interface, but i'm going to impliment it inside of one of my apps for quick usage Does: Autosuggest based on what you type (minimum 3 letters), auto define, auto translate. All based on what you type, as you type it.Screenshot:expandcollapse popup#include <inet.au3> #include <array.au3> #include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> $test = GUICreate("test", 800, 800, -1, -1) $input = GUICtrlCreateInput("", 5, 10, 550, 30) $list = GUICtrlCreateListView("Suggestion", 5, 40, 260, 700) _GUICtrlListView_SetColumnWidth($list, 0, 245) $defines = GUICtrlCreateEdit("", 265, 192, 530, 550, $ES_MULTILINE, 0) $edit = GUICtrlCreateEdit("", 265, 40, 295, 150, $ES_MULTILINE, 0) $from = GUICtrlCreateCombo("en - English", 560, 13, 90, 20) GUICtrlSetData(-1, "es - Spanish|sq - Albanian|ar - Arabic|bg - Bulgarian|ca - Catalan|hr - Croatian|cs - Czeh|da - Danish|nl - Dutch|et - Estonian|tl - Filipino|fi - Finish|fr - French|gl - Galacian|de - German|el - Greek|iw - Hebrew|hi - Hindi|hu - Hungarian|id - Indonesian|it - Italian|lv - Latvian|vi - Vietnamese|tr - Turkish|sv - Sweedish|ru - Russian|pt - Portuguese") $to = GUICtrlCreateCombo("es - Spanish", 650, 13, 90, 20) GUICtrlSetData(-1, "en - English|sq - Albanian|ar - Arabic|bg - Bulgarian|ca - Catalan|hr - Croatian|cs - Czeh|da - Danish|nl - Dutch|et - Estonian|tl - Filipino|fi - Finish|fr - French|gl - Galacian|de - German|el - Greek|iw - Hebrew|hi - Hindi|hu - Hungarian|id - Indonesian|it - Italian|lv - Latvian|vi - Vietnamese|tr - Turkish|sv - Sweedish|ru - Russian|pt - Portuguese") GUICtrlCreateLabel("", 563, 40, 235, 150) GUICtrlSetData(-1, "spanish = es, Albanian = sq, Arabic = ar, Bulgarian = bg,Catalan = ca, Croatian = hr, Czech = cs,Danish = da" & _ "dutch = nl,Estonian = et,Filipino = tl, Finnish = fi, French = fr, Galician = gl,German = de,Greek = el" & _ "Hebrew = iw,Hindi = hi - no, Hungarian = hu,Indonesian = id, Italian = it, Latvian = lv,Vietnamese = vi" & _ "Turkish = tr,Swedish = sv,Russian = ru, Portuguese = pt, English = en") GUISetState() $olddata = "" ConsoleWrite(_GUICtrlListView_GetSelectedCount($list) > 0 & @CRLF) While 1 $msg = GUIGetMsg() Switch $msg Case - 3 Exit Case $from, $to $Translate = _GoogleTranslate(GUICtrlRead($input), StringLeft(GUICtrlRead($to), 2), StringLeft(GUICtrlRead($from), 2)) GUICtrlSetData($edit, $Translate) EndSwitch If _GUICtrlListView_GetSelectedCount($list) <> False Then $found = _GUICtrlListView_GetItemTextString($list, -1) GUICtrlSetData($input, $found) EndIf If GUICtrlRead($input) <> "" Then $data = GUICtrlRead($input) If $olddata <> $data Then If StringLen($data) < 3 Then Else $suggestions = _GoogleSuggestions($data) _GUICtrlListView_DeleteAllItems($list) GUICtrlSetData($defines, "") GUICtrlSetData($edit, "") For $i = 1 To UBound($suggestions) - 1 GUICtrlCreateListViewItem($suggestions[$i], $list) ConsoleWrite($suggestions[$i] & @CRLF) Next $Definitions = _GoogleDefine($data) For $i = 0 To UBound($Definitions) - 1 GUICtrlSetData($defines, $i & ": " & $Definitions[$i] & @CRLF, $defines) Next $Translate = _GoogleTranslate($data, StringLeft(GUICtrlRead($to), 2), StringLeft(GUICtrlRead($from), 2)) GUICtrlSetData($edit, $Translate) EndIf EndIf $olddata = $data EndIf WEnd $suggestions = _GoogleSuggestions('autoit s') _ArrayDisplay($suggestions, 'Suggestions') $Definitions = _GoogleDefine("Pulp") _ArrayDisplay($Definitions, 'Pulp ') $Translate = _GoogleTranslate("Hello how are you?") MsgBox(0, 'English to Spanish ', "Hello how are you?" & @CRLF & $Translate) Func _GoogleSuggestions($sSuggest); Retruns an Array of Suggestions Local $sSource, $aResults;, $aQueries $sSource = _INetGetSource("http://google.com/complete/search?output=toolbar&q=" & $sSuggest) If @error Then Return SetError(1) $aResults = StringRegExp($sSource, '<CompleteSuggestion><suggestion data="(.*?)"/>', 3) ;~ $sQueries = StringRegExp($source, '"/><num_queries int="(\d{0,})"/>', 3) Return $aResults EndFunc ;==>_GoogleSuggestions Func _GoogleDefine($sKeyWord) Local $aDefintions, $sSource $sSource = _INetGetSource("http://www.google.com/search?q=define%3A" & $sKeyWord) If @error Then Return SetError(1) $aDefintions = StringRegExp($sSource, "<li>(.*?)<br>", 1) If IsArray($aDefintions) Then Return StringSplit(StringRegExpReplace($aDefintions[0], '(<li>)', '|'), '|') Else Return "" EndIf EndFunc ;==>_GoogleDefine Func _GoogleTranslate($sText, $sTo = "es", $sFrom = "en") Local $sTranslation, $sUrl, $sSource $sUrl = StringFormat("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=%s&langpair=%s%%7C%s", $sText, $sFrom, $sTo) $sSource = _INetGetSource($sUrl) $sTranslation = StringRegExp(BinaryToString($sSource, 4), '"translatedText":"([^"]+)"', 1) If IsArray($sTranslation) Then Return $sTranslation[0] Else Return "" EndIf EndFunc ;==>_GoogleTranslate ;~ spanish = es, Albanian = sq, Arabic = ar, Bulgarian = bg,Catalan = ca, Croatian = hr, Czech = cs,Danish = da ;~ dutch = nl,Estonian = et,Filipino = tl, Finnish = fi, French = fr, Galician = gl,German = de,Greek = el ;~ Hebrew = iw,Hindi = hi - no, Hungarian = hu,Indonesian = id, Italian = it, Latvian = lv,Vietnamese = vi ;~ Turkish = tr,Swedish = sv,Russian = ru, Portuguese = pt, English = en[c Edited July 18, 2009 by zackrspv -_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.
Yashied Posted July 18, 2009 Posted July 18, 2009 Very good. I think you need to expand the list of functions and make it as UDF. In this case, 5* for you from me is guaranteed. Thanks. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
dantay9 Posted July 20, 2009 Posted July 20, 2009 I agree. 5 stars from me too. I really like the translator. I have seen many people try to use sites like babelfish, but I haven't seen many people try google. These are very good results from a different source. I like the suggestions and the translator very much.
Beege Posted July 20, 2009 Author Posted July 20, 2009 Thanks for the comments guys. In the future I would like to add one more function. _GoogleUnitConvert(). Im always using googles unit converter.. Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator
Beege Posted July 21, 2009 Author Posted July 21, 2009 (edited) Heres the _GoogleUnitConvert() I said I would do. If your wondering about why I used stringlower() on $sTo and $sFrom, its because Google is picky! Apparently no capital letters are allowed. "10 miles in feet" works fine, but "10 Miles in feet" will not work. Ya.. kinda dumb. #include <inet.au3> #include <array.au3> $convert = _GoogleUnitConvert(.03,'kilowatt hours', 'joules') MsgBox(0,'Kilowatt Hours to Joules', '.03 Kilowatt Hours = ' & $convert & ' Joules') MsgBox(0,'Gallons to Liters', '10 Gallons = ' &_GoogleUnitConvert(10, 'gallons', 'liters')& ' Liters') Func _GoogleUnitConvert($sValue, $sFrom, $sTo) Local $sSource $sSource = _INetGetSource("http://www.google.com/search?q=" & $sValue & "%20" & StringLower($sFrom) & "%20in%20" & StringLower($sTo)) If @error Then Return SetError(1) $sSource = StringRegExp($sSource, '<h2(.*?)More about calculator.</a>', 1) $sSource = StringRegExp($sSource[0], '=\s(.*?)\s[a-z]*(\s?[a-z]*?)</b>', 1) Return StringReplace($sSource[0], Chr(160), '') EndFunc ;==>_GoogleUnitConvert Edited July 21, 2009 by bchris01 Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator
Shafayat Posted December 25, 2009 Posted December 25, 2009 This is really a good script (in the first post). Can you tell me how to set the "Detect Language" option in the to param (instead of a certain language)? [Not using this account any more. Using "iShafayet" instead]
pierrotm777 Posted May 1, 2010 Posted May 1, 2010 Heres the _GoogleUnitConvert() I said I would do. If your wondering about why I used stringlower() on $sTo and $sFrom, its because Google is picky! Apparently no capital letters are allowed. "10 miles in feet" works fine, but "10 Miles in feet" will not work. Ya.. kinda dumb. #include <inet.au3> #include <array.au3> $convert = _GoogleUnitConvert(.03,'kilowatt hours', 'joules') MsgBox(0,'Kilowatt Hours to Joules', '.03 Kilowatt Hours = ' & $convert & ' Joules') MsgBox(0,'Gallons to Liters', '10 Gallons = ' &_GoogleUnitConvert(10, 'gallons', 'liters')& ' Liters') Func _GoogleUnitConvert($sValue, $sFrom, $sTo) Local $sSource $sSource = _INetGetSource("http://www.google.com/search?q=" & $sValue & "%20" & StringLower($sFrom) & "%20in%20" & StringLower($sTo)) If @error Then Return SetError(1) $sSource = StringRegExp($sSource, '<h2(.*?)More about calculator.</a>', 1) $sSource = StringRegExp($sSource[0], '=\s(.*?)\s[a-z]*(\s?[a-z]*?)</b>', 1) Return StringReplace($sSource[0], Chr(160), '') EndFunc ;==>_GoogleUnitConvert Is it possible to use the _GoogleUnitConvert to convert the money . I have tried this line that give me an error: MsgBox(0,'Gallons to Liters', '1 dollar = ' &_GoogleUnitConvert(1, 'dollar', 'euro')& ' euro') I have tried also that but i have the same issue: MsgBox(0,'Gallons to Liters', '1 dollar = ' &_GoogleUnitConvert(1, 'usd', 'eur')& ' euro') Thanks for all help
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now