Thread: vbscript help
View Single Post
Old 2008-11-11, 18:28   #10
IronBits
I ♥ BOINC!
 
IronBits's Avatar
 
Oct 2002
Glendale, AZ. (USA)

111310 Posts
Default

Thanks for the Cint suggestion. I'll look into it further.

For now, here is my 'final' code on parsing Results.txt produced from llrnet servers.

I'm sure there are some optimizations that could be done, so if you see any, appreciate any tips.
All my filenames that I parse end with .org.txt so I'm making copies of the original files to create the .txt and .csv files.
I suppose if someone passed the filename Results.txt as an argument, this would fail...

Code:
Option Explicit

Const ForReading = 1, ForWriting = 2, ForAppending = 8 

Dim oFSO, oInFile, oOutFiletxt,oOutFilecsv
Dim str_Input, str_Output, str_OutCSV, str_CurrentLine, str_CSV, str_TXT
Dim MyArray, MyLine, UserName, Lines
Dim MyDate, MyMO, MyDD, MyYY, MyDay, MyAMPM
Dim MyTIME, MyHH, MyMM, MySS
Dim MyK, MyP, MyN, MyDATA, MyRES, MyT, MyD
Dim Team_Name, arrMyTeamName, FileName, strFileName, arrFileName
Dim argNum, argCount:argCount = Wscript.Arguments.Count

'Set objArgs = WScript.Arguments

If (argCount < 1) Then
    Wscript.Echo VbCrLf & "Please supply the name of the Results file to be converted to .csv ." & VbCrLf
    Wscript.Quit 1
End If 

Wscript.Echo VbCrLf

strFileName = WScript.Arguments(0)
arrFileName = Split(strFileName,".",-1,1)

' the path to the input and output files
str_Input  = strFileName
str_Output = arrFileName(0) & ".txt"
str_OutCSV = arrFileName(0) & ".csv"

str_CSV=""
str_TXT=""
Lines="0"

Set oFSO = CreateObject("Scripting.FileSystemObject")

' If the file exists

If oFSO.FileExists(str_Input) Then

    ' open the text file for input
    Set oInFile = oFSO.OpenTextFile(str_Input)

    ' create the txt file for output
    Set oOutFiletxt = oFSO.CreateTextFile(str_Output,True)

    ' create the csv file for output
    Set oOutFilecsv = oFSO.CreateTextFile(str_OutCSV,True)

    ' for each line in the input file
    Do While Not oInFile.AtEndOfStream

    ' read the line 
    str_CurrentLine = oInFile.ReadLine()
    str_CurrentLine = Replace(str_CurrentLine, Chr(13), "")
    str_CurrentLine = Replace(str_CurrentLine, Chr(10), "") 
    Lines = Lines+1

' do Team_User

    if Left(str_CurrentLine,5) = "user=" Then
        MyArray = Split(str_CurrentLine,"=",-1,1)
        Team_Name = MyArray(1)
        arrMyTeamName = Split(Team_Name,"_",-1,1)
        if arrMyTeamName(0) = "gd" Then UserName = Team_Name End If
        If arrMyTeamName(0) = "Free-DC" Then UserName = arrMyTeamName(1) End If
        If arrMyTeamName(0) = "AMDUsers" Then UserName = arrMyTeamName(1) End If
        If arrMyTeamName(0) = "ArsTechnica" Then UserName = arrMyTeamName(1) End If
        If arrMyTeamName(0) = "XtremeSystems" Then UserName = arrMyTeamName(1) End If
        If arrMyTeamName(0) = "Team_Italia" Then UserName = arrMyTeamName(1) End If
        If arrMyTeamName(0) = "XGrubbersKickAss" Then UserName = arrMyTeamName(1) End If
        If arrMyTeamName(0) = "Ukraine" Then UserName = arrMyTeamName(1) End If
        If arrMyTeamName(0) = "Singapura" Then UserName = arrMyTeamName(1) End If
        If arrMyTeamName(0) = "RaidersOfTheLostPrime" Then UserName = arrMyTeamName(1) End If
