diff --git a/flake.nix b/flake.nix index 8a66fd1..d49609d 100644 --- a/flake.nix +++ b/flake.nix @@ -1,33 +1,18 @@ { description = "Nix flake for the activity logging script"; - outputs = - { self, nixpkgs }: + { self, nixpkgs, ... }@inputs: { - packages.x86_64-linux.tuh-activity-logger = + packages.x86_64-linux = let - pname = "tuh-activity-logger"; - version = "1.0"; - pkgs = import nixpkgs { system = "x86_64-linux"; }; + inherit (self) outputs; + system = "x86_64-linux"; + pkgs = import nixpkgs { inherit system; }; in - pkgs.python3Packages.buildPythonApplication { - inherit pname version; - src = builtins.path { - path = ./tuhmayto/.; - name = "${pname}-${version}"; + { + tuh-activity-logger = import ./pkgs/tuh-activity-logger/default.nix { + inherit (pkgs) python3Packages sqlite; }; - build-system = [ pkgs.python3Packages.setuptools ]; - dependencies = - [ - pkgs.sqlite - ] - ++ builtins.attrValues { - inherit (pkgs.python3Packages) - beautifulsoup4 - requests - matplotlib - ; - }; }; }; } diff --git a/pkgs/tuh-activity-logger/default.nix b/pkgs/tuh-activity-logger/default.nix new file mode 100644 index 0000000..6f49e27 --- /dev/null +++ b/pkgs/tuh-activity-logger/default.nix @@ -0,0 +1,24 @@ +{ python3Packages, sqlite, ... }: +let + pname = "tuh-activity-logger"; + version = "1.0"; +in +python3Packages.buildPythonApplication { + inherit pname version; + src = builtins.path { + path = ../../source/tuhmayto/.; + name = "${pname}-${version}"; + }; + build-system = [ python3Packages.setuptools ]; + dependencies = + [ + sqlite + ] + ++ builtins.attrValues { + inherit (python3Packages) + beautifulsoup4 + requests + matplotlib + ; + }; +} diff --git a/tuhmayto/.envrc b/source/tuhmayto/.envrc similarity index 100% rename from tuhmayto/.envrc rename to source/tuhmayto/.envrc diff --git a/tuhmayto/chart.html b/source/tuhmayto/chart.html similarity index 100% rename from tuhmayto/chart.html rename to source/tuhmayto/chart.html diff --git a/tuhmayto/dummy.sql b/source/tuhmayto/dummy.sql similarity index 100% rename from tuhmayto/dummy.sql rename to source/tuhmayto/dummy.sql diff --git a/tuhmayto/export_json.py b/source/tuhmayto/export_json.py similarity index 100% rename from tuhmayto/export_json.py rename to source/tuhmayto/export_json.py diff --git a/tuhmayto/logs.py b/source/tuhmayto/logs.py similarity index 100% rename from tuhmayto/logs.py rename to source/tuhmayto/logs.py diff --git a/tuhmayto/setup.cfg b/source/tuhmayto/setup.cfg similarity index 100% rename from tuhmayto/setup.cfg rename to source/tuhmayto/setup.cfg diff --git a/tuhmayto/setup.py b/source/tuhmayto/setup.py similarity index 100% rename from tuhmayto/setup.py rename to source/tuhmayto/setup.py diff --git a/tuhmayto/shell.nix b/source/tuhmayto/shell.nix similarity index 100% rename from tuhmayto/shell.nix rename to source/tuhmayto/shell.nix diff --git a/tuhmayto/tracker.py b/source/tuhmayto/tracker.py similarity index 94% rename from tuhmayto/tracker.py rename to source/tuhmayto/tracker.py index 9cbe168..31ce86a 100644 --- a/tuhmayto/tracker.py +++ b/source/tuhmayto/tracker.py @@ -4,9 +4,11 @@ import sqlite3 import requests from bs4 import BeautifulSoup +DB_FILE = "/home/jawz/.config/jawz/tuh_online_log.db" + def setup_database() -> None: - conn = sqlite3.connect("activity_log.db") + conn = sqlite3.connect(DB_FILE) cursor = conn.cursor() cursor.execute( """ @@ -21,7 +23,7 @@ def setup_database() -> None: def log_activity(timestamp: str) -> None: - conn = sqlite3.connect("activity_log.db") + conn = sqlite3.connect(DB_FILE) cursor = conn.cursor() cursor.execute( "INSERT OR IGNORE INTO activity_log (timestamp) VALUES (?)", (timestamp,) @@ -31,7 +33,7 @@ def log_activity(timestamp: str) -> None: def fetch_latest_log() -> datetime | None: - conn = sqlite3.connect("activity_log.db") + conn = sqlite3.connect(DB_FILE) cursor = conn.cursor() cursor.execute("SELECT timestamp FROM activity_log ORDER BY timestamp DESC LIMIT 1") result = cursor.fetchone()