/
classes.py
83 lines (76 loc) · 2.41 KB
/
classes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
Default classes
Taken from default classes in aw-webui
"""
import logging
import random
from typing import (
Any,
Dict,
List,
Tuple,
)
import aw_client
logger = logging.getLogger(__name__)
CategoryId = List[str]
CategorySpec = Dict[str, Any]
default_classes: List[Tuple[CategoryId, CategorySpec]] = [
(["Work"], {"type": "regex", "regex": "Google Docs|libreoffice|ReText"}),
(
["Work", "Programming"],
{
"type": "regex",
"regex": "GitHub|Stack Overflow|BitBucket|Gitlab|vim|Spyder|kate|Ghidra|Scite",
},
),
(
["Work", "Programming", "ActivityWatch"],
{"type": "regex", "regex": "ActivityWatch|aw-", "ignore_case": True},
),
(["Work", "Image"], {"type": "regex", "regex": "Gimp|Inkscape"}),
(["Work", "Video"], {"type": "regex", "regex": "Kdenlive"}),
(["Work", "Audio"], {"type": "regex", "regex": "Audacity"}),
(["Work", "3D"], {"type": "regex", "regex": "Blender"}),
(["Media", "Games"], {"type": "regex", "regex": "Minecraft|RimWorld"}),
(["Media", "Video"], {"type": "regex", "regex": "YouTube|Plex|VLC"}),
(
["Media", "Social Media"],
{
"type": "regex",
"regex": "reddit|Facebook|Twitter|Instagram|devRant",
"ignore_case": True,
},
),
(
["Media", "Music"],
{"type": "regex", "regex": "Spotify|Deezer", "ignore_case": True},
),
(
["Comms", "IM"],
{
"type": "regex",
"regex": "Messenger|Telegram|Signal|WhatsApp|Rambox|Slack|Riot|Discord|Nheko",
},
),
(
["Comms", "Email"],
{"type": "regex", "regex": "Gmail|Thunderbird|mutt|alpine"},
),
]
def get_classes() -> List[Tuple[List[str], dict]]:
"""
Get classes from server-side settings.
Might throw a 404 if not set yet, in which case we use the default classes as a fallback.
"""
# NOTE: Always tries to fetch from prod server,
# which is potentially wrong if testing server is being used.
awc = aw_client.ActivityWatchClient(f"get-setting-{random.randint(0, 10000)}")
try:
classes = awc.get_setting("classes")
except Exception:
logger.warning(
"Failed to get classes from server, using default classes as fallback"
)
return default_classes
# map into list of tuples
return [(v["name"], v["rule"]) for v in classes]