formatting guidelines
This commit is contained in:
parent
b866ab25b6
commit
305f9cf491
1 changed files with 27 additions and 17 deletions
|
@ -4,6 +4,7 @@
|
|||
Module for ActivityWatch (https://activitywatch.net/)
|
||||
Displays the amount of time the system was used actively
|
||||
"""
|
||||
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
|
@ -14,28 +15,32 @@ import core.widget
|
|||
class Module(core.module.Module):
|
||||
def __init__(self, config, theme):
|
||||
super().__init__(config, theme, core.widget.Widget(self.output))
|
||||
self.__uptime = ""
|
||||
self.__usage = ""
|
||||
|
||||
def output(self, _):
|
||||
return "{}".format(self.__uptime)
|
||||
return "{}".format(self.__usage)
|
||||
|
||||
def update(self):
|
||||
database_loc = self.parameter('database', '~/.local/share/activitywatch/aw-server/peewee-sqlite.v2.db')
|
||||
home = os.path.expanduser('~')
|
||||
database_loc = self.parameter(
|
||||
"database", "~/.local/share/activitywatch/aw-server/peewee-sqlite.v2.db"
|
||||
)
|
||||
home = os.path.expanduser("~")
|
||||
|
||||
database = sqlite3.connect(database_loc.replace('~', home))
|
||||
database = sqlite3.connect(database_loc.replace("~", home))
|
||||
cursor = database.cursor()
|
||||
|
||||
cursor.execute('SELECT key, id FROM bucketmodel')
|
||||
cursor.execute("SELECT key, id FROM bucketmodel")
|
||||
|
||||
bucket_id = 1
|
||||
|
||||
for tuple in cursor.fetchall():
|
||||
if 'aw-watcher-afk' in tuple[1]:
|
||||
if "aw-watcher-afk" in tuple[1]:
|
||||
bucket_id = tuple[0]
|
||||
|
||||
cursor.execute(f'SELECT duration, datastr FROM eventmodel WHERE bucket_id = {bucket_id} ' +
|
||||
'AND strftime(\'%Y,%m,%d\', timestamp) = strftime(\'%Y,%m,%d\', \'now\')')
|
||||
cursor.execute(
|
||||
f"SELECT duration, datastr FROM eventmodel WHERE bucket_id = {bucket_id} "
|
||||
+ 'AND strftime("%Y,%m,%d", timestamp) = strftime("%Y,%m,%d", "now")'
|
||||
)
|
||||
|
||||
duration = 0
|
||||
|
||||
|
@ -43,11 +48,16 @@ class Module(core.module.Module):
|
|||
if '{"status": "not-afk"}' in tuple[1]:
|
||||
duration += tuple[0]
|
||||
|
||||
hours = '%.0f' % (duration // 3600)
|
||||
minutes = '%.0f' % ((duration % 3600) // 60)
|
||||
seconds = '%.0f' % (duration % 60)
|
||||
hours = "%.0f" % (duration // 3600)
|
||||
minutes = "%.0f" % ((duration % 3600) // 60)
|
||||
seconds = "%.0f" % (duration % 60)
|
||||
|
||||
formatting = self.parameter("format", "HHh, MMmin")
|
||||
self.__usage = (
|
||||
formatting.replace("HH", hours)
|
||||
.replace("MM", minutes)
|
||||
.replace("SS", seconds)
|
||||
)
|
||||
|
||||
formatting = self.parameter('format', 'HHh, MMmin')
|
||||
self.__uptime = formatting.replace('HH', hours).replace('MM', minutes).replace('SS', seconds)
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
Loading…
Reference in a new issue