Jump to content

OverloadUT

Active Members
  • Posts

    46
  • Joined

  • Last visited

Everything posted by OverloadUT

  1. Those tail functions use _FileCountLines() which has to read the entire file in to memory. Once again, I cannot have it do that. The solutions presented by gafrost and randallc do not read the entire file in to memory, which is exactly what I need. I'll use qafrost's because it's a very small amount of code and all I need to do is read a file from a particular byte forward, not write to the file. Thanks everyone! Edit: Actually, the "scripting.filesystemobject" method used in gafrost's solution takes a while to seek far in to a file. I tested it seeking 100mb in to a 200mb file, and it took a good 3 seconds to execute. The _APIFile functions in randallc's solution works perfectly - seeking 100mb in only takes a few ms. Thanks!
  2. Thank you gafrost, that's exactly what I need! In case you're curious, my AutoIt program serves as the "bridge" between Civilization 4 and my civstats.com website. The AutoIt program will need to read from a log file created by a Civ4 python script and upload only the new log items to the webserver every time it changes. This log file could potentially become very large so just remembering the last byte I stopped at on the last upload is seems like the most logical way of doing it. Every couple seconds I check to see if the log file has grown, and if it has I start reading any bytes starting after the last byte I read.
  3. _FileCountLines() is simply a UDF that does this: Return StringLen(StringAddCR(FileRead($sFilePath, $N))) - $N + 1 ; $N is the size of the file Therefore, it has to read the entire file in to memory with the "FileRead()" call. I need to avoid doing that.
  4. Yes, both of those solutions would accomplish the goal of reading part of the file, but the fundamental problem is the fact that both of them require reading the entire file in to memory. As I said, my file could be 30mb, so that would be a huge amount of memory to use every 5 seconds. The file system allows you to "seek" to a particular byte and only read the bytes you want to, but all of the AU3 functions seem to read the entire file in to memory...
  5. I am in need of reading a file starting from a particular byte. I do not want to read the entire file in to memory and then scan it that way, because this file could be up to 30 megs, and I need to read it every 5 seconds. I looked through the help file and I couldn't find any file read functions that let you seek to a particular byte and read from there. Does this exist?
  6. In both of your examples, you're declaring the variable AFTER you call "IsDeclared" so it's functioning exactly as expected. If this just a snippit of your code? If it is, post the whole thing, or at least the entirety of an example so we can see.
  7. How about adding Goto? This was a joke.
  8. Well, you can read the cookies sent by the server using these functions, but I currently don't have a way of sending custom headers with a get or post request - that's something I'll need to add. I might create special cookie handling functions as well.
  9. Google actually does all of its searches as GET requests, not POST requests. This is so that you can link a page of results and actually have it work. In that case, to do a google search, you would want to do this: $host = "www.google.com" $page = "/imghp" $vars = "hl=en&tab=wi&q=" $searchterm = "porche" $url = $page&"?"&_HTTPEncodeString($vars&$searchstring) $socket = _HTTPConnect($host) $get = _HTTPGet($host,$url,$socket) $recv = _HTTPRead($socket,1) ConsoleWrite("Data received:"&@CRLF$recv[4]&@CRLF) Any variables after the question mark need to be HTTP Encoded, which is why I put the "vars" in a separate variable from the page.
  10. Ironically, B3TA_SCR1PT3R's method is in some ways more random, because it contains unpredictable entropy. Food for thought.
  11. Thank you everyone for the kind words. If anyone actually gives it a try, I'd love to hear how it works for them. This website was my main source. Well, that and a LOT of trial and error.
  12. That code will work, but the output will be the raw packets as opposed to the actual data of the response. In the case of a chunked response, it would be a real pain to write a parser... ... a pain that I already went through, so you shouldn't have to! I recommend checking out my HTTP UDF's - one of the features is that you can set the User-Agent.
  13. I am working on a fairly large project and a big part of it is an AutoIt application that uploads a lot of data to a PHP script. For a while I was using INetGet and submitting all my data as GET variables in the URL. However, the amount of data to upload got too big (over 1000 characters) and the INetGet function started to fail. I also hated that INetGet ONLY works if the webserver responds with "200 OK" - There is no way to tell the difference between a 404 error and simply not being able to connect to the server in the first place. So I write this library of UDF's. Basically, it's a fully compliant HTTP/1.1 client. It uses only the TCP functions; no DllCall needed here! I had a blast learning all about the HTTP protocol and how to use it. Advantages over INetGet: The data is downloaded right in to variables instead of to files. You can of course then write this data to a file if you wish. You can read all of the headers supplied by the webserver. You can get the HTTP Response Code from the webserver. When it failes, you know exactly what failed instead of having to guess. ; =================================================================== ; HTTP UDF's ; v0.5 ; ; By: Greg "Overload" Laabs ; Last Updated: 07-22-06 ; Tested with AutoIt Version 3.1.1.131 ; Extra requirements: Nothing! ; ; A set of functions that allow you to download webpages and submit ; POST requests. ; ; Main functions: ; _HTTPConnect - Connects to a webserver ; _HTTPGet - Submits a GET request to a webserver ; _HTTPPost - Submits a POST request to a webserver ; _HTTPRead - Reads the response from a webserver ; =================================================================== I consider this UDF package to be a "beta" and that's why I call it version 0.5. However, I would love people to give it a try and tell me how it works for them. I have done extensive testing and I think I have the parser working perfectly. I plan on improving this library. It's possible that I might change the way the functions work (I don't think the _HTTPConnect function is necessary; I could move that functionality right in to the Get or Post functions.) To Do: Add a function that downloads the data right to a file. You might not want to download a 10 meg file in to memory before saving it to a file.Add a method to get the progress of the download. This will probably be in the form of a callback function, if that's possible in AutoIt.Add the ability to automatically follow "Location:" headers. Currently you'd have to do it manually.Other things I can't think of!Post #25 For Updated functions to work with current AutoIt versions.
  14. ... I knew it was something simple. And I've been using regular expressions for years too. I am ashamed. Thanks!
  15. Okay, I've been banging my head against this for at least an hour now. I'm sure it's something simple, but I can't for the life of me figure it out. I wanted to check here before I submit it as a bug. $data = "|pbupload:test|anothervar:test2|" $regex = StringRegExp($data, "|error:([^|:]+)|", 1) ConsoleWrite(@error&@CRLF&@extended&@CRLF) That outputs: 0 1 WHY? The pattern should mean: Literal string "|error:" followed by 1 or more characters that are not "|" or ":" (and capture it as a group) and then the literal string "|" That pattern should NOT match the test string because "error:" is not in it! Please tell me I'm going crazy and missing something simple...
  16. Icekirby1: That's exactly how I was going to do it, and it's how my current version works with nested arrays. The problem I ran in to was I couldn't figure out any way to get the value from an array where I didn't know the non-variable number of dimensions. Evay() doesn't work with arrays, so I figured it wasn't possible. However, I see that VicTT's version uses Execute() to do what I wanted to do. Had I known that worked, it would have saved me a LOT of headache!
  17. Ah. For some reason when I searched for it I got no matches. I probably searched in the wrong forum by mistake. Regardless, that is a pretty nice function, but I feel that my functions still provide very useful functionality that is missing from _ArrayBox. Namely, my functions will display nested arrays to an unlimited depth, and support arrays up to 4 dimensions (Although I don't think I've ever used arrays larger than 3 dimensions!) Also, I don't like that _ArrayBox requires so many parameters. I only use these functions for debugging and usually just want to very quickly insert _BetterArrayDisplay($array) without having to worry about any other arguments. But thanks for the link!
  18. Argh I hate question 19! Also I think question #12 is very unclear.
  19. No I have not. It's not in the latest beta. Do you have a link to it?
  20. I use arrays a lot. I also use _ArrayDisplay a lot for debugging. However, I was constantly getting frustrated with the fact that it not only didn't support multi-dimensional arrays, but it didn't even have proper error handing when they are passed in! I set out to write a better _ArrayDisplay function that could handle arrays of any dimension. Unfortunately I wasn't able to make it work with unlimited, so I coded this version that works on arrays up to 4 dimensions. There is also a _BetterArrayConsoleDump() function that does the same thing, but it dumps to the console instead of a MsgBox. It also has the added feature of displaying nested arrays - it can do that to unlimited dimensions. Here is some example output to the console. This is a 1 Dimensional Array with a 4 dimensional array nested in the 8th index: 1 Dimensional Array [0] = 17 [1] = 54 [2] = 3 [3] = 77 [4] = 53 [5] = 87 [6] = 52 [7] = 4 Dimensional Array [0] |--[0] |---+--[0] |---+---+--[0] = 71 |---+--[1] |---+---+--[0] = 28 |--[1] |---+--[0] |---+---+--[0] = 85 |---+--[1] |---+---+--[0] = 82 [1] |--[0] |---+--[0] |---+---+--[0] = 91 |---+--[1] |---+---+--[0] = 73 |--[1] |---+--[0] |---+---+--[0] = 84 |---+--[1] |---+---+--[0] = 3 [2] |--[0] |---+--[0] |---+---+--[0] = 17 |---+--[1] |---+---+--[0] = 20 |--[1] |---+--[0] |---+---+--[0] = 4 |---+--[1] |---+---+--[0] = 57 [8] = 54 [9] = 1 Here are the UDF's: ;=============================================================================== ; ; Function Name: _BetterArrayDisplay() ; Description: Displays an array of any dimensions in a message box. ; Author(s): Greg Laabs <gl-autoit at apartment167 dot com> ; ;=============================================================================== Func _BetterArrayDisplay(Const ByRef $avArray, $sTitle = "Array") Local $iCounter = 0, $sMsg = "" If (Not IsArray($avArray)) Then SetError(1) Return 0 EndIf $sMsg = _BetterArrayDisplayFormat(0, $avArray) MsgBox(4096, $sTitle, $sMsg) SetError(0) Return 1 EndFunc ;==>_BetterArrayDisplay ;=============================================================================== ; ; Function Name: _BetterArrayConsoleDump() ; Description: Displays an array of any dimensions in the console. ; Author(s): Greg Laabs <gl-autoit at apartment167 dot com> ; ;=============================================================================== Func _BetterArrayConsoleDump(Const ByRef $avArray, $sTitle = "Array Dump") Local $iCounter = 0, $sMsg = "" If (Not IsArray($avArray)) Then SetError(1) Return 0 EndIf $sMsg = _BetterArrayDisplayFormat(0, $avArray) ConsoleWrite($sTitle & @CRLF) ConsoleWrite($sMsg) SetError(0) Return 1 EndFunc ;==>_BetterArrayConsoleDump ;=============================================================================== ; ; Function Name: _BetterArrayDisplayFormat() ; Description: Formats the string displayed in _BetterArrayConsoleDump and ; _BetterArrayDisplay() ; Author(s): Greg Laabs <gl-autoit at apartment167 dot com> ; ;=============================================================================== Func _BetterArrayDisplayFormat($deep, Const ByRef $avArray) Local $iCounter = 0, $jCounter = 0, $kCounter, $lCounter, $sCounter Local $sMsg = "" $sMsg &= UBound($avArray, 0) & " Dimensional Array" & @CRLF If UBound($avArray, 0) > 1 Then ;FIRST DIMENSION (I) RECURSIVE For $iCounter = 0 To UBound($avArray) - 1 For $sCounter = 1 To $deep If $sCounter = $deep + 1 Then $sMsg &= " |--" ElseIf $sCounter > $deep + 1 Then $sMsg &= "-+--" Else $sMsg &= " " EndIf Next $sMsg &= "[" & $iCounter & "]" & @CR If UBound($avArray, 0) > 2 Then ; SECOND DIMENSION (J) RECURSIVE For $jCounter = 0 To UBound($avArray, 2) - 1 For $sCounter = 1 To $deep + 1 If $sCounter = $deep + 1 Then $sMsg &= " |--" ElseIf $sCounter > $deep + 1 Then $sMsg &= "-+--" Else $sMsg &= " " EndIf Next $sMsg &= "[" & $jCounter & "]" & @CR If UBound($avArray, 0) > 3 Then ; THIRD DIMENSION (K) RECURSIVE For $kCounter = 0 To UBound($avArray, 2) - 1 For $sCounter = 1 To $deep + 2 If $sCounter = $deep + 1 Then $sMsg &= " |--" ElseIf $sCounter > $deep + 1 Then $sMsg &= "-+--" Else $sMsg &= " " EndIf Next $sMsg &= "[" & $kCounter & "]" & @CR If UBound($avArray, 0) > 4 Then ; FOURTH DIMENSION (L) RECURSIVE SetError(1) Return "Cannot display arrays deeper than 3 dimensions" Else ; FOURTH DIMENSION (L) DISPLAY For $lCounter = 0 To UBound($avArray, 4) - 1 For $sCounter = 1 To $deep + 3 If $sCounter = $deep + 1 Then $sMsg &= " |--" ElseIf $sCounter > $deep + 1 Then $sMsg &= "-+--" Else $sMsg &= " " EndIf Next $sMsg &= "[" & $lCounter & "] = " If IsArray($avArray[$iCounter][$jCounter][$kCounter][$lCounter]) Then $sMsg &= _BetterArrayDisplayFormat($deep + 5, $avArray[$iCounter][$jCounter][$kCounter][$lCounter]) Else $sMsg &= $avArray[$iCounter][$jCounter][$kCounter][$lCounter] & @CR EndIf Next EndIf Next Else ; THIRD DIMENSION (K) DISPLAY For $kCounter = 0 To UBound($avArray, 3) - 1 For $sCounter = 1 To $deep + 2 If $sCounter = $deep + 1 Then $sMsg &= " |--" ElseIf $sCounter > $deep + 1 Then $sMsg &= "-+--" Else $sMsg &= " " EndIf Next $sMsg &= "[" & $kCounter & "] = " If IsArray($avArray[$iCounter][$jCounter][$kCounter]) Then $sMsg &= _BetterArrayDisplayFormat($deep + 4, $avArray[$iCounter][$jCounter][$kCounter]) Else $sMsg &= $avArray[$iCounter][$jCounter][$kCounter] & @CR EndIf Next EndIf Next Else ; SECOND DIMENSION (J) DISPLAY For $jCounter = 0 To UBound($avArray, 2) - 1 For $sCounter = 1 To $deep + 1 If $sCounter = $deep + 1 Then $sMsg &= " |--" ElseIf $sCounter > $deep + 1 Then $sMsg &= "-+--" Else $sMsg &= " " EndIf Next $sMsg &= "[" & $jCounter & "] = " If IsArray($avArray[$iCounter][$jCounter]) Then $sMsg &= _BetterArrayDisplayFormat($deep + 3, $avArray[$iCounter][$jCounter]) Else $sMsg &= $avArray[$iCounter][$jCounter] & @CR EndIf Next EndIf Next Else ; FIRST DIMENSION (I) DISPLAY For $iCounter = 0 To UBound($avArray) - 1 For $sCounter = 1 To $deep If $sCounter = $deep + 1 Then $sMsg &= " |--" ElseIf $sCounter > $deep + 1 Then $sMsg &= "-+--" Else $sMsg &= " " EndIf Next $sMsg &= "[" & $iCounter & "] = " If IsArray($avArray[$iCounter]) Then $sMsg &= _BetterArrayDisplayFormat($deep + 2, $avArray[$iCounter]) Else $sMsg &= $avArray[$iCounter] & @CR EndIf Next EndIf Return $sMsg EndFunc ;==>_BetterArrayDisplayFormatoÝ÷ ض¬¶¡z·¢±©ÞÅ©©ë®*m¶ek&«¢éÝÂ+aÖ®¶­sb6æ6ÇVFRfÇC´&WGFW$'&æS2fwC° ¤FÒb33c´&t'&³5Õ³%Õ³UճР¤f÷"b33c¶ÓFò f÷"b33c¶£ÓFò f÷"b33c¶³ÓFò@ f÷"b33c¶ÃÓFò b33c´&t'&²b33c¶Õ²b33c¶¥Õ²b33c¶µÕ²b33c¶ÅÒÒ&æFöÒÃà æW@ æW@ æW@¤æW@ ¥ô&WGFW$'&F7Æb33c´&t'&ÂgV÷C´&r'&×6t&÷gV÷C²¥ô&WGFW$'&6öç6öÆTGV×b33c´&t'&ÂgV÷C´&r'&6öç6öÆRGV×gV÷C² ¤FÒb33cµ6ÖÆÄ'&³Ð ¤f÷"b33c¶ÓFò b33cµ6ÖÆÄ'&²b33c¶ÒÒ&æFöÒÃäæW@¢b33cµ6ÖÆÄ'&³uÒÒb33c´&t'& ¥ô&WGFW$'&F7Æb33cµ6ÖÆÄ'&ÂgV÷Cµ6ÖÆÂ'&×6t&÷gV÷C²¥ô&WGFW$'&6öç6öÆTGV×b33cµ6ÖÆÄ'&ÂgV÷Cµ6ÖÆÂ'&6öç6öÆRGV×gV÷C² Please let me know what you think of my first contribution to the AutoIt community!
  21. The Scripts and Scraps forum says it's not for support, so since the OP was asking a question, I would expect it to be here, not S&S. At least, that's how I understand it.
  22. FYI, I found some UDFs in the Scripts and Scraps forum that does exactly what I needed! I figured I would link it here in case anyone was searching for the same. Unix Timestamp Functions
  23. Thank you!! I was ripping my hair out trying to figure out a good way to generate a Unix timestamp, but I totally forgot to search Scripts and Scraps! These functions work perfectly.
  24. Unfortunately that is not good enough. Some places to not observe DST. I need to know if the system's clock is being adjusted for DST or not so I can adjust the timestamp appropriately. Really I think there should be some built in functions for getting the full date/time (with timezone information) built in to AutoIt. Any ideas?
  25. I am still having no luck with this. Anybody have any ideas? I provided code samples and everything!
×
×
  • Create New...