aa2zz6 Posted July 19, 2017 Share Posted July 19, 2017 (edited) Our operators are currently using app collector forms to store data. To increase productivity, I'm looking at using an online service that provides an api key for users, such as myself, to post app collector forms and be convert into text. This service would process the data much quicker than by typing each field by hand on ArcGIS Desktop 10.3.1, thus increasing productivity levels for our mapping department. The goal is to use the available service to migrate the data into a more suitable format that would allow us to send our forms to be processed, returned and ready for our mapping. I've included API key but I'm not familiar with implementing it. Currently, the website is requesting an API key, but I can't seem to implement it in the correct area for it to register. *The script doesn't include anywhere to send the files* I haven't gotten far enough or tested anything to include this.* $oMyError = ObjEvent('AutoIt.Error", "MyErrFunc') ; Install a custom error handler $link = 'https://api.ocr.space/parse/image' $api_key ='8f1e0a750088957' ;~ API Key ~; $oHTTP = ObjCreate('winhttp.winhttprequest.5.1') $oHTTP.Open ('POST', $link) $oHTTP.Send() If @error Then MsgBox(16, 'Error', '$oHTTP.Send() returned @error = ' & @error & ', and @extended = ' & @extended) Exit Else $HTMLSource = $oHTTP.Responsetext MsgBox(64, 'Results', $HTMLSource) EndIf Edited July 19, 2017 by aa2zz6 Link to comment Share on other sites More sharing options...
Danyfirex Posted July 19, 2017 Share Posted July 19, 2017 Hello here is a example using GET and POST methods. expandcollapse popupConsoleWrite(">GET METHOD USING IMAGE URL<" & @CRLF) _GetMethodTest() ConsoleWrite(">POST METHOD UPLOADING LOCAL IMAGE<" & @CRLF) _PostMethodTest() Func _PostMethodTest() Local Const $sAPIKey = '8f1e0a750088957' Local $sBoundary = "--------Boundary" Local $sHeaders = "Content-Type: multipart/form-data; boundary=" & $sBoundary & @CRLF Local $sData = '' Local $sFileName="OCR.png" Local $sFilePath=@ScriptDir & "\" & $sFileName Local $hFile=FileOpen($sFilePath,16);16=$FO_BINARY Local $sFileData=FileRead($hFile) FileClose($hFile) $sData &= "--" & $sBoundary & @CRLF $sData &= 'Content-Disposition: form-data; name="file"; filename="' & $sFileName & '"' & @CRLF $sData &= 'Content-Type: application/octet-stream' & @CRLF & @CRLF $sData &= BinaryToString($sFileData,0) & @CRLF $sData &= "--" & $sBoundary & @CRLF $sData &= 'Content-Disposition: form-data; name="language"' & @CRLF & @CRLF $sData &="eng" & @CRLF $sData &=$sBoundary & "--" Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", "https://api.ocr.space/Parse/Image", False) $oHTTP.SetRequestHeader("Content-Type", "multipart/form-data; " & "boundary=" & $sBoundary) $oHTTP.SetRequestHeader("apikey", $sAPIKey) $oHTTP.Send(StringToBinary($sData,1)) Local $sReceived = $oHTTP.ResponseText ConsoleWrite($sReceived & @CRLF) EndFunc ;==>_PostMethodTest Func _GetMethodTest() Local Const $sAPIKey = '8f1e0a750088957' Local $sReturn = InetRead('https://api.ocr.space/parse/imageurl?apikey=' & $sAPIKey & '&url=http://i.imgur.com/fwxooMv.png', 1) ;1=$INET_FORCERELOAD $sReturn = BinaryToString($sReturn) ConsoleWrite($sReturn & @CRLF) EndFunc ;==>_GetMethodTest Consider to use WinHTTP UDF Instead winhttp COM object. Saludos Skysnake 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
aa2zz6 Posted July 19, 2017 Author Share Posted July 19, 2017 (edited) @Danyfirex Thanks for the reply. I'm tried out the POST method function and I got this error: {"ParsedResults":[{"TextOverlay":{"Lines":[],"HasOverlay":false,"Message":"Text overlay is not provided as it is not requested"},"FileParseExitCode":1,"ParsedText":"","ErrorMessage":"","ErrorDetails":""}],"OCRExitCode":1,"IsErroredOnProcessing":false,"ErrorMessage":null,"ErrorDetails":null,"ProcessingTimeInMilliseconds":"1088"} Do we need to set the "isOverlayRequired=False" within a Content-Disposition for it to register false with the image? HasOverlay Overlay is present or not True/False depending upon if the overlay for the parsed result is present or not $sData &= 'Content-Disposition: form-data; name ="isOverlayRequired"' & @CRLF & @CRLF $sData &= "False" & @CRLF I tried including this but the error still occurs so I'm thinking the overlay isn't being applied correctly. Edited July 19, 2017 by aa2zz6 Link to comment Share on other sites More sharing options...
Danyfirex Posted July 20, 2017 Share Posted July 20, 2017 (edited) mmm I see. Edit: I think by default is false. But You could do it this way. change true to false. :-P expandcollapse popupConsoleWrite(">GET METHOD USING IMAGE URL<" & @CRLF) _GetMethodTest() ConsoleWrite(">POST METHOD UPLOADING LOCAL IMAGE<" & @CRLF) _PostMethodTest() Func _PostMethodTest() Local Const $sAPIKey = '8f1e0a750088957' Local $sBoundary = "--------Boundary" Local $sHeaders = "Content-Type: multipart/form-data; boundary=" & $sBoundary & @CRLF Local $sData = '' Local $sFileName = "OCR.png" Local $sFilePath = @ScriptDir & "\" & $sFileName Local $hFile = FileOpen($sFilePath, 16) ;16=$FO_BINARY Local $sFileData = FileRead($hFile) FileClose($hFile) $sData &= "--" & $sBoundary & @CRLF $sData &= 'Content-Disposition: form-data; name="file"; filename="' & $sFileName & '"' & @CRLF $sData &= 'Content-Type: application/octet-stream' & @CRLF & @CRLF $sData &= BinaryToString($sFileData, 0) & @CRLF $sData &= "--" & $sBoundary & @CRLF $sData &= 'Content-Disposition: form-data; name="language"' & @CRLF & @CRLF $sData &= "eng" & @CRLF $sData &= "--" & $sBoundary & @CRLF $sData &= 'Content-Disposition: form-data; name="isOverlayRequired"' & @CRLF & @CRLF $sData &= 'true' & @CRLF $sData &= "--" & $sBoundary & "--" & @CRLF Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", "https://api.ocr.space/Parse/Image", False) $oHTTP.SetRequestHeader("Content-Type", "multipart/form-data; " & "boundary=" & $sBoundary) $oHTTP.SetRequestHeader("apikey", $sAPIKey) $oHTTP.Send(StringToBinary($sData, 1)) Local $sReceived = $oHTTP.ResponseText ConsoleWrite($sReceived & @CRLF) EndFunc ;==>_PostMethodTest Func _GetMethodTest() Local Const $sAPIKey = '8f1e0a750088957' Local $sReturn = InetRead('https://api.ocr.space/parse/imageurl?apikey=' & $sAPIKey & '&isOverlayRequired=true&url=http://i.imgur.com/fwxooMv.png', 1) ;1=$INET_FORCERELOAD $sReturn = BinaryToString($sReturn) ConsoleWrite($sReturn & @CRLF) EndFunc ;==>_GetMethodTest Saludos Edited July 20, 2017 by Danyfirex aa2zz6 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
aa2zz6 Posted July 20, 2017 Author Share Posted July 20, 2017 (edited) @Danyfirex - Thanks, it's working correctly. Edited July 20, 2017 by aa2zz6 Link to comment Share on other sites More sharing options...
artepad Posted September 10, 2017 Share Posted September 10, 2017 Hello, I'm using your example but I do not understand those lines of code! and also gives me an error how good that if it works and between the error gets the information of the image $sData &= "--" & $sBoundary & @CRLF $sData &= 'Content-Disposition: form-data; name="file"; filename="' & $sFileName & '"' & @CRLF $sData &= 'Content-Type: application/octet-stream' & @CRLF & @CRLF $sData &= BinaryToString($sFileData, 0) & @CRLF $sData &= "--" & $sBoundary & @CRLF $sData &= 'Content-Disposition: form-data; name="language"' & @CRLF & @CRLF $sData &= "eng" & @CRLF $sData &= "--" & $sBoundary & @CRLF $sData &= 'Content-Disposition: form-data; name="isOverlayRequired"' & @CRLF & @CRLF $sData &= 'true' & @CRLF $sData &= "--" & $sBoundary & "--" & @CRLF Imagen: Error: Link to comment Share on other sites More sharing options...
Danyfirex Posted September 11, 2017 Share Posted September 11, 2017 @artepad There is no error in your response. You also could set isOverlayRequired to false to get just the ParsedText without the TextOverlay information. You can use some Json UDF to parse the response or just use some string manipulation. Saludos artepad 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
artepad Posted September 11, 2017 Share Posted September 11, 2017 I understand, compile the script with isOverlayRequired false and the string is a little shorter but there is no way I can do that only the number I have to occupy a substring StringMid example to format? I'm sorry, I'm very new to Autoit Link to comment Share on other sites More sharing options...
mikell Posted September 11, 2017 Share Posted September 11, 2017 This returns an array with the numbers inside $array = StringRegExp($response, '(\d{3}\.\d{3})', 3) artepad 1 Link to comment Share on other sites More sharing options...
artepad Posted September 11, 2017 Share Posted September 11, 2017 I am amazed how easy it was. Thank you very much! Link to comment Share on other sites More sharing options...
Danyfirex Posted September 11, 2017 Share Posted September 11, 2017 thank you too Danyfirex Saludos artepad 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
artepad Posted September 11, 2017 Share Posted September 11, 2017 1 hour ago, Danyfirex said: thank you too Danyfirex Saludos Jajaja muchas gracias para ti también Danyfirex por ser el primero quien me ayudo Saludos! Danyfirex 1 Link to comment Share on other sites More sharing options...
artepad Posted September 13, 2017 Share Posted September 13, 2017 Hi, it's me again, I have a problem with that line of code only accepts number in "100 thousand" unit but when I have "10 thousand" the image will have a number from 0 to 100 thousand Quote $array = StringRegExp($response, '(\d{3}\.\d{3})', 3) Example [/url] I'm trying to understand how StringRegExp works on my part Link to comment Share on other sites More sharing options...
Danyfirex Posted September 13, 2017 Share Posted September 13, 2017 Read the help file. Saludos artepad 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
mikell Posted September 13, 2017 Share Posted September 13, 2017 Ohhh Danyfirex Last gift $array = StringRegExp($response, '(\d+\.\d+)', 3) But reading the helpfile is not such a bad idea Danyfirex and artepad 2 Link to comment Share on other sites More sharing options...
artepad Posted September 13, 2017 Share Posted September 13, 2017 3 hours ago, mikell said: Ohhh Danyfirex Last gift $array = StringRegExp($response, '(\d+\.\d+)', 3) But reading the helpfile is not such a bad idea I did not work but thanks for the help and sorry for bothering I will try to learn only with the help Link to comment Share on other sites More sharing options...
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