APP Release chatlog reader

belle_delphine.py

Active member
Joined
Jul 28, 2019
Messages
46
Reaction score
11
Location
Sibiu
just a small script that reads the chatlog and when it detects a word that is in cuv_cap(type = Dictionary) it sets to clipboard the key/value..made in python 3..i was bored
@monday helped me with sum things <3

Python:
import pyperclip, time, getpass
from os.path import getsize
from pathlib import Path


username = getpass.getuser()
path = Path('C:\\Users\\'+ username + '\\Documents\\GTA San Andreas User Files\\SAMP\\chatlog.txt')



if path.is_file():
    print(path.is_file())
    print(f"Heyy {username}")
else:
    path = input('Chatlog directory path > ')


cuv_cap = {

     'virgin' : 'me',
     'Romania' : 'Bucuresti',
     'gay' : 'user88',
     'BMW' : 'i8',
     'ugbase' : 'nothin'

    }
custom_pref = input('custom prefix[blank = no prefix]: ')


def chatEntry(custom_pref):
   
    if not custom_pref or custom_pref in ['no', 'nu', 'n'] :
        return None
    elif custom_pref:
        return custom_pref

chatEntry(custom_pref)


def read_lines(path):
    if getsize(path) > 0:
        with open(path, 'r+') as chatlog:
            for line in chatlog:
                for cuv, cap in cuv_cap.items():
                    if cuv in line:
                        print(f"Key: [{cuv}] Value: [{cap}] --> PRINT{[cap]}")
                        print(line)
                       
                        pyperclip.copy(chatEntry(custom_pref) + " " + cap)
                        pyperclip.paste()
                        chatlog.truncate(0)
                   

                    if cap in line:
                        print(f"Value: [{cap}] Key: [{cuv}] --> PRINT{[cuv]}")
                        print(line)

                        pyperclip.copy(chatEntry(custom_pref) + " " + cuv)
                        pyperclip.paste()
                        chatlog.truncate(0)



while True:
    try:
        read_lines(path)
    except PermissionError:
        pass
    except FileNotFoundError:
        raise Exception("PathError: Path(chatlog.txt) is WRONG")
    time.sleep(0.2)
 
Last edited:

belle_delphine.py

Active member
Joined
Jul 28, 2019
Messages
46
Reaction score
11
Location
Sibiu
better way to read the last line from chatlog without truncating it ...
Python:
import getpass, os, re
from os.path import isfile
from pathlib import Path


def getUserPath():
    return Path('C:\\Users\\'+ getUserNameD() + '\\Documents\\GTA San Andreas User Files\\SAMP\\chatlog.txt')

    

def getUserNameD():
    return getpass.getuser()


def checkUserFilePathD(filepath): #debug
    if isfile(filepath): return True
    else: raise Exception('wrong path file')





def read_lines(path):

    chatlog_lines = []

    with open(path, 'rb') as chatlog_obj:

        chatlog_obj.seek(0, os.SEEK_END)

        buffer = bytearray()

        p_location = chatlog_obj.tell()

        while p_location >= 0:

            chatlog_obj.seek(p_location)

            p_location = p_location -1

            l_byte = chatlog_obj.read(1)

            if l_byte == b'\n':

                chatlog_lines.append(buffer.decode()[::-1])

                if len(chatlog_lines) == 2:

                    return list(reversed(chatlog_lines))

                buffer = bytearray()

            else:

                buffer.extend(l_byte)
 
        if len(buffer) > 0:

            list_of_lines.append(buffer.decode()[::-1])
            
    return list(reversed(chatlog_lines))


path = getUserPath()
last_line = read_lines(path)[0][11:].rstrip()
last_line = re.sub(r"(\s?\{[A-F0-9]{6}\}\s?)", "", last_line)
 
Top