Last active
April 26, 2021 15:39
-
-
Save JoeGlines/b0db693ce27707ef1768bb09480f2d9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;******************************************************* | |
; Want a clear path for learning AutoHotkey; Take a look at our AutoHotkey Udemy courses. They're structured in a way to make learning AHK EASY | |
; Right now you can get a coupon code here: https://the-Automator.com/Learn | |
;******************************************************* | |
Endpoint:="https://www.opensymbols.org/api/v1/symbols/search" ; Set endpoint outside of the loop as it doesn't change | |
obj:=ImageGetUrl(Endpoint,QueryString_Builder({"q":"taco"})) | |
for k, v in obj | |
images.= v.image_URL "`n" ;get a list of all image URLs | |
Resizable_GUI(images,900,500) | |
return | |
ImageGetUrl(Endpoint,QS){ | |
HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1") ;Create COM lObject | |
HTTP.Open("GET", Endpoint QS) | |
HTTP.Send() | |
oAHK:=ParseJSON(HTTP.ResponseText) ;Make sure the ParseJSON function is in your library | |
DebugWindow(Obj2String(oAHK),1,1,200,0) | |
return oAHK | |
} | |
QueryString_Builder(x){ | |
for a,b in x | |
String.=(A_Index=1?"?":"&") a "=" b | |
return String | |
} | |
Resizable_GUI(Data,x=900,y=600){ | |
static EditWindow | |
Gui,12:Destroy | |
Gui,12:Default | |
Gui,+Resize | |
Gui,Font,s12 cBlue q5, Courier New | |
Gui,Add,Edit,w%x% h%y% -Wrap HScroll hwndEditWindow, %Data% | |
Gui,Show | |
return | |
12GuiEscape: | |
12GuiClose: | |
Gui,12:Destroy | |
return | |
12GuiSize: | |
GuiControl,12:Move,%EditWindow%,% "w" A_GuiWidth-30 " h" A_GuiHeight-25 | |
return | |
} | |
ParseJSON(jsonStr){ | |
static SC:=ComObjCreate("ScriptControl"),C:=Chr(125) | |
SC.Language:="JScript",ComObjError(0),SC.ExecuteStatement("function arrangeForAhkTraversing(obj){if(obj instanceof Array){for(var i=0; i<obj.length; ++i)obj[i]=arrangeForAhkTraversing(obj[i]);return ['array',obj];" C "else if(obj instanceof Object){var keys=[],values=[];for(var key in obj){keys.push(key);values.push(arrangeForAhkTraversing(obj[key]));" C "return ['object',[keys,values]];" C "else return [typeof obj,obj];" C ";obj=" jsonStr) | |
return convertJScriptObjToAhks(SC.Eval("arrangeForAhkTraversing(obj)")) | |
}ConvertJScriptObjToAhks(JSObj){ | |
if(JSObj[0]="Object"){ | |
Obj:=[],Keys:=JSObj[1][0],Values:=JSObj[1][1] | |
while(A_Index<=Keys.length) | |
Obj[Keys[A_Index-1]]:=ConvertJScriptObjToAhks(Values[A_Index-1]) | |
return Obj | |
}else if(JSObj[0]="Array"){ | |
Array:=[] | |
while(A_Index<=JSObj[1].length) | |
Array.Push(ConvertJScriptObjToAhks(JSObj[1][A_Index-1])) | |
return Array | |
}else | |
return JSObj[1] | |
} | |
#Include XHR.AHK | |
Obj2String(Obj,FullPath:=1,BottomBlank:=0){ | |
static String,Blank | |
if(FullPath=1) | |
String:=FullPath:=Blank:="" | |
if(IsObject(Obj)&&!Obj.XML){ | |
for a,b in Obj{ | |
if(IsObject(b)&&b.OuterHtml) | |
String.=FullPath "." a " = " b.OuterHtml | |
else if(IsObject(b)&&!b.XML) | |
Obj2String(b,FullPath "." a,BottomBlank) | |
else{ | |
if(BottomBlank=0) | |
String.=FullPath "." a " = " (b.XML?b.XML:b) "`n" | |
else if(b!="") | |
String.=FullPath "." a " = " (b.XML?b.XML:b) "`n" | |
else | |
Blank.=FullPath "." a " =`n" | |
} | |
} | |
}else if(Obj.XML) | |
String.=FullPath Obj.XML "`n" | |
return String Blank | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment