Jump to content

dragan

Active Members
  • Posts

    180
  • Joined

  • Last visited

  • Days Won

    2

dragan last won the day on August 25 2013

dragan had the most liked content!

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

dragan's Achievements

  1. Has anyone tried to use Google APIs for scraping search results? I've built this simple script to demonstrate my problem I'm having with Google results scraping: #include <Array.au3> Global $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") _PerformSearch(); Func _PerformSearch() dim $ShowResults[0][3]; $searchPages = 3 for $j = 1 to $searchPages*8 Step 8 $SearchString = 'Apple+Juice'; Disable this line... ;~ $SearchString = 'intitle:"crazy+stink"'; ...And enable this one ;http://ajax.googleapis.com/ajax/services/search/web?v=1.0&start=1&rsz=large&q=intitle:%22crazy+stink%22 $sURL = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&start=" & $j & "&rsz=large&q=" & $SearchString $oHTTP.Open("GET", $sURL, False) $oHTTP.SetRequestHeader("Referer", @IPAddress1) If (@error) Then Return SetError(1, 0, 0) $oHTTP.Send() If (@error) Then Return SetError(2, 0, 0) $retVal = $oHTTP.ResponseText If (@error) Then Return SetError(3, 0, 0) $aReturn = _JSON_Decode($retVal) if NOT @error then $responseData = $aReturn[0][1] $results = $responseData[0][1] for $i = 0 to UBound($results)-1 $oneResult = $results[$i] $title = _OnlyBoldedDecode(_getJSonValue($oneResult, "title")) $url = _getJSonValue($oneResult, "url") $content = _OnlyBoldedDecode(_getJSonValue($oneResult, "content")) ReDim $ShowResults[UBound($ShowResults)+1][3] $arIndex = UBound($ShowResults)-1 $ShowResults[$arIndex][0] = $title $ShowResults[$arIndex][1] = $url $ShowResults[$arIndex][2] = $content Next EndIf Next _ArrayDisplay($ShowResults); EndFunc Func _OnlyBoldedDecode($sData);decoding only most common code Return StringReplace(StringReplace($sData, "\u003c", "<"), "\u003e", ">"); EndFunc Func _getJSonValue($_res, $getData) for $i = 0 to UBound($_res)-1 if $_res[$i][0] == $getData then Return $_res[$i][1] Next Return ""; EndFunc Func _JSON_Decode($sString) Local $iIndex, $aVal, $sOldStr = $sString, $b $sString = StringStripCR(StringStripWS($sString, 7)) If Not StringRegExp($sString, "(?i)^\{.+}$") Then Return SetError(1, 0, 0) Local $aArray[1][2], $iIndex = 0 $sString = StringMid($sString, 2) Do $b = False $aVal = StringRegExp($sString, '^"([^"]+)"\s*:\s*(["{[]|[-+]?\d+(?:(?:\.\d+)?[eE][+-]\d+)?|true|false|null)', 2) ; Get value & next token If @error Then ConsoleWrite("!> StringRegExp Error getting next Value." & @CRLF) ConsoleWrite($sString & @CRLF) $sString = StringMid($sString, 2) ; maybe it works when the string is trimmed by 1 char from the left ? ContinueLoop EndIf $aArray[$iIndex][0] = $aVal[1] ; Key $sString = StringMid($sString, StringLen($aVal[0])) Switch $aVal[2] ; Value Type (Array, Object, String) ? Case '"' ; String ; Value -> Array subscript. Trim String after that. $aArray[$iIndex][1] = StringMid($sString, 2, StringInStr($sString, """", 1, 2) - 2) $sString = StringMid($sString, StringLen($aArray[$iIndex][1]) + 3) ReDim $aArray[$iIndex + 2][2] $iIndex += 1 Case '{' ; Object ; Recursive function call which will decode the object and return it. ; Object -> Array subscript. Trim String after that. $aArray[$iIndex][1] = _JSON_Decode($sString) $sString = StringMid($sString, @extended + 2) If StringLeft($sString, 1) = "," Then $sString = StringMid($sString, 2) $b = True ReDim $aArray[$iIndex + 2][2] $iIndex += 1 Case '[' ; Array ; Decode Array $sString = StringMid($sString, 2) Local $aRet[1], $iArIndex = 0 ; create new array which will contain the Json-Array. Do $sString = StringStripWS($sString, 3) ; Trim Leading & trailing spaces $aNextArrayVal = StringRegExp($sString, '^\s*(["{[]|\d+(?:(?:\.\d+)?[eE]\+\d+)?|true|false|null)', 2) if @error Then Return SetError(@error, 0, 0); Switch $aNextArrayVal[1] Case '"' ; String ; Value -> Array subscript. Trim String after that. $aRet[$iArIndex] = StringMid($sString, 2, StringInStr($sString, """", 1, 2) - 2) $sString = StringMid($sString, StringLen($aRet[$iArIndex]) + 3) Case "{" ; Object ; Recursive function call which will decode the object and return it. ; Object -> Array subscript. Trim String after that. $aRet[$iArIndex] = _JSON_Decode($sString) $sString = StringMid($sString, @extended + 2) Case "[" MsgBox(0, "", "Array in Array. WTF is up with this JSON shit?") MsgBox(0, "", "This should not happen! Please post this!") Exit 0xDEADBEEF Case Else ConsoleWrite("Array Else (maybe buggy?)" & @CRLF) $aRet[$iArIndex] = $aNextArrayVal[1] EndSwitch ReDim $aRet[$iArIndex + 2] $iArIndex += 1 $sString = StringStripWS($sString, 3) ; Leading & trailing If StringLeft($sString, 1) = "]" Then ExitLoop $sString = StringMid($sString, 2) Until False $sString = StringMid($sString, 2) ReDim $aRet[$iArIndex] $aArray[$iIndex][1] = $aRet ReDim $aArray[$iIndex + 2][2] $iIndex += 1 Case Else ; Number, bool ; Value (number (int/flaot), boolean, null) -> Array subscript. Trim String after that. $aArray[$iIndex][1] = $aVal[2] ReDim $aArray[$iIndex + 2][2] $iIndex += 1 $sString = StringMid($sString, StringLen($aArray[$iIndex][1]) + 2) EndSwitch If StringLeft($sString, 1) = "}" Then StringMid($sString, 2) ExitLoop EndIf If Not $b Then $sString = StringMid($sString, 2) Until False ReDim $aArray[$iIndex][2] Return SetError(0, StringLen($sOldStr) - StringLen($sString), $aArray) EndFunc ;==>_JSON_Decode This works as long as you're not using "intelligent search placeholders" like using "intitle", "inurl", "site", and other placeholders with sentences (single word works, like: intitle:cake, but with sentence like: intitle:"crazy+stink" it doesn't, while searching this on google will give you approx. 35 results: https://www.google.com/search?q=intitle:"crazy+stink" ) Has anyone found a better way to legally scrape Google? This JSON API was built to be free, without big limitations (max results you get from a single query is 64), but it's not working properly, it doesn't give me results on "intelligent search placeholders". I'm aware of the Google Custom Search API, which requires API Key (which I have) but this API can search only specific website, and I need to scrape results from Google's search results. Any thoughts, suggestions, ideas? Edit: July 4th 2014: I have found a way how to use Google Custom Search API with API Key, and still search entire web (instead of only single page). I have found this: https://support.google.com/customsearch/answer/2631040?hl=en and I have followed the instructions. I got my CX code, and I formatted the URL: https://www.googleapis.com/customsearch/v1?key=[MY_API_KEY]&cx=017576662512468239146:omuauf_lfve&q=intitle:%22crazy+stink%22 (the CX in this example is the one that Google provides as an example for the API here: https://developers.google.com/custom-search/json-api/v1/using_rest, however, even with my own CX I get the same results) Here are the results: { "kind": "customsearch#search", "url": { "type": "application/json", "template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json" }, "queries": { "request": [ { "title": "Google Custom Search - intitle:\"crazy stink\"", "totalResults": "0", "searchTerms": "intitle:\"crazy stink\"", "count": 10, "inputEncoding": "utf8", "outputEncoding": "utf8", "safe": "off", "cx": "017576662512468239146:omuauf_lfve" } ] }, "searchInformation": { "searchTime": 0.35068, "formattedSearchTime": "0.35", "totalResults": "0", "formattedTotalResults": "0" } } The results are almost the same as I get them from AJAX JSON Api http://ajax.googleapis.com/ajax/services/search/web?v=1.0&start=1&rsz=large&q=intitle:%22crazy+stink%22: {"responseData": {"results":[],"cursor":{"moreResultsUrl":"http://www.google.com/search?oe\u003dutf8\u0026ie\u003dutf8\u0026source\u003duds\u0026start\u003d1\u0026hl\u003den\u0026q\u003dintitle:%22crazy+stink%22","searchResultTime":"0.10"}}, "responseDetails": null, "responseStatus": 200} Which is 0. So... maybe there isn't any error on my part, but there is on Google's? I'm just curious if anyone encountered an issue like the one I have, or if anyone have any better suggestion, but bare in mind that I want to keep this legal (scraping results from IE object is not something I want to do).
  2. Why not just running it yourself, and then visiting your IP in your web browser, you'll be able to see it in practice.
  3. Check this out: '?do=embed' frameborder='0' data-embedContent>> So you could modify the HTML you're posting back, or you could just post back textual information.
  4. Have you considered registering WM_COMMAND from your GUI? Then you would monitor the "button has been clicked" event from your GUI, instead of monitoring for clicks in your main loop. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiMenu.au3> #include <WinAPI.au3> $Form1 = GUICreate("main form", 250, 240) $Button1 = GUICtrlCreateButton("Click me", 15, 15, 100, 25) $Button2 = GUICtrlCreateButton("Click me #2", 15, 45, 100, 25) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND") ConsoleWrite("!-----------------------------------" & @CRLF & @CRLF & "-> "); While 1 ;main loop Sleep(250); ConsoleWrite("|") WEnd Func WM_SYSCOMMAND($hWnd, $iMsg, $WParam, $LParam) Switch $hWnd Case $Form1 Switch $WParam Case $SC_CLOSE ;X (close) button in the GUI form Exit EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $nID = BitAND($iwParam, 0x0000FFFF) $iCode = _WinAPI_HiWord($iwParam) ;how to detect GUI control clicks: Switch $nID Case $Button1 ConsoleWrite(@CRLF & "+> Button 1 clicked!" & @CRLF & "-> ") Case $Button2 ConsoleWrite(@CRLF & ">> Button 2 clicked!" & @CRLF & "-> ") EndSwitch Return $GUI_RUNDEFMSG EndFunc
  5. This could be interesting: ;declare main array that will hold your values: dim $mainArray[20] ;set 20 different data on each element of the array (you'll have 20) $mainArray[0] = _CreateNewObject(1, 0, 1);250 $mainArray[1] = _CreateNewObject(0, 1, 1);500 $mainArray[2] = _CreateNewObject(0, 1, 0);750 $mainArray[3] = _CreateNewObject(0, 1, 0);1000 $mainArray[4] = _CreateNewObject(0, 1, 0);etc... $mainArray[5] = _CreateNewObject(0, 1, 0) $mainArray[6] = _CreateNewObject(0, 1, 0) $mainArray[7] = _CreateNewObject(0, 1, 0) $mainArray[8] = _CreateNewObject(0, 1, 0) $mainArray[9] = _CreateNewObject(0, 1, 0) $mainArray[10] = _CreateNewObject(0, 1, 0) $mainArray[11] = _CreateNewObject(0, 1, 0) $mainArray[12] = _CreateNewObject(0, 1, 0) $mainArray[13] = _CreateNewObject(0, 1, 0) $mainArray[14] = _CreateNewObject(0, 1, 0) $mainArray[15] = _CreateNewObject(0, 1, 0) $mainArray[16] = _CreateNewObject(0, 1, 0) $mainArray[17] = _CreateNewObject(0, 1, 0) $mainArray[18] = _CreateNewObject(0, 1, 0) $mainArray[19] = _CreateNewObject(0, 1, 0) ;----------------------------------------------------------- ;how to pull data out of this? $randNumber = Random(250, 5000, 1) $div = Round($randNumber / 250, 0) - 1; ConsoleWrite("!!!--------------------------------" & @CRLF & ">> Our number is: " & $randNumber & " (div is: " & $div & ", for var " & ($div+1)*250 & ")" & @CRLF & @CRLF) $readData = _ReadObject($mainArray[$div]); ConsoleWrite("!> RED: " & @TAB & $readData[0] & @CRLF) ConsoleWrite(".> BLACK: " & @TAB & $readData[1] & @CRLF) ConsoleWrite("-> YELLOW: " & @TAB & $readData[2] & @CRLF) ;----------------------------------------------------------- ;Release the resources used by the structure. _ClearArray($mainArray) ;================================================================================ Func _ReadObject($tSTRUCT1) Local $_red = DllStructGetData($tSTRUCT1, "red") Local $_black = DllStructGetData($tSTRUCT1, "black") Local $_yellow = DllStructGetData($tSTRUCT1, "yellow") dim $retArray[3] = [$_red, $_black, $_yellow] Return $retArray; EndFunc Func _CreateNewObject($_red, $_black, $_yellow) Local Const $tagSTRUCT1 = "struct;int red;int black;int yellow;endstruct" Local $tSTRUCT1 = DllStructCreate($tagSTRUCT1) DllStructSetData($tSTRUCT1, "red", $_red) DllStructSetData($tSTRUCT1, "black", $_black) DllStructSetData($tSTRUCT1, "yellow", $_yellow) Return $tSTRUCT1 EndFunc Func _ClearArray(ByRef $_array) if (UBound($_array) <= 0) Then Return For $singleStruct in $_array $singleStruct = 0 Next ReDim $_array[0] EndFunc
  6. If you still want to use the IE objects, you could: #include <IE.au3> $sXML = '<availability>' & @crlf & _ '<members date="2014-06-6" count="2" day="2" night="1" OOA="0" na="0" />' & @crlf & _ '<members date="2014-06-7" count="6" day="5" night="1" OOA="0" na="0" />' & @crlf & _ '<members date="2014-06-8" count="8" day="4" night="1" OOA="0" na="0" />' & @crlf & _ '<members date="2014-06-9" count="9" day="9" night="1" OOA="0" na="0" />' & @crlf & _ '</availability>' $oIE = _IECreate("about:blank", 0, 0) _IEBodyWriteHTML($oIE, $sXML) Local $Availability = _IETagNameGetCollection($oIE, 'availability', 0) if IsObj($Availability) Then Local $members = _IETagNameGetCollection($Availability, "members") if IsObj($members) Then ConsoleWrite("----------------" & @CRLF) for $member in $members ConsoleWrite(">> date: " & $member.getAttribute("date") & @CRLF) ConsoleWrite(">> count: " & $member.getAttribute("count") & @CRLF) ConsoleWrite(">> day: " & $member.getAttribute("day") & @CRLF) ConsoleWrite(">> night: " & $member.getAttribute("night") & @CRLF) ConsoleWrite(">> OOA: " & $member.getAttribute("OOA") & @CRLF) ConsoleWrite(">> na: " & $member.getAttribute("na") & @CRLF) ConsoleWrite("----------------" & @CRLF) Next EndIf EndIf _IEQuit($oIE) or to get only today's "day": #include <IE.au3> $sXML = '<availability>' & @crlf & _ '<members date="2014-06-6" count="2" day="2" night="1" OOA="0" na="0" />' & @crlf & _ '<members date="2014-06-7" count="6" day="5" night="1" OOA="0" na="0" />' & @crlf & _ '<members date="2014-06-8" count="8" day="4" night="1" OOA="0" na="0" />' & @crlf & _ '<members date="2014-06-9" count="9" day="9" night="1" OOA="0" na="0" />' & @crlf & _ '</availability>' $oIE = _IECreate("about:blank", 0, 0) _IEBodyWriteHTML($oIE, $sXML) Local $Availability = _IETagNameGetCollection($oIE, 'availability', 0) if IsObj($Availability) Then Local $members = _IETagNameGetCollection($Availability, "members") if IsObj($members) Then ConsoleWrite("-------------------" & @CRLF) for $member in $members $splDate = StringSplit($member.getAttribute("date"), "-") if ($splDate[0] >= 3) Then if (Number($splDate[1]) = @YEAR AND Number($splDate[2]) = @MON AND Number($splDate[3]) = @MDAY) Then ConsoleWrite('>> today''s "day" is: ' & $member.getAttribute("day") & @CRLF) ExitLoop EndIf EndIf Next EndIf EndIf _IEQuit($oIE) However, I would advise you to use xmldom like jdelaney suggested.
  7. Personally, I would have done it like this: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiMenu.au3> #include <WinAPI.au3> Global $Counter = 0; Global $isCounting = False; Global $WaitExcel = False; Global $WaitExcelTimeOut = 0; Global $ExcelTimeNow = null; $Form1 = GUICreate("Count 1 to 100", 250, 240) $Button1 = GUICtrlCreateButton("Start", 15, 15, 75, 25) $Label1 = GUICtrlCreateLabel("0", 135, 16, 40, 17) $Button2 = GUICtrlCreateButton("Stop", 15, 55, 75, 25) $Button3 = GUICtrlCreateButton("Reset", 15, 95, 75, 25) $Button4 = GUICtrlCreateButton("Start Excel", 15, 155, 75, 25) $Button5 = GUICtrlCreateButton("Stop waiting Excel", 15, 195, 100, 25) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND") While 1 Sleep(10); ;----- loop that can be broken: ---------- if ($isCounting AND $Counter < 100) Then While $Counter < 100 AND $isCounting $Counter += 1 GUICtrlSetData($Label1, $Counter) Sleep(100) WEnd $isCounting = False; EndIf ;----------------------------------------- ;----------------------------------------- if ($WaitExcel) Then While 1 if WinExists("Microsoft Excel", "") Then MsgBox(0, "Success", "Excel is up and running!") ExitLoop EndIf if NOT $WaitExcel Then MsgBox(0, "Canceled", "You are no longer waiting for excel!") ExitLoop EndIf if $ExcelTimeNow <> null AND $WaitExcelTimeOut > 0 Then if (TimerDiff($ExcelTimeNow) >= $WaitExcelTimeOut*1000) then MsgBox(0, "Timed out", "You are no longer waiting for excel!" & @CRLF & "Timed out.") ExitLoop EndIf EndIf Sleep(10); WEnd $WaitExcel = False; EndIf ;----------------------------------------- WEnd Func WM_SYSCOMMAND($hWnd, $iMsg, $WParam, $LParam) Switch $hWnd Case $Form1 Switch $WParam Case $SC_CLOSE ;X button in the GUI form Exit; EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) Local $nID = BitAND($iwParam, 0x0000FFFF) #forceref $hWnd, $iMsg, $iwParam, $ilParam $iCode = _WinAPI_HiWord($iwParam) Switch $nID Case $Button1 $isCounting = True; Case $Button2 $isCounting = False; Case $Button3 $Counter = 0; GUICtrlSetData($Label1, $Counter) Case $Button4 $WaitExcelTimeOut = 30; wait for 30 seconds. $ExcelTimeNow = TimerInit(); ShellExecute("excel.exe"); $WaitExcel = True; Case $Button5 $WaitExcel = False; EndSwitch Return $GUI_RUNDEFMSG EndFunc
  8. How about setting the target attribute: $oObject.setAttribute("target") = "_blank"; $oObject is the link object ;now you can "click" the link, and it will be opened in a new window.
  9. I feel generous today... #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> #include <GuiMenu.au3> #include <IE.au3> Global const $twitchURL = "http://www.twitch.tv/" Global $twitch_ID = "snejkipl"; Global $isVisible = 1; Global $fullUrl = $twitchURL & $twitch_ID Global $LastMessage = "" Global $width = 800, $height = 600 Global $Form1 = GUICreate("Twitch Chat details for: " & $twitch_ID, $width, $height) Global $hRichEdit = _GUICtrlRichEdit_Create($Form1, "", 0, 0, $width, $height, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) GUISetState(@SW_SHOW) AppedSystemMessage("Please wait while I start IE..." & @CRLF) Global $oIE = _IECreate("about:blank", 0, $isVisible); GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") _GUICtrlRichEdit_SetEventMask($hRichEdit, $ENM_LINK) _GUICtrlRichEdit_AutoDetectURL($hRichEdit, True) AppedSystemMessage("Please wait while I load up: " & $fullUrl & @CRLF) _IENavigate($oIE, $fullUrl); AppedSystemMessage("Please wait while the chat loads up..." & @CRLF) While 1 Sleep(100) _CheckForMessages() WEnd Func _CheckForMessages() If NOT IsObj($oIE) Then Return $chatObject = _IEGetObjById($oIE, "chat") If NOT IsObj($chatObject) Then Return $divsInChat = _IETagNameGetCollection($chatObject, "div") if IsObj($divsInChat) Then $addMessages = False for $oneDivInChat in $divsInChat if StringInStr($oneDivInChat.classname, "ember-view chat-line") Then $allSpans = _IETagNameGetCollection($oneDivInChat, "span") if IsObj($allSpans) Then $curMessage = ""; $stringColor = "0x00000000"; for $oneSpan in $allSpans Switch $oneSpan.classname case "timestamp" $curMessage &= "<" & $oneSpan.innertext & "> " case "from" if ($oneSpan.innertext = "jtv") Then $stringColor = "0x00C3C3C3" Else $curMessage &= $oneSpan.innertext & ": " $pulledColor = StringReplace(StringReplace($oneSpan.style.getAttribute('color'), "rgb(", ""), ")", ""); $splitCol = StringSplit($pulledColor, ',') if ($splitCol[0] >= 3) Then $stringColor = "0x00" & Hex(Number(StringStripWS($splitCol[3], 3)), 2) & Hex(Number(StringStripWS($splitCol[2], 3)), 2) & Hex(Number(StringStripWS($splitCol[1], 3)), 2) EndIf case "message" if (StringLen(StringStripWS($oneSpan.innertext, 3)) > 0) AND (String($oneSpan.innertext) <> "0") Then $curMessage &= $oneSpan.innertext $allSpans2 = _IETagNameGetCollection($oneSpan, "span") if IsObj($allSpans2) Then for $oneSpan2 in $allSpans2 if StringInStr($oneSpan2.classname, "emoticon") Then $curMessage &= "[" & StringReplace($oneSpan2.classname, "emoticon ", "") & "]" Next EndIf EndSwitch Next if (StringLen($LastMessage) = 0 OR $addMessages) Then AppendUserMessage($curMessage & @CRLF, $stringColor) $LastMessage = $curMessage Else if $LastMessage = $curMessage then $addMessages = True EndIf EndIf EndIf Next EndIf EndFunc func AppendUserMessage($sText, $iColor) _GUICtrlRichEdit_AppendTextColor($hRichEdit, $sText, $iColor) EndFunc Func AppedSystemMessage($sText) _GUICtrlRichEdit_AppendTextColor($hRichEdit, $sText, 0x00C3C3C3) EndFunc Func _GUICtrlRichEdit_AppendTextColor($hWnd, $sText, $iColor) Local $iLength = _GUICtrlRichEdit_GetTextLength($hWnd, True, True) Local $iCp = _GUICtrlRichEdit_GetCharPosOfNextWord($hWnd, $iLength) _GUICtrlRichEdit_AppendText($hWnd, $sText) _GUICtrlRichEdit_SetSel($hWnd, $iCp-1, $iLength + StringLen($sText)) _GUICtrlRichEdit_SetCharColor($hWnd, $iColor) _GuiCtrlRichEdit_Deselect($hWnd) EndFunc Func WM_SYSCOMMAND($hWnd, $iMsg, $WParam, $LParam) Switch $hWnd Case $Form1 Switch $WParam Case $SC_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) _IEQuit($oIE) Exit EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam) #forceref $hWnd, $iMsg, $iWparam Local $hWndFrom, $iCode, $tNMHDR, $tEnLink, $cpMin, $cpMax, $tMsgFilter $tNMHDR = DllStructCreate($tagNMHDR, $iLparam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hRichEdit Select Case $iCode = $EN_LINK $tMsgFilter = DllStructCreate($tagMSGFILTER, $iLparam) If DllStructGetData($tMsgFilter, "msg") = $WM_LBUTTONUP Then $tEnLink = DllStructCreate($tagENLINK, $iLparam) $cpMin = DllStructGetData($tEnLink, "cpMin") $cpMax = DllStructGetData($tEnLink, "cpMax") ShellExecute(_GUICtrlRichEdit_GetTextInRange($hRichEdit, $cpMin, $cpMax)); EndIf EndSelect EndSwitch Return $GUI_RUNDEFMSG EndFunc EDIT : I just realized, that twitch chat is powered by IRC. And there are plenty of IRC scripts in here. You just need to get the correct parameters (server, port, channel...). You can also build a chat bot with mIRC:
  10. Your script failed on my PC at CrateFileW function. I was able to test this successfully on my PC though: $retVal = testFunc(@WindowsDir & "\notepad.exe") if NOT @error then MsgBox(0, "HCATINFO", "Success: " & @CRLF & @CRLF & $retVal) Else MsgBox(0, "Error", "Error code: " & @error & @CRLF & @CRLF & $retVal) EndIf func testFunc($sFile) Local $pContext $context = DllCall('Wintrust.dll', 'BOOL', 'CryptCATAdminAcquireContext', 'ptr*', $pContext, 'ptr', 0, 'DWORD', 0) If @error Or Not $context[0] Then Return SetError(1, 0, "CryptCATAdminAcquireContext failed to return pContext") $context = $context[1] Local $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFileW", _ "wstr", $sFile, _ "dword", 0x80000000, _ ; GENERIC_READ "dword", 1, _ ; FILE_SHARE_READ "ptr", 0, _ "dword", 3, _ ; OPEN_EXISTING "dword", 0, _ ; SECURITY_ANONYMOUS "ptr", 0) If @error Or $a_hCall[0] = -1 Then Return SetError(2, 0, "CreateFileW function failed") Local $hFile = $a_hCall[0] Local $cbHash = 0 $cbHash = DllCall('Wintrust.dll', 'BOOL', 'CryptCATAdminCalcHashFromFileHandle', 'handle', $hFile, 'DWORD*', $cbHash, 'ptr', 0, 'dword', 0) If @error Or Not $cbHash[0] Then _WinAPI_CloseHandleEx($hFile) Return SetError(3, 0, "CryptCATAdminCalcHashFromFileHandle failed to return cbHash") EndIf $cbHash = $cbHash[2] Local $Buffer = DllStructCreate('BYTE[' & $cbHash & ']') $pbHash = DllStructGetPtr($Buffer, 1) $cbHash = DllCall('Wintrust.dll', 'BOOL', 'CryptCATAdminCalcHashFromFileHandle', 'handle', $hFile, 'DWORD*', $cbHash, 'ptr', $pbHash, 'DWORD', 0) If @error Or Not $cbHash[0] Then _WinAPI_CloseHandleEx($hFile) Return SetError(4, 0, "CryptCATAdminCalcHashFromFileHandle failed to return cbHash, #2") EndIf $cbHash = $cbHash[2] _WinAPI_CloseHandleEx($hFile) Local $CatalogContext = DllCall('Wintrust.dll', 'handle', 'CryptCATAdminEnumCatalogFromHash', 'handle', $context, 'ptr', $pbHash, 'DWORD', $cbHash, 'DWORD', 0, "handle", 0) If @error Or not $CatalogContext[0] Then Return SetError(5, 0, "CryptCATAdminEnumCatalogFromHash failed to return HCATINFO") $CatalogContext = $CatalogContext[0] Return $CatalogContext EndFunc ; #FUNCTION# ==================================================================================================================== ; Author ........: Paul Campbell (PaulIA) ; Modified.......: ; =============================================================================================================================== Func _WinAPI_CloseHandleEx($hObject) Local $aResult = DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hObject) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] EndFunc ;==>_WinAPI_CloseHandle
  11. The error you're seeing is a .NET native message box for showing exceptions in compiled programs. It's nothing related to AutoIt. I believe that the app you're trying to start does not like being a child process. If you use ShellExecute or Run commands, then the app you're trying to start will act as a child process of the process that started it. To test this you can download Process Explorer and try to start "notepad.exe" from ShellExecute or Run. You'll notice that the "notepad.exe" is now a child process of your autoit's script. If that is indeed the case, then this might help: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <FileConstants.au3> ;set your app destination here: $AppThatIWantToStart = "C:\Windows\notepad.exe"; REQUIRES FULL DESTINATION if outside of %windir%, but in this case I could have just written: "notepad.exe" because "notepad.exe" is indeed in the %windir% $Form1 = GUICreate("Form1", 300, 100) $Button1 = GUICtrlCreateButton("start APP", 0, 0, 300, 50) $Button2 = GUICtrlCreateButton("start APP alternative", 0, 50, 300, 50) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ShellExecute($AppThatIWantToStart) Case $Button2 ShellExecuteNoParrent($AppThatIWantToStart, "", "/MAX");/MAX will maximize it, for other options check this link: http://ss64.com/nt/start.html if @error then MsgBox(0, "error", "could not start your program") EndSwitch WEnd Func ShellExecuteNoParrent($fileName, $parameters = "", $options = "", $title = "", $command = "") $tempFile = @TempDir & "\tempStartMyApp.bat" if StringLen($options) > 0 then $options = " " & $options $title = ' "' & $title & '"' if StringLen($command) > 0 then $command = ' "' & $command & '"' if StringLen($parameters) > 0 then $parameters = " " & $parameters $scriptLines = "@echo off" & @CRLF & 'START ' & $options & $title & ' "' & $fileName & '"' & $command & $parameters $FileHandle = FileOpen($tempFile, $FO_UTF8_NOBOM + $FO_OVERWRITE) if @error then Return SetError(1, 0, 0) FileWrite($FileHandle, $scriptLines) FileClose($FileHandle) ShellExecuteWait("tempStartMyApp.bat", Default, @TempDir, Default, @SW_HIDE) FileDelete($tempFile) EndFunc First button will start the app normally (and you can see that your app - notepad.exe, is now a child of your script), and the 2nd button will start the app as it's being started from a windows native "run" dialog box (where parent is "explorer.exe").
  12. It seems that the WMP can't change aspect ratio, so you can't stretch to fill both: desired width and desired height. http://www.sevenforums.com/music-pictures-video/163445-stretch-videos-wmp.html http://stackoverflow.com/questions/15749181/stretch-video-of-axwindowsmediaplayer-without-maintaining-aspect-ration-in-c-sha But you can stretch to the either one of those: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <IE.au3> Global $width = 800 Global $height = 450 Global $IEControl; = null; Global $MyGUI = GUICreate("WMPlayer Control", $width,$height,(@DesktopWidth-$width)/2,(@DesktopHeight-$height)/2, $WS_OVERLAPPEDWINDOW) Global $oIE = _GUICtrl_CreateWMPlayer("about:blank", 0, 0, $width, $height) GUISetState (@SW_SHOW, $MyGUI) GUIRegisterMsg($WM_SIZE, "WM_SIZE") Global $playerOBJ = _IEGetObjById($oIE, "objWMPlayer") if NOT IsObj($playerOBJ) Then MsgBox(0, "Error", "WMP failed to be created."); Exit; EndIf ;~ $FileOpen = "C:\Users\Public\Videos\Sample Videos\Wildlife.wmv"; $FileOpen = FileOpenDialog("Open Videos", @UserProfileDir, "Movies (*.3gp;*.mp4;*.avi;*.wmv;*.flv)") If Not @error Then _wmpvalue($playerOBJ, "nocontrols") _wmploadmedia($playerOBJ,$FileOpen) $mediaName = _wmpvalue($playerOBJ, "getname"); WinSetTitle($MyGUI, "", "Playing video: " & $mediaName) Else Exit; EndIf While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit; EndSwitch WEnd Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $xClient, $yClient $xClient = BitAND($ilParam, 0x0000FFFF) $yClient = BitShift($ilParam, 16) GUICtrlSetPos($IEControl, 0, 0, $xClient, $yClient) if NOT @error Then if IsObj($playerOBJ) Then $playerOBJ.width = $xClient; if IsObj($playerOBJ) Then $playerOBJ.height = $yClient; EndIf Return $GUI_RUNDEFMSG EndFunc ;=============================================== ;=============================================== ;=============================================== #cs _wmploadmedia( $object, $URL ) $object: Object returned from the $playerOBJ = _IEGetObjById($oIE, "objWMPlayer") $URL: Path or URL of the media Return: None #ce Func _wmploadmedia( $object, $URL) $object.URL = $URL While Not $object.controls.isAvailable("play") Sleep(1) WEnd $object.controls.play() EndFunc ; Function: _GUICtrl_CreateWMPlayer ; Purpose: Embed Windows Media Player and play one file or one playlist only. ; Notes: PARAM NAME="url" is ReadOnly ; Authors: squirrely1 ; borderless IE embed example: GaryFrost ; Kudos - Kare Johansson, CFire ; References: ; http://msdn2.microsoft.com/en-us/library/ms930698.aspx ; http://www.w3schools.com/media/media_playerref.asp ; clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6 - wmplayer latest installed version ; clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95 - wmp 6.4 ;=============================================== Func _GUICtrl_CreateWMPlayer($movieURL, $playerLeft, $playerTop, $playerWidth, $playerHeight, _ $insetBorders = 0, $fullscreenMode = False, $showControls = True, $enableContextMenu = True, _ $LoopMode = false, $playCount = 1, $playVolume = 100, $playBalance = 0, $enableFullScreenControls = True) If $fullscreenMode Then $fullscreenMode = "true" Else $fullscreenMode = "false" EndIf If $showControls Then $showControls = "true" Else $showControls = "false" EndIf If $enableContextMenu Then $enableContextMenu = "true" Else $enableContextMenu = "false" EndIf If $LoopMode Then $playCount = 999 EndIf If $enableFullScreenControls Then $enableFullScreenControls = "true" Else $enableFullScreenControls = "false" EndIf Local $myIE_Obj = _IECreateEmbedded () $IEControl = GUICtrlCreateObj($myIE_Obj, $playerLeft, $playerTop, $playerWidth, $playerHeight) _IENavigate($myIE_Obj, "about:blank") Local $htmlWMP $htmlWMP = '' _ & @CR & '<body style="margin:0;padding:0" >' _ & @CR & '<OBJECT' _ & @CR & 'ID="objWMPlayer"' _ & @CR & 'STYLE="margin:0;padding:0"' _ & @CR & 'HSPACE="0"' _ & @CR & 'VSPACE="0"' _ & @CR & 'BORDER="0"' _ & @CR & 'WIDTH="' & $playerWidth & '"' _ & @CR & 'HEIGHT="' & $playerHeight & '"' _ & @CR & 'CLASSID="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"' _ & @CR & 'STANDBY="Loading Windows Media Player components..."' _ & @CR & 'TYPE="application/x-ms-wmp">' _ & @CR & '<PARAM NAME="allowHideControls" VALUE="true">' _ & @CR & '<PARAM NAME="autoStart" VALUE="false">' _ & @CR & '<PARAM NAME="audioStream" VALUE="false">' _ & @CR & '<PARAM NAME="autoSize" VALUE="false">' _ & @CR & '<PARAM NAME="balance" VALUE="' & $playBalance & '"><!-- -100 to 100 -->' _ & @CR & '<!-- <PARAM NAME="bufferingTime" VALUE="5"><!-- seconds -->' _ & @CR & '<PARAM NAME="clickToPlay" VALUE="false"><!-- has no effect -->' _ & @CR & '<PARAM NAME="currentPosition" VALUE="0"><!-- start position within video, in seconds -->' _ & @CR & '<PARAM NAME="enableContextMenu" VALUE="' & $enableContextMenu & '">' _ & @CR & '<PARAM NAME="enableFullScreenControls" VALUE="' & $enableFullScreenControls & '">' _ & @CR & '<PARAM NAME="enabled" VALUE="true"><!-- whether controls are enabled -->' _ & @CR & '<PARAM NAME="fullScreen" VALUE="' & $fullscreenMode & '">' _ & @CR & '<PARAM NAME="mute" VALUE="false">' _ & @CR & '<PARAM NAME="playCount" VALUE="' & $playCount & '">' _ & @CR & '<!-- <PARAM NAME="previewMode" VALUE="true"> -->' _ & @CR & '<PARAM NAME="rate" VALUE="1"><!-- play speed of -.5 to 2 increments of .1 -->' _ & @CR & '<PARAM NAME="sendPlayStateChangeEvents" VALUE="false">' _ & @CR & '<PARAM NAME="showCaptioning" VALUE="false">' _ & @CR & '<PARAM NAME="showControls" VALUE="' & $showControls & '">' _ & @CR & '<PARAM NAME="showGotoBar" VALUE="false">' _ & @CR & '<PARAM NAME="showPositionControls" VALUE="true"><!-- uiMode must = "full" -->' _ & @CR & '<PARAM NAME="showStatusBar" VALUE="false"><!-- has no effect -->' _ & @CR & '<PARAM NAME="showDisplay" VALUE="true"><!-- has no effect - reportedly shows filename -->' _ & @CR & '<PARAM NAME="stretchToFit" VALUE="true">' _ & @CR & '<PARAM NAME="uiMode" VALUE="full"><!-- invisible, none, mini, full -->' _ & @CR & '<!-- <PARAM NAME="videoBorderWidth" VALUE="0"> -->' _ & @CR & '<PARAM NAME="volume" VALUE="' & $playVolume & '"><!-- volume percent setting of wmplayer.exe -->' _ & @CR & '<PARAM NAME="windowlessVideo" VALUE="false"><!-- must be the default (false) for function to work in wmp 9.0, otherwise might renders video directly in the client area -->' _ & @CR & '</OBJECT>' _ & @CR & '</body>' _IEDocWriteHTML ($myIE_Obj, $htmlWMP) _IEAction ($myIE_Obj, "refresh") $myIE_Obj.document.body.scroll = "no" $myIE_Obj.document.body.style.border = $insetBorders Return $myIE_Obj EndFunc ;==>_GUICtrl_CreateWMPlayer Func _wmpvalue( $object, $setting, $para=1 ) Switch $setting Case "play" If $object.controls.isAvailable("play") Then $object.controls.play() case "stop" If $object.controls.isAvailable("stop") Then $object.controls.stop() case "pause" If $object.controls.isAvailable("pause") Then $object.controls.pause() case "invisible" $object.uiMode = "invisible" case "controls" $object.uiMode = "full" case "nocontrols" $object.uiMode = "none" case "fullscreen" $object.fullscreen = "True" Case "step" If $object.controls.isAvailable("step") Then $object.controls.step($para) Case "fastForward" If $object.controls.isAvailable("fastForward") Then $object.controls.fastForward() Case "fastReverse" If $object.controls.isAvailable("fastReverse") Then $object.controls.fastReverse() Case "volume" $object.settings.volume = $para Case "rate" $object.settings.rate = $para Case "playcount" $object.settings.playCount = $para Case "setposition" $object.controls.currentPosition = $para Case "getposition" Return $object.controls.currentPosition Case "getpositionstring" Return $object.controls.currentPositionString Case "getduration" Return $object.currentMedia.duration Case "getname" Return $object.currentMedia.name EndSwitch EndFunc
  13. Can you try this query as a test? $query = "SELECT Sammelgang_DB.Short_Description, Sammelgang_DB.Status, Sammelgang_DB.Wunschtermin FROM Sammelgang_DB WHERE Sammelgang_DB.Status LIKE 'Angefordert' ORDER BY Sammelgang_DB.Wunschtermin"
  14. is this working? #RequireAdmin #include <Array.au3> $sHost = @ComputerName $aNetworkAdapters = WMI_ListAllNetworkAdapters($sHost) _ArrayDisplay($aNetworkAdapters) Func WMI_ListAllNetworkAdapters($sHost) ;coded by UEZ 2013 Local $objWMIService = ObjGet("winmgmts:\\" & $sHost & "\root\cimv2") If @error Then Return SetError(1, 0, 0) Local $aStatus[13] = ["Disconnected", "Connecting", "Connected", "Disconnecting", "Hardware not present", "Hardware disabled", "Hardware malfunction", _ "Media Disconnected", "Authenticating", "Authentication Succeeded", "Authentication Failed", "Invalid Address", "Credentials Required"] $colItems = $objWMIService.ExecQuery("SELECT Name, NetConnectionID, NetConnectionStatus FROM Win32_NetworkAdapter", "WQL", 0x30) Local $aNetworkAdapters[1000][3], $i = 0, $iPointer If IsObj($colItems) Then For $objItem in $colItems With $objItem $aNetworkAdapters[$i][0] = .NetConnectionID $aNetworkAdapters[$i][1] = .Name $aNetworkAdapters[$i][2] = $aStatus[.NetConnectionStatus * 1] EndWith $i += 1 Next ReDim $aNetworkAdapters[$i][3] Return $aNetworkAdapters Else Return SetError(2, 0, 0) EndIf EndFunc Coded by: UEZ Source:
  15. $TerminateKey = "F10" MsgBox(0, $TerminateKey, _IsTerminateKeyOK($TerminateKey)) $TerminateKey = "OFF" MsgBox(0, $TerminateKey, _IsTerminateKeyOK($TerminateKey)) $TerminateKey = "F13" MsgBox(0, $TerminateKey, _IsTerminateKeyOK($TerminateKey)) Func _IsTerminateKeyOK($trmKey) Switch $trmKey Case "OFF", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12" Return True EndSwitch Return False EndFunc ;================================================ dim $Read[7] = [0, 4, 4, 4, 4, 4, 4];$Read[1] = 4, $Read[2] = 4, $Read[3] = 4, $Read[4] = 4, $Read[5] = 4, $Read[6] = 4 MsgBox(0, 'Array equal to 4', _IsReadArrayEqualTo($Read, 4)) Func _IsReadArrayEqualTo($theArray, $theNumber) for $i = 1 to UBound($theArray)-1 if $theArray[$i] <> $theNumber Then Return False Next Return True EndFunc
×
×
  • Create New...