AutoHotkey Community

It is currently May 27th, 2012, 1:21 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: August 15th, 2008, 4:22 am 
Offline

Joined: March 11th, 2008, 11:36 pm
Posts: 291
Returns first definition of the queried term. you need httpQuery() installed in stdlib
Press Win+U then type the word to look up
quite simple, isn't? :D

Code:
#u:: ;Set Hotkey, change to other in case of you're using windows utility manager
Gui, Margin, 0, 0
Gui, -Caption +ToolWindow +AlwaysOnTop
Gui, Add, Edit, +0x1 w150 vWord
Gui, Add, Button, Default gGo
Gui, Show, h20
Return

Go:
Gui, Submit
Gui, Destroy
httpquery(r, "http://www.urbandictionary.com/define.php?term=" . word) ;get html
VarSetCapacity(r, -1)
RegExMatch(r,"<div class='definition'>(.+?)</div>", out) ;parsing
out1 := RegExReplace(out1, "(<.+?>|\n)") ;remove non-strings
DecodeHtmlChars(out1)
TrayTip,,%out1%
Return

DecodeHtmlChars(ByRef outStr) ;by nnesori
{       
  StringReplace, outStr, outStr, &quot; , " , 1
  StringReplace, outStr, outStr, &nbsp; , %A_Space% , 1
  StringReplace, outStr, outStr, &gt; , > , 1
  StringReplace, outStr, outStr, &lt; , < , 1
  StringReplace, outStr, outStr, &amp; , & , 1
  StringReplace, outStr, outStr, #39; , ', 1
}

_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2008, 6:33 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Good work. Here's a PHP version I wrote for something I needed:

Code:
function udict($term) {
   $ch = curl_init('http://www.urbandictionary.com/define.php?term=' . urlencode($term));
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_USERAGENT, UA_DEB);
   $d = curl_exec($ch);
   curl_close($ch);
   
   $p = '<div class=\'definition\'>';
   $ps = strpos($d, $p);
   if (!$ps) return false;
   $p = $ps + strlen($p);
   $d = trim(substr($d, $p, strpos($d, '</div>') - $p));
   $d = str_replace('<br/>', "\n", $d);
   $d = preg_replace('/<[^>]*?>/', '', $d);
   $ps = strpos($d, "\n");
   if ($ps !== false) $d = substr($d, 0, $ps - 1);
   return htmlspecialchars_decode($d, ENT_QUOTES);
}

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group