-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathconfig_schema.py
More file actions
71 lines (54 loc) · 2.07 KB
/
config_schema.py
File metadata and controls
71 lines (54 loc) · 2.07 KB
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
"""Configuration schema definitions.
This module defines Pydantic models for validating and
parsing the application configuration, including Reddit
credentials, notification templates, and subreddit filters.
"""
from typing import List, Dict, Optional
from pydantic import BaseModel
from pydantic_yaml import parse_yaml_raw_as
class SubredditConfig(BaseModel):
"""Configuration for filtering subreddit content.
Attributes:
title: List of strings to match against submission titles.
not_title: List of strings that should not appear in titles.
flair: List of strings to match against submission flairs.
not_flair: List of strings that should not appear in flairs.
"""
title: Optional[List[str]] = []
not_title: Optional[List[str]] = []
flair: Optional[List[str]] = []
not_flair: Optional[List[str]] = []
class RedditConfig(BaseModel):
"""Reddit API and subreddit configuration.
Attributes:
client: Reddit API client ID.
secret: Reddit API secret key.
agent: User agent string for API requests.
notification_title: Template for notification titles.
notification_body: Template for notification bodies.
subreddits: List of subreddit filter configurations.
"""
client: str
secret: str
agent: str
notification_title: Optional[str] = "{SUBREDDIT} - {TITLE}"
notification_body: Optional[str] = "{URL}"
subreddits: List[Dict[str, SubredditConfig]]
class Config(BaseModel):
"""Top-level application configuration.
Attributes:
apprise: List of Apprise notification endpoints.
reddit: Reddit API and subreddit configuration.
"""
apprise: List[str]
reddit: RedditConfig
@classmethod
def from_yaml(cls, path: str) -> "Config":
"""Load configuration from a YAML file.
Args:
path: Path to the YAML configuration file.
Returns:
Config: Parsed configuration object.
"""
with open(path, "r", encoding="utf-8") as f:
return parse_yaml_raw_as(Config, f.read())