add config parser
parent
f544d8eef9
commit
1172db1d95
@ -0,0 +1,8 @@
|
||||
---
|
||||
username: kassandra
|
||||
homeserver: https://matrix.org
|
||||
password: beware of greeks bearing gifts
|
||||
allert_rooms:
|
||||
- "#troy:matrix.org"
|
||||
- "#ithaca:matrix.org"
|
||||
...
|
@ -0,0 +1,14 @@
|
||||
import argparse
|
||||
import asyncio
|
||||
|
||||
from .config import load_config
|
||||
|
||||
async def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-c", "--config", default="config.yaml")
|
||||
args = parser.parse_args()
|
||||
config = load_config(args.config)
|
||||
print(config)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
@ -0,0 +1,22 @@
|
||||
"""
|
||||
Config related tools.
|
||||
"""
|
||||
|
||||
import dataclasses
|
||||
import yaml
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Config:
|
||||
username: str
|
||||
homeserver: str
|
||||
password: str
|
||||
allert_rooms: list[str]
|
||||
|
||||
def load_config(file:str)->Config:
|
||||
"""
|
||||
Load the config from the config file.
|
||||
"""
|
||||
with open(file, 'r') as f:
|
||||
data = yaml.load(f, Loader=yaml.loader.SafeLoader)
|
||||
return Config(**data)
|
||||
|
Loading…
Reference in New Issue