' do Date

    ElseIf Left(str_CurrentLine,1) = "[" Then
        '[08/11/2008 06:55:34 AM]
        MyLine = Split(str_CurrentLine," ", -1, 1 )
        MyDay  = Split(MyLine(0),"/", -1 ,1 )
        MyMO   = Replace( MyDay(0), "[", "" )
        MyDD   = MyDay(1)
        MyYY   = MyDay(2)
        MyTime = Split(MyLine(1),":")
        MyHH   = MyTime(0)
        MyMM   = MyTime(1)
        MySS   = MyTime(2)
        MyAMPM = Replace( MyLine(2), "]", "" )
        if MyAMPM = "AM" and MyHH = "12" Then MyHH = "00" End If
        If MyAMPM = "PM" and MyHH <> "12" Then MyHH = MyHH+12 End If

'do not prime.

    ElseIf inStr(1,str_CurrentLine,"not prime.") Then
        MyDATA = Split(str_CurrentLine," ",-1,1)
        MyK = Split(MyDATA(0),"*",-1,1) ' 305 * 2 ^ 587594 - 1
        MyP = Split(MyK(1),"^",-1,1)    ' 2 
        MyN = Split(MyP(1),"-",-1,1)    ' 587594
        MyD = MyN(1)
        MyRES = MyDATA(6)
        MyT = MyDATA(10)
        str_TXT = "user=" & UserName & VBCrLf &  "[" & MyYY  & "/" & MyMO  & "/" & MyDD & " " & MyHH & ":" & MyMM & ":" & MySS & "]" & VBCrLf & Str_CurrentLine
        str_CSV = UserName & "," & MyYY & "/" & MyMO & "/" & MyDD & "," & MyHH & ":" & MyMM & ":" & MySS & "," & MyK(0) & "," & MyP(0) & "," & MyN(0) & ",-," & MyD & ",0," & MyRES & "," & MyT
        ' output the data to the csv and txt files
        oOutFileTXT.WriteLine(str_TXT)
        oOutFileCSV.WriteLine(str_CSV)
'do prime!

    ElseIf inStr(1,str_CurrentLine,"prime!") Then
        MyDATA = Split(str_CurrentLine," ",-1,1)
        MyK = Split(MyDATA(0),"*",-1,1) ' 305 * 2 ^ 587594 - 1
        MyP = Split(MyK(1),"^",-1,1)    ' 2 
        MyN = Split(MyP(1),"-",-1,1)    ' 587594
        MyD = MyN(1)
        MyT = MyDATA(6)
        str_TXT = "user=" & UserName & VBCrLf & "[" & MyYY  & "/" & MyMO  & "/" & MyDD & " " & MyHH & ":" & MyMM & ":" & MySS & "]" & VBCrLf & Str_CurrentLine
'prime! -                 gd_barnes,11/8/2008,6:04:29,301,2,587635,-,1,1,,515
        str_CSV = UserName & "," & MyYY  & "/" & MyMO  & "/" & MyDD & "," & MyHH & ":" & MyMM & ":" & MySS & "," & MyK(0) & "," & MyP(0) & "," & MyN(0) & ",-," & MyD & ",1," & "," & MyT
        Wscript.echo str_TXT
        oOutFileTXT.WriteLine(str_TXT)
        oOutFileCSV.WriteLine(str_CSV)
'        MsgBox "Prime Found!" & VBCr & "by: " & UserName & VbCr & Str_CurrentLine
    End If

str_CSV=""
str_TXT=""

LOOP

' Close the input and output file

    oInFile.Close
    oOutFileTXT.Close
    oOutFileCSV.Close

' Finished and exit

End IF

' Tidy up and print results

    Set oFSO = Nothing

    Wscript.Echo VbCrLf & "Processed " & Lines & " Lines in " & strFileName & VbCrLf

    Wscript.Quit 0

Last fiddled with by IronBits on 2008-11-11 at 18:29
IronBits is offline   Reply With Quote