Thread: Data Parser

    #1
  1. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154

    Data Parser


    The below code is part of my Data Parser for battle.net. I tried to change the code from VB6 to Python as best I could. I was getting confused with the Left() and Right()'s because Python starts at 0 and VB6 starts at 1. Whatever doesn't have a note next to it I'm almsot 100% sure is correct. What does have notes is either wrong or I'm not sure. Can anyone help me?
    PS. Thanks to everyone who's helped me many times.
    Code:
        def Parse(strData):
        if strData[0:-2] == chr(10): # If Left(strData, 1) = Chr(10) Then
            strData = strData[0:len(strData)-1] # strData = Right(strData, Len(strData) - 1)
        if int(strData[0:-4]) < 1001 or int(strData[0:-4]) > 3000: # If Val(Left(strData, 4)) < 1001 Or Val(Left(strData, 4)) > 3000 Then
            Unknown(strData)
            pass
        i = chr(34) in strData
        if i != 0:
            i2 = i - 2
            i1 = i + 1
            i1m = len(strData) - i - 1
            strData1 = strData[0:-i2] # strData1 = Left(strData, i - 2)
            strData2 = strData[i1:i1m] # strData2 = Mid(strData, i + 1, Len(strData) - i - 1)
        else:
            strData1 = strData
            strData2 = ""
        SplitStr(strData1, strArgs())
        case = int(strArgs(1))
        while case == 1001:
            InChannel(strArgs(3), strArgs(4), strArgs(5))
        while case == 1002:
            UserJoin(strArgs(3), strArgs(4), strArgs(5))
        while case == 1003:
            UserLeave(strArgs(3), strArgs(4))
        while case == 1004:
            RecvWhisper(strArgs(3), strArgs(4), strData2)
        while case == 1005:
            UserTalk(strArgs(3), strArgs(4), strData2)
        while case == 1006:
            Broadcast(strData2)
        while case == 1007:
            Channel(strData2)
        while case == 1010:
            SendWhisper(strArgs(3), strArgs(4), strData2)
        while case == 1013:
            ChannelFull(strData2)
        while case == 1014:
            ChannelNotExist(strData2)
        while case == 1015:
            ChannelRestricted(strData2)
        while case == 1016:
            Info(strData2)
        while case == 1018:
            Info(strData2)
        while case == 1019:
            BnetError(strData2)
        while case == 1023:
            UserEmote(strArgs(3), strArgs(4), strData2)
        while case == 2010:
            LoggedIn(strArgs(3))
        while case == 3000:
            Info(strData2)
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    Originally Posted by †Yegg†
    The below code is part of my Data Parser for battle.net. I tried to change the code from VB6 to Python as best I could. I was getting confused with the Left() and Right()'s because Python starts at 0 and VB6 starts at 1.
    (Commentry is mixed with the code)

    Code:
        
    def Parse(strData):
        # if strData[0:-2] == chr(10): # If Left(strData, 1) = Chr(10) Then
        #     strData = strData[0:len(strData)-1] # strData = Right(strData, Len(strData) - 1)
    
        # left(strData, 1) retrieves the first character --> strData[0]
        # However, literally doing the VB check is more ugly than it needs to be in Python
        # chr(10) is the newline character, so that would become:
        if strData.startswith('\n'):
            strData = strData[1:]
    
        # (use everything from the first space onwards)
    
    
        # if int(strData[0:-4]) < 1001 or int(strData[0:-4]) > 3000: # If Val(Left(strData, 4)) < 1001 Or Val(Left(strData, 4)) > 3000 Then
        #     Unknown(strData)
        #     pass
     
        # strData[0:-4] takes everything from the start to four characters from the end. 
        # The first four characters would be "strData[0:4]" and it's normal to leave out 0's, so:
        if int(strData[:4]) < 1001 or int(strData[:4]) > 3000:
            Unknown(strData)
    
        # pass does nothing, it's just a placeholder and isn't needed
    
        # i = chr(34) in strData
        # if i != 0:
        #     i2 = i - 2
        #     i1 = i + 1
        #     i1m = len(strData) - i - 1
        #     strData1 = strData[0:-i2] # strData1 = Left(strData, i - 2)
        #     strData2 = strData[i1:i1m] # strData2 = Mid(strData, i + 1, Len(strData) - i - 1)
        # else:
        #     strData1 = strData
        #     strData2 = ""
    
        # chr(34) is a quote mark "
        # i = chr(34) in strData  returns True (it is present) or False (it isn't present)
        # if i != 0  will then raise an Exception because you can't compare True/False with the number 0
    
        # What it seems to be doing is: if " is in the string, split it to get the left and the right halves.    
    
        if '"' in strData:
            strData1, strData2 = strData.split('"', 1)
        else:
            strData1 = strData
            strData2 = ""
    
     
        SplitStr(strData1, strArgs())
        # splitstr? strargs?   ????
    
    
        # case = int(strArgs(1))
        # while case == 1001:
        #     InChannel(strArgs(3), strArgs(4), strArgs(5))
    
        # strArgs? What's that?
        # while case == any_number: will do nothing if case is another number.
        # As soon as it becomes that number, it will loop forever and crash.
        
        
        # There is no "switch" or "case" in Python, the closest equivalent is
       
        if x == 1:
            a()
        elif x == 2:
            b()
        elif x == 3:
            c()
        
        # and so on
    Where does strArgs come from?
  4. #3
  5. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    strArgs come from SplitStr, it is the Delimiter.
    Code:
        def SplitStr(OriginalString, Delimiter):
            array = OriginalString.split(Delimiter) + [OriginalString]
            return len(array), array
    Here is where strArgs is made.
    Code:
    SplitStr(strData1, strArgs())
    SplitStr(strData1, strArgs()) is under def Parse(strData).Thanks for all the help sfb.
  6. #4
  7. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    I just finished fixing all the small erorrs in my program, and when I was almost at the bottom of the code, I hit an error I couldn't fix, I forgot all about this. It has UBound so I wasn't sure how to change it.
    Code:
        def ParseData(strData):
            SplitStr(strData, strStrings)
            for i == 1 in UBound(strStrings):
                Parse(strStrings(i))
    Thanks for all the other help you given me sfb.

IMN logo majestic logo threadwatch logo seochat tools logo