add my.demo for testing out various approaches to configuring

This commit is contained in:
Dima Gerasimov 2020-05-10 21:32:48 +01:00
parent d6f071e3b1
commit 0ac78143f2
4 changed files with 107 additions and 4 deletions

56
my/demo.py Normal file
View file

@ -0,0 +1,56 @@
'''
Just a demo module for testing and documentation purposes
'''
from .core.common import Paths
from datetime import tzinfo
import pytz
from my.config import demo as user_config
from dataclasses import dataclass
@dataclass
class demo(user_config):
data_path: Paths
username: str
timezone: tzinfo = pytz.utc
def config() -> demo:
from .core.cfg import make_config
config = make_config(demo)
return config
from pathlib import Path
from typing import Sequence, Iterable
from datetime import datetime
from .core.common import Json, get_files
@dataclass
class Item:
'''
Some completely arbirary artificial stuff, just for testing
'''
username: str
raw: Json
dt: datetime
def inputs() -> Sequence[Path]:
return get_files(config().data_path)
import json
def items() -> Iterable[Item]:
for f in inputs():
dt = datetime.fromtimestamp(f.stat().st_mtime, tz=config().timezone)
j = json.loads(f.read_text())
for raw in j:
yield Item(
username=config().username,
raw=raw,
dt=dt,
)