pull config from krunnerrc or env

- setup shell
This commit is contained in:
Aaron Bieber 2025-01-16 09:01:14 -07:00
parent 46146d547e
commit 8eec95fd64
No known key found for this signature in database
3 changed files with 41 additions and 4 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use_nix

22
krha.py
View File

@ -1,10 +1,12 @@
#!/usr/bin/python3
import dbus.service
from configparser import ConfigParser
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib
import requests
import dbus.service
import json
import os
import requests
DBusGMainLoop(set_as_default=True)
@ -17,8 +19,22 @@ iface = "org.kde.krunner1"
class Runner(dbus.service.Object):
def __init__(self):
dbus.service.Object.__init__(self, dbus.service.BusName("dev.suah.krha", dbus.SessionBus()), objpath)
config = ConfigParser()
config_path = os.path.expanduser('~/.config/krunnerrc')
config.read(config_path)
try:
self.api_key = config.get('Runners][HomeAssistant', 'api_key')
except:
self.api_key = os.environ.get("HA_API_KEY", "")
self.ha_url = os.environ.get("HA_URL", "").rstrip('/')
try:
self.ha_url = config.get('Runners][HomeAssistant', 'ha_url')
except:
self.ha_url = os.environ.get("HA_URL", "")
if self.ha_url:
self.ha_url = self.ha_url.rstrip('/')
@dbus.service.method(iface, in_signature='s', out_signature='a(sssida{sv})')
def Match(self, query: str):

20
shell.nix Normal file
View File

@ -0,0 +1,20 @@
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
let
pythonEnv = python3.withPackages (
p: with p; [
dbus-python
pygobject3
requests
]
);
in pkgs.mkShell {
shellHook = ''
PS1='\u@\h:\w; '
'';
buildInputs = with pkgs; [
pythonEnv
wrapGAppsHook
gobject-introspection
];
}