from pymongo import MongoClient client = MongoClient() db = client.deskmeter state = db.state def update_current_task(task): state.update_one( {"_id": "current_task"}, {"$set": {"task": task}}, upsert=True, ) def update_current_workspace(workspace): state.update_one( {"_id": "current_workspace"}, {"$set": {"workspace": workspace}}, upsert=True, ) def get_current_task(): current_task = state.find_one({"_id": "current_task"}) if current_task: return current_task.get("task") return None def get_current_workspace(): current_workspace = state.find_one({"_id": "current_workspace"}) if current_workspace: return current_workspace.get("workspace") return None