👔 Add support for dumping and importing
This commit is contained in:
parent
c9ce1bd130
commit
e209036d1f
2 changed files with 9 additions and 3 deletions
1
TODO.md
1
TODO.md
|
@ -1,5 +1,4 @@
|
||||||
# ToDos
|
# ToDos
|
||||||
|
|
||||||
- add support for pickling/unpickling `Voting`
|
|
||||||
- add `click` and provide a user-friendly CLI
|
- add `click` and provide a user-friendly CLI
|
||||||
- add `fastapi` and implement a builtin JSON/REST API server
|
- add `fastapi` and implement a builtin JSON/REST API server
|
||||||
|
|
|
@ -8,7 +8,7 @@ from .quorum import Quorum, QuorumKind
|
||||||
from arrow import Arrow, get as arrow_get
|
from arrow import Arrow, get as arrow_get
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Dict, List
|
from typing import Dict, TextIO, List
|
||||||
|
|
||||||
import abc
|
import abc
|
||||||
import json.tool
|
import json.tool
|
||||||
|
@ -74,10 +74,17 @@ class Voting(object):
|
||||||
def dumps(self) -> str:
|
def dumps(self) -> str:
|
||||||
return json.dumps(self.as_dict())
|
return json.dumps(self.as_dict())
|
||||||
|
|
||||||
|
def dump(self, f: TextIO) -> None:
|
||||||
|
f.write(self.dumps())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def loads(cls, data: Dict):
|
def loads(cls, data: Dict) -> None:
|
||||||
return cls(**json.loads(data))
|
return cls(**json.loads(data))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def load(cls, f: TextIO) -> None:
|
||||||
|
return cls.loads('\n'.join(f.readlines()))
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Result:
|
class Result:
|
||||||
|
|
Loading…
Reference in a new issue