
Fly By Night
Members-
Posts
16 -
Joined
-
Last visited
Everything posted by Fly By Night
-
If I wanted to load in the Events object and search through all the values of a key for a specific one, what method would you recommend? I wasn't sure how to do this optimally that is why i ended up just doing a While..Wend using the $i to increment onto the next key until i find the value i'm after. Also i wasn't sure if '["events"][' & $i & ']["event_id"]') <> "" was the correct method to check for end of keys. I realise what i'm after is a Jsmn_Search function that looks for a value and returns how to obtain it via Jsmn_Get. I did a test of copying key values into an array using Jsmn_Get then _StringBetween and Jsmn_Get was a lot faster on a test of about 1600 keys.
-
I'm searching through a long (>800) list looking for a specific value using the following code and my routine seems to be very slow compared to using a similar version just using _StringBetween on the raw JSON string. I'm not sure if i can reduce the number of Jsmn_Get calls using the logic below. Is the While..Wend method below one to use or am i missing a better way to hunt for a value. Thanks again. Func getEventstate($eventID) ; Search for a specific EventID and return it's state Local $evState = "", $evFound = 0 Local $i = 0 While ((Jsmn_Get($EventsObj, '["events"][' & $i & ']["event_id"]') <> "") And $evFound = 0) If Jsmn_Get($EventsObj, '["events"][' & $i & ']["event_id"]') == $eventID Then $evState = Jsmn_Get($EventsObj, '["events"][' & $i & ']["state"]') $evFound = 1 EndIf $i = $i + 1 WEnd Return ($evState) EndFunc ;==>getEventstate2 For reference, same using _StringBetween Func getEventstate($eventID) $srcStr = '"event_id":"' & $eventID & '","state":"' $evState = _StringBetween($EventsJson, $srcStr, '"}') If $evState <> "" Then Return ($evState[0]) EndIf EndFunc ;==>getEventstate
-
Thanks! Wow, it's easy to do once you know the correct syntax. Thanks again for the UDF and your code above really helps me understand it more now
-
I'm trying to parse the data below, {"events":[{"world_id":2012,"map_id":873,"event_id":"659149D4-43EC-4DCB-A6BB-0B2D402B537B","state":"Warmup"}, {"world_id":2012,"map_id":873,"event_id":"72F93CD8-94AC-4234-8D86-996CCAC76A46","state":"Warmup"}, {"world_id":2012,"map_id":873,"event_id":"81F89AC2-4764-49CB-A4F1-8B7546201DC7","state":"Active"}, {"world_id":2012,"map_id":873,"event_id":"FF71DE90-423B-4685-A343-83487A330C7A","state":"Active"}]} The end result would be an array with 3 columns for map_id, event_id, and state filled with the relevant data. By striping '{"events":[' and ']}' from either end i managed to get the values of the first line/object but how do extract further items? I can't work out how to loop into the next line(s). Thanks for any help. My code isn't really worth showing hence no code example.
-
Defining Null Arrays
Fly By Night replied to Fly By Night's topic in AutoIt General Help and Support
Cheers i just read the info at the thread pointed to by Melba23 so will go work on these techniques. -
Defining Null Arrays
Fly By Night replied to Fly By Night's topic in AutoIt General Help and Support
Cheers. Now i know why i've never managed to figured out how to have an empty array...lol. Just never asked about it and made workarounds. Just trying to make a queue and sometimes it will be empty. Will just have to have a dummy entry in to keep array alive i guess. Thanks again. -
In all my years dabbling with AutoItScript, i've never figured this out. How do you define a null array? Is $clipQ[1] = [""] considered a null array? I've tried $clipQ = "" but when you try to do array operations on it, they seem to fail. With the _ArrayPop function, If the array has one element left, it will be set to "" after _ArrayPop() is used on it. What is that setting the array too as you can't display the array using _ArrayDisplay anymore. Is is going back to setting the array as an empty string as when i try to do an _ArrayAdd after it's popped the last item, this doesn't work? How do you get around that? Thanks for any info to clear this for me.
-
[Solved]How to capture a GET HTPP?
Fly By Night replied to Darako's topic in AutoIt General Help and Support
This is my code i used for this. Normally you get redirected to the final location of u.to/6GECAQ. By adding that WinHttpSetOption line, i stop redirects then you can grab the location it is going to by extracting Location: from the headers. #include "WinHttp.au3" $host = "u.to" $hGet = "/6GECAQ" ; Initialize and get session handle Global $hOpen = _WinHttpOpen() _WinHttpSetOption($hOpen, $WINHTTP_OPTION_REDIRECT_POLICY, $WINHTTP_OPTION_REDIRECT_POLICY_NEVER) ; Get connection handle Global $hConnect = _WinHttpConnect($hOpen, $host) ; Request Global $hRequest = _WinHttpOpenRequest($hConnect, "GET", $hGet) _WinHttpSendRequest($hRequest) _WinHttpReceiveResponse($hRequest) Global $sHeader ; If there is data available... If _WinHttpQueryDataAvailable($hRequest) Then $sHeader = _WinHttpQueryHeaders($hRequest) ; ...get full header ; Close handles _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) MsgBox(0, "Header", $sHeader) -
[Solved]How to capture a GET HTPP?
Fly By Night replied to Darako's topic in AutoIt General Help and Support
Use Mithrandir's code from post #2 and add this after $hOpen = _WinHttpOpen() _WinHttpSetOption($hOpen, $WINHTTP_OPTION_REDIRECT_POLICY, $WINHTTP_OPTION_REDIRECT_POLICY_NEVER) Just turns off server redirects. You can then extract the Location value from the headers returned in $sHeader -
Thanks for the quick reply. All working now, typical i missed the one setting when looking at the options. I have one scenario where i need to replicate a feature of cURL I'm using cURL just now a few functions but trying to move them in AutoIt. For the above, i'm grabbing a link from multiupload.com and it's redirecting to rapidshare which seems to use https. I use the -k option to get around the certificate issue which seems to get me the data required. I've tried setting a few options in WinHTTP but no luck. Do you have any idea how to do this at all? Thanks again. WINHTTP_OPTION_CLIENT_CERT_CONTEXT seems to be the nearest option but i'm not sure how to get this working with WinHTTP.au3 as it doesn't seem supported.
-
Hi I'm trying to catch a 302 redirect but when i disable redirects using _WinHttpSetOption, the request still goes on to the final page. My code is based on one of your examples. Also i'm not sure if i'm using _WinHttpAddRequestHeaders correctly. Any help would be appreciated, thanks. ; Initialize and get session handle Global $hOpen = _WinHttpOpen() _WinHttpSetOption($hOpen, $WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_DISABLE_REDIRECTS) ; Get connection handle Global $hConnect = _WinHttpConnect($hOpen, "u.to") ; Request Global $hRequest = _WinHttpOpenRequest($hConnect, "GET", "/6GECAQ") _WinHttpAddRequestHeaders($hRequest, "Host: u.to") _WinHttpAddRequestHeaders($hRequest, "User-Agent: Sausage Head/5.0") _WinHttpSendRequest($hRequest) _WinHttpReceiveResponse($hRequest) Global $sHeader = _WinHttpQueryHeaders($hRequest) ; Close handles _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) MsgBox(0, "Header", $sHeader)
-
Cheers. I found what i was looking for after all. I did a search and came up with an "incremental variable names" post that provided a solution. Global $numGenres = 15 Global $genreArr[$numGenres] = ["House", "Dance", "Electronic", "Trance", "Hardstyle", "Drum_&_Bass", "Commercial", "Jumpstyle", "Pop", "Rock", "Hip-Hop", "R_&_B", "Techno", "Other", "Psychedelic"] Global $genreTabs[$numGenres], $genreEdit[$numGenres] _ArraySort($genreArr) $SBForm = GUICreate("TabsRUs", 914, 605, 193, 124) $Tab = GUICtrlCreateTab(8, 8, 897, 513) GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) For $r = 0 To UBound($genreTabs, 1) - 1 $genreTabs[$r] = GUICtrlCreateTabItem($genreArr[$r]) $genreEdit[$r] = GUICtrlCreateEdit("", 12, 33, 889, 484) Next GUICtrlCreateTabItem("") GUISetState(@SW_SHOW)
-
I'm trying to build a GUI on the fly using a loop to generate the code needed. Array items are being read to get the values needed to build tabs, For $r = 0 To UBound($genreArr, 1) - 1 $tGenre = $genreArr[$r] $i = "$" & $tGenre & " = GUICtrlCreateTabItem(""" & $tGenre & """)" $j = "$" & $tGenre & "Edit = GUICtrlCreateEdit("""", 12, 33, 889, 484)" Eval($i) ; What goes here? Eval($j) ; What goes here? Next I've checked using MsgBox, $i and $j contains the strings to make the Tab elements needed in the correct format. I just used Eval in there as a placeholder but is there a function out there that can run the string like a line of code? I've tried searching for this as i'm sure it's been done loads of time but can't find the answer. Thanks.
-
Problem Handling Keypresses In A Loop
Fly By Night replied to Fly By Night's topic in AutoIt General Help and Support
Cheers I'll try that. I see my $temp = """{NUMPAD" & $i & "}""" wasn't working after all and $temp = "{NUMPAD" & $i & "}" does after all. Maybe you dont need the quotes for the value when using a variable with Send(). Thanks again .... -
Problem Handling Keypresses In A Loop
Fly By Night replied to Fly By Night's topic in AutoIt General Help and Support
I used $temp = """{NUMPAD" & $i & "}""" as the Send command takes Send("{Numpad1}") Using $temp = "{NUMPAD" & $i & "}" would make it Send({Numpad1}) Also I made a mistake in the SBAuto2 function, If $yourpos <> $1 Then should be If $yourpos <> $i Then I know about this so you don't need to tell me that. Cheers for the help so far. I can't see what i've done wrong as it is running Send with the right value so that's why I came to the forums. Plus yes sorry I'm asking why the loop is not behaving. I'm calling it ok this is just the function that didn't behave as planned. -
Problem Handling Keypresses In A Loop
Fly By Night posted a topic in AutoIt General Help and Support
Hi I had the following in a For .. Next loop before but had to revert to this long method due to it sending wrong keypresses. Here is the code, Func SBAuto() $i = 1; Sleep(4500) Send("{NUMPAD0}") Sleep($annDelay) If $yourpos <> 1 Then Send("{NUMPAD1}") Sleep(500) Send("{NUMPAD1}") Sleep(4500) EndIf If $yourpos <> 2 Then Send("{NUMPAD2}") Sleep(500) Send("{NUMPAD2}") Sleep(4500) EndIf If $yourpos <> 3 Then Send("{NUMPAD3}") Sleep(500) Send("{NUMPAD3}") Sleep(4500) EndIf If $yourpos <> 4 Then Send("{NUMPAD4}") Sleep(500) Send("{NUMPAD4}") Sleep(4500) EndIf If $yourpos <> 5 Then Send("{NUMPAD5}") Sleep(500) Send("{NUMPAD5}") Sleep(4500) EndIf If $yourpos <> 6 Then Send("{NUMPAD6}") Sleep(500) Send("{NUMPAD6}") Sleep(4500) EndIf If $yourpos <> 7 Then Send("{NUMPAD7}") Sleep(500) Send("{NUMPAD7}") Sleep(4500) EndIf If $yourpos <> 8 Then Send("{NUMPAD8}") Sleep(500) Send("{NUMPAD8}") EndIf Sleep(80000) EndFunc ;==>SBAuto Before I was using something like this which might be slighty out as wiped what i had Func SBAuto2() Sleep(4500) Send("{NUMPAD0}") Sleep($annDelay) For $i = 1 to 8 Step 1 $temp = """{NUMPAD" & $i & "}""" If $yourpos <> $1 Then Send($temp) Sleep(500) Send($temp) Sleep(4500) EndIf Next Sleep(80000) EndFunc It was making up the NUMPAD1 to 8 alright as I had a label up changing as it went up the loop. For some reason though it kept sending weird things to program and it didn't run as intended. Seemed to keep sending NUMPAD2 a lot. Can anyone see what might have gone wrong in the loop and why I had to go back to the "Long" version? Thanks