add config parser

master
histausse 3 years ago
parent f544d8eef9
commit 1172db1d95
Signed by: histausse
GPG Key ID: 67486F107F62E9E9

@ -0,0 +1,8 @@
---
username: kassandra
homeserver: https://matrix.org
password: beware of greeks bearing gifts
allert_rooms:
- "#troy:matrix.org"
- "#ithaca:matrix.org"
...

@ -12,6 +12,7 @@ packages = kassandra
python_requires = >=3.9.2
package_dir = =src
install_requires =
PyYAML>=5.4.1
matrix-bot @ git+https://gitea.auro.re/histausse/matrix-bot.git
[options.package_data]

@ -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…
Cancel
Save