Add the ability to set an intention
This commit is contained in:
@@ -35,6 +35,8 @@ async def run(args: Namespace, config: Config):
|
||||
reply = await interface.call_stop()
|
||||
elif args.pause:
|
||||
reply = await interface.call_pause()
|
||||
elif args.intention is not None:
|
||||
reply = await interface.call_intention(args.intention)
|
||||
elif args.unpause:
|
||||
reply = await interface.call_unpause()
|
||||
elif args.schedule:
|
||||
|
||||
@@ -47,6 +47,7 @@ class State(BaseModel):
|
||||
active_whiteblocks: List[Block] = []
|
||||
inactive_blackblocks: List[Block] = []
|
||||
pause: bool = False
|
||||
intention: str = ''
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
@@ -152,6 +152,13 @@ class AntiDriftDaemon(ServiceInterface):
|
||||
logging.info(m)
|
||||
return m
|
||||
|
||||
@method()
|
||||
def intention(self, intention: 's') -> 's':
|
||||
self.state.intention = intention
|
||||
m = f"Antidrift intention set to '{intention}'"
|
||||
logging.info(m)
|
||||
return m
|
||||
|
||||
@method()
|
||||
def status(self) -> 's':
|
||||
white_active = bool(self.state.active_whiteblocks)
|
||||
@@ -176,6 +183,8 @@ class AntiDriftDaemon(ServiceInterface):
|
||||
m += inactive_bbs
|
||||
case _:
|
||||
m = "inactive"
|
||||
if self.state.intention:
|
||||
m += f" 🎯 {self.state.intention}"
|
||||
return m
|
||||
|
||||
def allow_blackblock(self, blackblock: Block):
|
||||
@@ -186,10 +195,6 @@ class AntiDriftDaemon(ServiceInterface):
|
||||
m = f"Blackblock [sky_blue3]{blackblock.name}[/sky_blue3] is now allowed."
|
||||
logging.info(m)
|
||||
|
||||
def get_intention(self) -> str:
|
||||
s = " ".join(map(lambda b: b.name, self.state.active_whiteblocks))
|
||||
return f"intention is {s} work" if s else "no intention"
|
||||
|
||||
def log_window(self):
|
||||
window = XWindow()
|
||||
utc_timestamp = datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
|
||||
@@ -199,7 +204,7 @@ class AntiDriftDaemon(ServiceInterface):
|
||||
window_name = re.sub(r'\b\d+.\d\d\b', '', window_name)
|
||||
window_name = re.sub(r'[+-]\d+.\d+%', '', window_name)
|
||||
|
||||
intention = self.get_intention()
|
||||
intention = self.state.intention
|
||||
log_line = [utc_timestamp, window_name, window.cls, intention]
|
||||
with self.config.window_log_file.open('a', newline='') as f:
|
||||
writer = csv.writer(f)
|
||||
|
||||
1
main.py
1
main.py
@@ -25,6 +25,7 @@ def get_args():
|
||||
parser = argparse.ArgumentParser(description="AntiDrift CLI.")
|
||||
parser.add_argument("--daemon", action="store_true", help="run daemon")
|
||||
parser.add_argument("--evaluate", action="store_true", help="evaluate day")
|
||||
parser.add_argument("--intention", metavar="intention", help="set intention", default=None, type=str)
|
||||
parser.add_argument("--pause", action="store_true", help="pause antidrift")
|
||||
parser.add_argument("--schedule", metavar="blackblock", help="schedule blackblock")
|
||||
parser.add_argument("--start", metavar="whiteblock", nargs="+", help="start whiteblocks")
|
||||
|
||||
Reference in New Issue
Block a user