Added checking for new posts since last login

This commit is contained in:
sloumdrone 2018-12-20 19:48:04 -08:00
parent 95a0b0573d
commit e7c0605f01
1 changed files with 41 additions and 3 deletions

44
cspc.py
View File

@ -6,6 +6,7 @@ import sqlite3 as sql
import datetime, time
import subprocess
import readline
import signal
class c:
black = ''
@ -29,7 +30,7 @@ topic = None
post = None
available_ids = []
messages = []
last_log = False
def go_back():
global post
@ -131,6 +132,7 @@ def parse_command(com):
elif com == 'help':
show_help()
elif com in ['quit', 'q', 'exit']:
set_last_log()
sys.exit(0)
elif com == 'add':
make_add()
@ -204,7 +206,11 @@ def get_posts():
title = row[1]
if len(title) > 35:
title = '{}...'.format(title[:32])
print('({:^4}) {:35} {:12} {:18}'.format(row[0], title, row[2], dtime))
if last_log > row[3]:
print('({:^4}) {:35} {:12} {:18}'.format(row[0], title, row[2], dtime))
else:
print('({:^4}) {:35} {:12} {}{:18}{}'.format(row[0], title, row[2], c.green, dtime, c.end))
return True
@ -221,7 +227,11 @@ def get_topics():
title = row[0]
if len(title) > 35:
title = '{}...'.format(title[:32])
print('({:^4}) {}{:35}{} {:18}'.format(row[2], c.cyan, title, c.end, dtime))
if last_log > row[1]:
print('({:^4}) {}{:35}{} {:18}'.format(row[2], c.cyan, title, c.end, dtime))
else:
print('({:^4}) {}{:35} {}{:18}{}'.format(row[2], c.cyan, title, c.green, dtime, c.end))
return True
@ -278,6 +288,32 @@ def add_to_db(action, data):
tupdate = update_time(utime)
return True
def get_last_log():
global last_log
filepath = '{}/.cspc'.format(userdir)
if not os.path.isfile(filepath):
with open(filepath, 'w') as f:
current = int(time.time())
f.write(str(current))
with open(filepath, 'r') as f:
data = f.read()
try:
last_log = int(data)
except:
last_log = False
def set_last_log():
filepath = '{}/.cspc'.format(userdir)
with open(filepath, 'w') as f:
current = int(time.time())
f.write(str(current))
#------- Main loop --------#
def mainloop():
@ -301,5 +337,7 @@ def mainloop():
if __name__ == '__main__':
signal.signal(signal.SIGINT, signal.SIG_IGN)
check_and_build_db()
get_last_log()
mainloop()