Browse Source

Reworks how writes work to make reads a little lower cost

action-support
sloumdrone 3 years ago
parent
commit
c4849ba8e9
  1. 20
      gab

20
gab

@ -13,9 +13,8 @@ def read_file(user, path, num_lines):
global log
if os.path.isfile(path):
with open(path, "r") as f:
lines = f.read().split("\n")[-num_lines:]
for line in lines:
msg = line.split("|", 1)
for line in range(num_lines):
msg = f.readline().split("|", 1)
if len(msg) == 2:
log[msg[0].strip()] = "\033[7m {} \033[0m {}".format(user, msg[1].strip())
@ -71,14 +70,23 @@ def diff_time_from_now(t):
def add_message(msg):
user = os.environ.get('USER')
timestamp = str(time.time())
output = "{}|{}\n".format(timestamp, msg.strip())
fp = "/home/{}/.gab".format(user)
try:
with open(fp, "a") as f:
f.write("{}|{}\n".format(timestamp, msg.strip()))
print("Successfully added text to chatlog")
with open(fp, 'r') as original:
data = original.read(12000)
with open(fp, 'w') as modified:
modified.write(output)
modified.write(data)
except FileNotFoundError:
with open(fp, 'a') as modified:
modified.write(output)
except:
print("Error adding text to chatlog")
return
print("Successfully added text to chatlog")
try:
os.chmod(fp, 0o644)
except PermissionError:

Loading…
Cancel
Save