Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Activity tracker
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Saswat
Activity tracker
Commits
5c5d8e1c
Commit
5c5d8e1c
authored
Nov 22, 2022
by
Saswat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add logger
parent
513726a9
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
25 additions
and
16 deletions
+25
-16
Makefile
Makefile
+2
-2
README.md
README.md
+1
-0
src/dbhandler.py
src/dbhandler.py
+3
-5
src/gui.py
src/gui.py
+2
-0
src/plotter.py
src/plotter.py
+1
-1
src/trackingdaemon.py
src/trackingdaemon.py
+2
-3
src/utils.py
src/utils.py
+14
-5
No files found.
Makefile
View file @
5c5d8e1c
...
...
@@ -40,10 +40,10 @@ $(VENV)/bin/activate: requirements.txt
run
:
daemon gui
daemon
:
$(DAEMON) $(UTILS)
$(PYTHON)
src/trackingdaemon.py
-d
-i
10 &> log/deamon.log &
$(PYTHON)
src/trackingdaemon.py
-d
-i
$(INTERVAL)
gui
:
$(GUI) $(UTILS)
$(PYTHON)
src/gui.py
-d
&> deamon.log
$(PYTHON)
src/gui.py
-d
pkg
:
dist/ActivityTracker dist/ActivityTrackerd $(PKGS_UTILS)
@
echo
Building Package
...
...
README.md
View file @
5c5d8e1c
...
...
@@ -30,6 +30,7 @@ make daemon interval=10
Data is dumped to the databse only after an event is detected after the interval of 10 sec.
Logs about the data being dumped into the database can be seen in
`log/daemon.log`
.
### Run GUI
In a duplicate terminal we will open the GUI.
The GUI utility to visualise the activity data can also be started using makefile.
```
bash
make gui
...
...
src/dbhandler.py
View file @
5c5d8e1c
import
sqlite3
from
datetime
import
datetime
,
timedelta
import
sys
import
utils
class
DBHandler
:
"""
...
...
@@ -48,8 +49,7 @@ class DBHandler:
print
(
"All data in activity table"
)
cursor
=
self
.
conn
.
execute
(
"SELECT * from ACTIVITY "
)
for
row
in
cursor
:
print
(
row
)
sys
.
stdout
.
flush
()
utils
.
logger
.
log
(
row
)
return
def
write_interval
(
self
,
interval_start
,
app_name
,
duration
):
...
...
@@ -57,8 +57,7 @@ class DBHandler:
Write an entry for the amount of time an application was active in an interval.
"""
query
=
f
"INSERT INTO activity VALUES ({interval_start}, '{app_name}', {duration})"
print
(
query
)
sys
.
stdout
.
flush
()
utils
.
logger
.
log
(
query
)
self
.
conn
.
execute
(
query
)
self
.
conn
.
commit
()
...
...
@@ -67,7 +66,6 @@ class DBHandler:
Provided a date instance return all data present corresponding the whole week
for the date.
"""
sys
.
stdout
.
flush
()
date
=
datetime
(
date
.
year
,
date
.
month
,
date
.
day
,
0
,
0
,
0
)
start
=
date
-
timedelta
(
days
=
date
.
weekday
())
end
=
start
+
timedelta
(
days
=
7
)
...
...
src/gui.py
View file @
5c5d8e1c
...
...
@@ -7,6 +7,7 @@ from tkinter.ttk import *
from
tkcalendar
import
DateEntry
import
sys
import
getopt
import
utils
DEBUG
=
False
...
...
@@ -169,5 +170,6 @@ if __name__ == '__main__':
Execution starts from here, Creating a ActivityTracker object, then it is set on mainloop().
"""
parse_cmdargs
()
utils
.
logger
.
is_debug
=
DEBUG
tracker
=
ActivityTracker
(
DEBUG
)
tracker
.
root
.
mainloop
()
\ No newline at end of file
src/plotter.py
View file @
5c5d8e1c
...
...
@@ -147,5 +147,5 @@ class ActivityPlotter:
week_fig
,
screen_time_text
=
self
.
__get_week_plot
()
day_fig
=
self
.
__get_day_plot
()
app_fig
=
self
.
__get_app_plot
()
print
(
self
.
curr_date
,
screen_time_text
)
utils
.
logger
.
log
(
f
"{self.curr_date}, {screen_time_text}"
)
return
week_fig
,
day_fig
,
app_fig
,
screen_time_text
src/trackingdaemon.py
View file @
5c5d8e1c
...
...
@@ -201,11 +201,10 @@ if __name__ == '__main__':
parse_cmdargs
()
signal
.
signal
(
signal
.
SIGINT
,
signal_handler
)
signal
.
signal
(
signal
.
SIGTERM
,
signal_handler
)
utils
.
logger
.
is_debug
=
DEBUG
utils
.
logger
.
log
(
f
"Current deamon pid: {os.getpid()}"
)
print
(
"Current deamon pid:"
,
os
.
getpid
())
sys
.
stdout
.
flush
()
event_handler
=
init_eventhandler
()
event_fetcher
=
EventFetcher
()
while
True
:
event_fetcher
.
handle_xevent
()
\ No newline at end of file
src/utils.py
View file @
5c5d8e1c
...
...
@@ -25,13 +25,22 @@ def get_db_path(debug):
if
debug
:
if
os
.
path
.
exists
(
os
.
path
.
dirname
(
DEV_DB_PATH
))
==
False
:
os
.
mkdir
(
os
.
path
.
dirname
(
DEV_DB_PATH
))
print
(
"Using DB file: "
,
DEV_DB_PATH
)
sys
.
stdout
.
flush
()
logger
.
log
(
f
"Using DB file: {DEV_DB_PATH}"
)
return
DEV_DB_PATH
else
:
if
os
.
path
.
exists
(
os
.
path
.
dirname
(
DB_PATH
))
==
False
:
os
.
mkdir
(
os
.
path
.
dirname
(
DB_PATH
))
print
(
"Using DB file: "
,
DB_PATH
)
sys
.
stdout
.
flush
()
logger
.
log
(
f
"Using DB file: {DB_PATH}"
)
return
DB_PATH
class
Logger
:
def
__init__
(
self
)
->
None
:
self
.
is_debug
=
False
def
log
(
self
,
text
):
if
self
.
is_debug
:
print
(
text
)
sys
.
stdout
.
flush
()
logger
=
Logger
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment