Pandas fetch line from datas into columns

96 views Asked by At

i have a problem with my script. I`ve made a script that fetch some datas from lines of a raw.txt file into columns to excel. Its worked at the beggining but now when i added more datas in the file its not, if you can help me or have another solve.

**This is my script:

import xlrd, xlwt, re
from svnscripts.timestampdirectory import createdir, path_dir
import os
import pandas as pd
import time
def clearcasevobs():
    pathdest = path_dir()
    dest = createdir()
    timestr = time.strftime("%Y-%m-%d")

    txtName = rf"{pathdest}\{timestr}-clearcaseRawData-vobsDetails.txt"
    workBook = xlwt.Workbook(encoding='ascii')
    workSheet = workBook.add_sheet('sheet1')

    fp = open(txtName, 'r+b')

    # header
    workSheet.write(0, 0, "Tag")
    workSheet.write(0, 1, "CreateDate")
    workSheet.write(0, 2, "Created By")
    workSheet.write(0, 3, "Storage Host Pathname")
    workSheet.write(0, 4, "Storage Global Pathname")
    workSheet.write(0, 5, "DB Schema Version")
    workSheet.write(0, 6, "Mod_by_rem_user")
    workSheet.write(0, 7, "Atomic Checkin")
    workSheet.write(0, 8, "Owner user")
    workSheet.write(0, 9, "Owner Group")
    workSheet.write(0, 10, "ACLs enabled")
    workSheet.write(0, 11, "FeatureLevel")

    row = 0
    entries = 0
    fullentry = []
    for linea in fp.readlines():

        str_linea = linea.decode('gb2312', 'ignore')
        str_linea = str_linea[:-2]  # str  string

        txt = str_linea
        arr = str_linea

        if arr[:9] == "versioned":
            txt = arr
            entries += 1
            s = txt.index("/")
            e = txt.index('"', s)
            txt = txt[s:e]
            fullentry.append(txt)

        elif arr.find("created") >= 0:
            entries += 1
            txt = arr
            s = txt.index("created")
            e = txt.index("by")
            txt1 = txt[s + 7:20]
            fullentry.append(txt1)

            txt2 = txt[e + 3:]
            fullentry.append(txt2)

        elif arr.find("VOB storage host:pathname") >= 0:
            entries += 1
            txt = arr
            s = txt.index('"')
            e = txt.index('"', s + 1)
            txt = txt[s + 1:e]
            fullentry.append(txt)

        elif arr.find("VOB storage global pathname") >= 0:
            entries += 1
            txt = arr
            s = txt.index('"')
            e = txt.index('"', s + 1)
            txt = txt[s + 1:e]
            fullentry.append(txt)

        elif arr.find("database schema version:") >= 0:
            entries += 1
            txt = arr
            txt = txt[-2:]
            fullentry.append(txt)

        elif arr.find("modification by remote privileged user:") >= 0:
            entries += 1
            txt = arr
            s = txt.index(':')
            txt = txt[s + 2:]
            fullentry.append(txt)

        elif arr.find("tomic checkin:") >= 0:
            entries += 1
            txt = arr
            s = txt.index(':')
            txt = txt[s + 2:]
            fullentry.append(txt)

        elif arr.find("owner ") >= 0:
            entries += 1
            txt = arr
            s = txt.index('owner')
            txt = txt[s + 5:]
            fullentry.append(txt)

        elif arr.find("group tmn") >= 0:
            if arr.find("tmn/root") == -1:
                entries += 1
                txt = arr
                s = txt.index('group')
                entries += 1
                txt = txt[s + 5:]
                fullentry.append(txt)

        elif arr.find("ACLs enabled:") >= 0:
            entries += 1
            txt = arr
            txt = txt[-2:]
            fullentry.append(txt)

        elif arr.find("FeatureLevel =") >= 0:
            entries += 1
            txt = arr
            txt = txt[-1:]
            fullentry.append(txt)

        if (row == 65536):
            break;

    finalarr = []
    finalarr1 = []
    temp = 0
    row = 1

    for r in fullentry:
        finalarr.append(r)
        temp += 1

        if temp == 12:
            finalarr1.append(finalarr)

            temp = 0

            col = 0
            for arr in finalarr:
                workSheet.write(row, col, arr)
                col += 1
            row += 1
            finalarr.clear()
            if (row == 65536):
                break;

    workBook.save(os.path.join(dest, "ClearcaseReport.xls"))
    fp.close()

This is my file.txt datas(the file that script need to work and doesnt):

https://paste.pythondiscord.com/sedowagigo

This is how should output as excel file::

expected output

Details:

-The script that i did basically should read the datas inside the .txt file and based on the keywords that i put to create the columns and add the wanted datas in the right columns, but also should ignore the sh*t/raw datas dat dont need to be processed.

-First time was working thats why i have also the output photo .xls, but now its not working anymore because i added more datas inside and have more junkies... If someone can help me or you know other method im open to all

This is the old .txt file that i tested the script and works: https://paste.pythondiscord.com/ohewatahuv

This is the error that i received when i use the script on the new file that i attach inside the pastebin at the beggining ( https://paste.pythondiscord.com/sedowagigo ):

error

Ty for help!

0

There are 0 answers