Browse Source

header added. Time format moved into a variable. Cleanup.

pull/1/head
Sam Hunter 2 months ago
parent
commit
ed6000d6d6
1 changed files with 11 additions and 6 deletions
  1. +11
    -6
      recent.py

+ 11
- 6
recent.py View File

@ -1,4 +1,9 @@
#!/usr/bin/env python3
# recent.py for rawtext.club by samhunter
# https://git.rawtext.club/samhunter/rtc-shell-scripts/src/branch/master/recent.py
# inspired by:
# https://git.rawtext.club/hannu/recent
import glob
import sys
import os
@ -6,6 +11,7 @@ import time
import datetime
import sqlite3 as sql
import subprocess
def get_files():
services = dict([
('gab','.gab'),
@ -35,6 +41,7 @@ def get_files():
return ret
out = []
timefmt = "%Y-%m-%d %H:%M"
ts = time.time() - (24 * 3600 * 14) # 2 weeks
for d in get_files():
service=d[2]
@ -42,7 +49,7 @@ for d in get_files():
with open(d[0]) as f:
ftim = float(f.readline().split("|")[0])
if ftim > ts:
st = datetime.datetime.fromtimestamp(ftim).strftime('%Y-%m-%d %H:%M')
st = datetime.datetime.fromtimestamp(ftim).strftime(timefmt)
out.append((st,d))
elif service == "gitbbs":
@ -52,12 +59,12 @@ for d in get_files():
#print(e.output)
continue
if ftim > ts:
st = datetime.datetime.fromtimestamp(ftim).strftime('%Y-%m-%d %H:%M')
st = datetime.datetime.fromtimestamp(ftim).strftime(timefmt)
out.append((st,d))
else:
ftim = os.stat(d[0]).st_mtime
if ftim > ts:
st = datetime.datetime.fromtimestamp(ftim).strftime('%Y-%m-%d %H:%M')
st = datetime.datetime.fromtimestamp(ftim).strftime(timefmt)
out.append((st,d))
db_path = '/usr/local/share/cspc/db/cspc'
@ -66,15 +73,13 @@ conn = sql.connect(db_path)
c = conn.cursor()
c.execute(query)
for row in c:
st = datetime.datetime.fromtimestamp(float(row[0])).strftime('%Y-%m-%d %H:%M')
st = datetime.datetime.fromtimestamp(float(row[0])).strftime(timefmt)
out.append((st, ("", row[1],"cspc")))
conn.close()
fmt = "{date:16s} {service:12s} {user:14s}"
for item in sorted(out, reverse=True):
# print(item);
date=item[0]
user=item[1][1]
service=item[1][2]


Loading…
Cancel
Save