Skip to content

Commit ccf6b12

Browse files
authored
feat!: switched config format to toml (#49)
* feat!: switched config format to toml * build(deps): updated aw-client BREAKING CHANGE: changes the config file used
1 parent 2f108d5 commit ccf6b12

File tree

3 files changed

+81
-24
lines changed

3 files changed

+81
-24
lines changed

aw_watcher_afk/afk.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
class Settings:
2828
def __init__(self, config_section):
2929
# Time without input before we're considering the user as AFK
30-
self.timeout = config_section.getfloat("timeout")
30+
self.timeout = config_section["timeout"]
3131
# How often we should poll for input activity
32-
self.poll_time = config_section.getfloat("poll_time")
32+
self.poll_time = config_section["poll_time"]
3333

3434
assert self.timeout >= self.poll_time
3535

@@ -41,7 +41,9 @@ def __init__(self, testing=False):
4141
self.settings = Settings(watcher_config[configsection])
4242

4343
self.client = ActivityWatchClient("aw-watcher-afk", testing=testing)
44-
self.bucketname = "{}_{}".format(self.client.client_name, self.client.client_hostname)
44+
self.bucketname = "{}_{}".format(
45+
self.client.client_name, self.client.client_hostname
46+
)
4547

4648
def ping(self, afk: bool, timestamp: datetime, duration: float = 0):
4749
data = {"status": "afk" if afk else "not-afk"}
@@ -93,7 +95,9 @@ def heartbeat_loop(self):
9395
# Send a heartbeat if no state change was made
9496
else:
9597
if afk:
96-
self.ping(afk, timestamp=last_input, duration=seconds_since_input)
98+
self.ping(
99+
afk, timestamp=last_input, duration=seconds_since_input
100+
)
97101
else:
98102
self.ping(afk, timestamp=last_input)
99103

aw_watcher_afk/config.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
from configparser import ConfigParser
2-
from aw_core.config import load_config
1+
from aw_core.config import load_config_toml
32

4-
default_settings = {
5-
"timeout": "180",
6-
"poll_time": "5",
7-
}
8-
default_testing_settings = {
9-
"timeout": "20",
10-
"poll_time": "1",
11-
}
3+
default_config = """
4+
[aw-watcher-afk]
5+
timeout = 180
6+
poll_time = 5
127
13-
default_config = ConfigParser()
14-
default_config['aw-watcher-afk'] = default_settings
15-
default_config['aw-watcher-afk-testing'] = default_testing_settings
16-
watcher_config = load_config("aw-watcher-afk", default_config)
8+
[aw-watcher-afk-testing]
9+
timeout = 20
10+
poll_time = 1
11+
""".strip()
12+
13+
watcher_config = load_config_toml("aw-watcher-afk", default_config)

poetry.lock

Lines changed: 62 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)