Created
February 12, 2017 01:37
-
-
Save mddub/25148a3e4cef8635d1c7fa302f181243 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import os | |
import re | |
import sys | |
from collections import defaultdict | |
from datetime import timedelta | |
import sqlite3 | |
from dateutil.parser import parser | |
date_parser = parser() | |
SQLITE_DB = '/Users/mark/.selfspy/selfspy.sqlite' | |
SCREENSHOTS_PATH = '/Users/mark/Library/Application Support/LifeSlice/screenshot_thumbs' | |
#IMG_STYLE = 'max-height: 45px; max-width: 80px;' | |
IMG_STYLE = 'max-height: 68px; max-width: 120px;' | |
DIV_STYLE = 'display: none; top: 68px; left: 0px; width: 400px; min-height: 100px; font-size: 14px; background: beige; position: absolute; z-index: 999;' | |
if len(sys.argv) > 1: | |
date_str = sys.argv[1] | |
date = date_parser.parse(date_str).date() | |
else: | |
today = datetime.datetime.now() | |
date = datetime.date(today.year, today.month, today.day) | |
files = os.listdir(SCREENSHOTS_PATH) | |
matches = filter(None, [re.match('screen_' + date.strftime('%Y-%m-%d') + 'T(\d\d)-(\d\d)-(\d\d)Z(-\d{4})\.png', f) for f in files]) | |
hour_minute_to_screenshot = {} | |
for match in matches: | |
filename = match.group() | |
hour, minute, second, offset = match.groups() | |
hour, minute, second = map(int, (hour, minute, second)) | |
hour_minute_to_screenshot[(hour, minute)] = filename | |
if False: | |
hour_minute_to_window_titles = defaultdict(list) | |
conn = sqlite3.connect(SQLITE_DB) | |
conn.row_factory = sqlite3.Row | |
query = 'select * from window inner join process on window.process_id = process.id' | |
query += ' where window.created_at >= datetime("' + date.strftime('%Y-%m-%d') + '")' | |
query += ' and window.created_at < datetime("' + (date + timedelta(days=1)).strftime('%Y-%m-%d') + '")' | |
windows_today = conn.execute(query).fetchall() | |
for window in windows_today: | |
_, created_at_str, title, _, _ , _, process_name = window | |
created_at = date_parser.parse(created_at_str) | |
hour_minute_to_window_titles[(created_at.hour, 5 * (created_at.minute / 5))].append('%s %s %s' % (created_at, process_name, title)) | |
print '<meta charset="utf-8">' | |
print '<table><tr><td></td>' | |
for m in range(0, 60, 5): | |
print '<th>%s</th>' % m | |
print '</tr>' | |
for h in range(24): | |
print '<tr>' | |
print '<th>%s</th>' % h | |
for m in range(0, 60, 5): | |
dom_id = 'windows-%02d%02d' % (h, m) | |
mouseover, mouseout = ['document.querySelector(\'#' + dom_id + '\').style.display = \'%s\';' % d for d in ('inherit', 'none')] | |
print '<td style="position: relative;">' | |
if (h, m) in hour_minute_to_screenshot: | |
print '<img src="{src}" style="{style}" onmouseover="{mouseover}" onmouseout="{mouseout}">'.format( | |
src=SCREENSHOTS_PATH + '/' + hour_minute_to_screenshot[(h, m)], | |
style=IMG_STYLE, | |
mouseover=mouseover, | |
mouseout=mouseout, | |
) | |
print '<div id="' + dom_id + '" style="' + DIV_STYLE + '">' | |
if False: | |
for window in hour_minute_to_window_titles[(h, m)]: | |
print window.encode('UTF-8') + '<br>' | |
print '</div>' | |
print '</td>' | |
print '</tr>' | |
print '</table>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment