flake setup and fragmented
This commit is contained in:
parent
85ee243f8d
commit
3f658af00f
31
flake.nix
31
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
|
||||
;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
24
pkgs/tuh-activity-logger/default.nix
Normal file
24
pkgs/tuh-activity-logger/default.nix
Normal file
@ -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
|
||||
;
|
||||
};
|
||||
}
|
||||
@ -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()
|
||||
Loading…
x
Reference in New Issue
Block a user