flake setup and fragmented
This commit is contained in:
parent
85ee243f8d
commit
3f658af00f
31
flake.nix
31
flake.nix
@ -1,32 +1,17 @@
|
|||||||
{
|
{
|
||||||
description = "Nix flake for the activity logging script";
|
description = "Nix flake for the activity logging script";
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
{ self, nixpkgs }:
|
{ self, nixpkgs, ... }@inputs:
|
||||||
{
|
{
|
||||||
packages.x86_64-linux.tuh-activity-logger =
|
packages.x86_64-linux =
|
||||||
let
|
let
|
||||||
pname = "tuh-activity-logger";
|
inherit (self) outputs;
|
||||||
version = "1.0";
|
system = "x86_64-linux";
|
||||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
pkgs = import nixpkgs { inherit system; };
|
||||||
in
|
in
|
||||||
pkgs.python3Packages.buildPythonApplication {
|
{
|
||||||
inherit pname version;
|
tuh-activity-logger = import ./pkgs/tuh-activity-logger/default.nix {
|
||||||
src = builtins.path {
|
inherit (pkgs) python3Packages sqlite;
|
||||||
path = ./tuhmayto/.;
|
|
||||||
name = "${pname}-${version}";
|
|
||||||
};
|
|
||||||
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
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
DB_FILE = "/home/jawz/.config/jawz/tuh_online_log.db"
|
||||||
|
|
||||||
|
|
||||||
def setup_database() -> None:
|
def setup_database() -> None:
|
||||||
conn = sqlite3.connect("activity_log.db")
|
conn = sqlite3.connect(DB_FILE)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"""
|
"""
|
||||||
@ -21,7 +23,7 @@ def setup_database() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def log_activity(timestamp: str) -> None:
|
def log_activity(timestamp: str) -> None:
|
||||||
conn = sqlite3.connect("activity_log.db")
|
conn = sqlite3.connect(DB_FILE)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"INSERT OR IGNORE INTO activity_log (timestamp) VALUES (?)", (timestamp,)
|
"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:
|
def fetch_latest_log() -> datetime | None:
|
||||||
conn = sqlite3.connect("activity_log.db")
|
conn = sqlite3.connect(DB_FILE)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("SELECT timestamp FROM activity_log ORDER BY timestamp DESC LIMIT 1")
|
cursor.execute("SELECT timestamp FROM activity_log ORDER BY timestamp DESC LIMIT 1")
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
Loading…
x
Reference in New Issue
Block a user