add config parser
This commit is contained in:
parent
f544d8eef9
commit
1172db1d95
4 changed files with 45 additions and 0 deletions
8
config.yaml.exp
Normal file
8
config.yaml.exp
Normal file
|
@ -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]
|
||||
|
|
14
src/kassandra/__main__.py
Normal file
14
src/kassandra/__main__.py
Normal file
|
@ -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())
|
22
src/kassandra/config.py
Normal file
22
src/kassandra/config.py
Normal file
|
@ -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 a new issue