Jump to content

[PYTHON] Chatlog reader


666BELLEDELPHINE
 Share

Recommended Posts

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)

Un simplu mod care iti citeste chatlog-ul si iti seteaza cuvantul in clipboard cand il gaseste in chat

merci @monday pentru niste optimizari

Link to comment
Share on other sites

Aolo franzelo, ce limbaj ti-ai gasit si tu sa faci programu asta, desi e unul relativ cautat, nu mi-a placut niciodata din simplul fapt ca nu pot sa-mi fac damblaua sa-mi pun paranteze, acuolade si punct si virgula =)), mna obisnuinta...

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.