Web lookup

Functions, classes, components, etc. Only high quality content.

Web lookup

Postby Lindsey on Fri Mar 14, 2003 6:39 pm

Here are a few somewhat more complicated macros which let you look up different kinds of information on the web.

You’ll need to define BROWSER_EXE in your startup macro to whichever browser you prefer. For example:

def BROWSER_EXE "iexplore.exe"

Three of these macros use the Substitute function:

Substitute
(Replaces all instances of "findStr" in "myStr" with "replaceStr")
----------------
;/
function ~&myStr ~findStr [~replaceStr] [#flags]

int lastFind = 0
int foundIndex
str tempStr

if( findStr.len == 0 )
,ret

rep
,foundIndex = find( myStr, findStr, lastFind, flags )
,if( foundIndex == -1 )
,,ret
,tempStr.get( myStr, (foundIndex + findStr.len) )
,myStr.fromn( myStr, foundIndex, replaceStr, -1, tempStr, -1 )
,lastFind + replaceStr.len
----------------


This one automatically searches using Google. If some text is selected, it searches for that. If nothing is selected (or as a sanity check, if a large amount of text is selected), then you get a small dialog that lets you choose the search terms.

You can change hl=en to match your favorite language.

Find with Google
----------------
str+ theSearchWords
str searchURL
str selectionText

selectionText.getsel
if( (selectionText.len != 0) && (selectionText.len < 100) )
,searchURL = selectionText
else
,inp-(theSearchWords, "Search for the words:", "Find on the web", theSearchWords)
,searchURL = theSearchWords
Substitute( &searchURL, "+", "%2B" )
searchURL.trim( )
searchURL - "www.google.com/search?hl=en&q="
run BROWSER_EXE searchURL
----------------


This one is much like the last, except that it looks up the word in an online English dictionary, instead:

Dictionary
----------------
str+ theSearchWords
str searchURL
str selectionText

selectionText.getsel
if( (selectionText.len != 0) && (selectionText.len < 40) )
,searchURL = selectionText
else
,inp-(theSearchWords, "Define the word", "Dictionary", theSearchWords)
,searchURL = theSearchWords
Substitute( &searchURL, "+", "%2B" )
searchURL.trim( )
searchURL - "dictionary.reference.com/search?r=67&q="
run BROWSER_EXE searchURL
----------------


And similarly, with an English thesaurus site —
----------------
str+ theSearchWords
str searchURL
str selectionText

selectionText.getsel
if( (selectionText.len != 0) && (selectionText.len < 40) )
,searchURL = selectionText
else
,inp-(theSearchWords, "Find a synonym for", "Thesaurus", theSearchWords)
,searchURL = theSearchWords
Substitute( &searchURL, "+", "%2B" )
searchURL.trim( )
searchURL - "thesaurus.reference.com/search?q="
run BROWSER_EXE searchURL
----------------


And lastly for something slightly different. This doesn’t look up information, but rather just opens the URL you have selected (or entered). It will automatically fill in “www.” and “.com” if you enter a single word.

Open URL
----------------
str+ theDirectURL
str theURL
str selectionText

selectionText.getsel
if( (selectionText.len != 0) && (selectionText.len < 250) )
,theURL = selectionText
else
,inp-( theDirectURL, "Connect to which site?", "Open URL", theDirectURL )
,theURL = theDirectURL
theURL.trim( )

if( findc( theURL, '.' ) == -1 )
,theURL - "www."
,theURL + ".com"

run BROWSER_EXE theURL
----------------

Enjoy!

PS: Edited to add automatic trimming of beginning and ending spaces, and to remove a small debugging command
PPS: Edited to remove the error-prone addition of “.com” to the end of URLs without a recognized ending, and replaced "iexplore.exe" with BROWSER_EXE for people using other browsers.
Lindsey
 
Posts: 19
Joined: Sat Mar 08, 2003 12:14 pm

Postby Gloobo on Sat Feb 18, 2006 7:16 am

you said in your post giving automatic qureys to Google? I was wondering isn't it against the Google TOS? Becasue I read it somewhere.
Gloobo
 

Postby ken gray on Mon Feb 20, 2006 1:16 pm

no, i think the API that they've released helps you do it.
User avatar
ken gray
Active Member
 
Posts: 1713
Joined: Wed Feb 19, 2003 4:27 pm
Location: Minnesota, USA


Return to QM Extensions

Who is online

Users browsing this forum: No registered users and 1 guest

cron