Add LexiconModel
This commit is contained in:
parent
34d3a08416
commit
01c5df1e5d
|
@ -0,0 +1,27 @@
|
|||
import os
|
||||
import time
|
||||
|
||||
import config
|
||||
|
||||
class LexiconModel():
|
||||
"""
|
||||
"""
|
||||
def __init__(self, lid):
|
||||
if not os.path.isdir(config.prepend('lexicon', lid)):
|
||||
raise ValueError("No lexicon with lid {}".format(lid))
|
||||
if not os.path.isfile(config.prepend('lexicon', lid, 'config.json')):
|
||||
raise FileNotFoundError("Lexicon {} missing config.json".format(lid))
|
||||
self.id = str(lid)
|
||||
self.config_path = config.prepend('lexicon', lid, 'config.json')
|
||||
with config.json_ro(self.config_path) as j:
|
||||
self.config = j
|
||||
|
||||
def __getattr__(self, key):
|
||||
if key not in self.config:
|
||||
raise AttributeError(key)
|
||||
return self.config.get(key)
|
||||
|
||||
def log(self, message):
|
||||
now = int(time.time())
|
||||
with config.json_rw(self.config_path) as j:
|
||||
j['log'].append([now, message])
|
|
@ -2,6 +2,10 @@
|
|||
"lid": null,
|
||||
"name": null,
|
||||
"editor": null,
|
||||
"time": {
|
||||
"created": null,
|
||||
"completed": null
|
||||
},
|
||||
"turn": {
|
||||
"current": null,
|
||||
"start": 1,
|
||||
|
@ -10,7 +14,7 @@
|
|||
}
|
||||
},
|
||||
"join": {
|
||||
"open": true,
|
||||
"open": false,
|
||||
"password": null,
|
||||
"max_players": 4
|
||||
},
|
||||
|
@ -31,7 +35,7 @@
|
|||
"capacity": null
|
||||
},
|
||||
"citation": {
|
||||
"allow_self": null,
|
||||
"allow_self": false,
|
||||
"min_extant": null,
|
||||
"max_extant": null,
|
||||
"min_phantom": null,
|
||||
|
@ -57,5 +61,7 @@
|
|||
"player": null,
|
||||
"signature": "~Ersatz Scrivener"
|
||||
}
|
||||
}
|
||||
},
|
||||
"log": [
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue