In this video I walk through how to use my AutoHotkey API Syntax Writer. If you’re new to APIs, be sure to check out our Webinar on API / Web Services or this page for a lot of examples of connecting to API services.
Please remember that, after launching the script, you’ll need to hold down the control key and left mouse-click to activate the menu options.
Here is the video walking through how to use the tool.
I made a few updates to my Web Scraping syntax writer. This new version adds in functionality to Get/Set attributes of an element as well easily find all tables on a given page, then extract the text and dump it into a dynamic Listview.
Both can be pretty helpful when scraping data from the web. For an extensive review of the tool, checkout the videos on my main Web Scraping page.
Demonstration of updated Web Scraping syntax writer
Often I have a list of hundreds (sometimes thousands) of items that I need to insert into a query. Unfortunately I can only add 99 items at a time.
This video demonstrates how my scriptreplaces the first 98 line breaks with commas and wrap items already having a comma with special characters to escape them. This is perfect for my SQL in list query! What would have taken me several minutes or longer is now done in the blink of an eye (while also escaping illegal characters). The below video demonstrates it’s usage and further down the page is the AutoHotkey code that cranks it out!
Video demonstrating how the SQL in list works
AutoHotkey code:
;***********save clipboard to retore later*******************
Store:=ClipboardAll ;Store full version of Clipboard
clipboard = ; Empty the clipboard
SendInput, ^c ;changd from Send 11/23
ClipWait, 1
If ErrorLevel ;Added errorLevel checking
{
MsgBox, No text was sent to clipboard
Return
}
;***********remove blank lines*******************
Loop,parse,Clipboard,`n`r ;loops through lines
{
New:=RegExReplace(A_LoopField,"^\s?$","") ;if line only has white space
If (new!="")
NewText.=new "`r`n"
}
Clipboard:=NewText
NewText:=""
;***********clean up the text*******************
Trimmed:=RegExReplace(clipboard, "m)^\s?(.*)\s?$","$1") ;trim spaces from both sides
;***********************wrap special characthers********************************.
StringReplace, Trimmed, Trimmed, &, '||'&'||',All ;wrap commas
StringReplace, Trimmed, Trimmed, ', '',All ; double up ' so it escapes it
;***********************Create groups of 999********************************.
Loop,
{
NewStr := RegExReplace(Trimmed, "`r`n", "','",1,998,1) ;998 is max
AddBreak := RegExReplace(NewStr, "`r`n", "`n`r*****************" . (A_Index*1000)+1 . "*****************`r",1,1,1)
If (AddBreak=NewStr) ;check to see if done looping through all items
break
Trimmed:=AddBreak ;
}
Clipboard := RegExReplace(NewStr, "','$", "") ; Delete ending ','
;***********restore clipboard*******************
SendEvent , ^v
Sleep, 50
Clipboard:=Store
;***********wipe out vars of SQL in list*******************
New:="" , newstr:="" , newText:="" , Trimmed:="" , Addbreak:="" ; Empty vars
return
While fun, writing code can be very tedious in that it needs to be in a specific format. I use hotstrings to replace words I frequently use but what I also realized is I often have to put parameters into specific format like a quote encapsulated/comma delimited list.
This video shows how I wrote some very simple code that makes it much easier for me to be more productive in my SQL code writing. I have other syntax writers for other languages but the concept stays the same.