add interface to read variants.json file

This commit is contained in:
Maximilian Keßler 2023-03-11 20:00:56 +01:00
parent d0ba1f4b4a
commit 46cc2c50ee
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 16 additions and 11 deletions

View file

@ -2,23 +2,13 @@ import json
from enum import Enum
from typing import List, Optional
import more_itertools
from variants import variant_id, variant_name
BASE62 = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
COLORS = 'rygbpt'
# Some setup for conversion between variant id and name
with open("variants.json", 'r') as f:
VARIANTS = json.loads(f.read())
def variant_id(variant_name):
return next(var['id'] for var in VARIANTS if var['name'] == variant_name)
def variant_name(variant_id):
return next(var['name'] for var in VARIANTS if var['id'] == variant_id)
# Helper method, iterate over chunks of length n in a string
def chunks(s: str, n: int):
for i in range(0, len(s), n):

15
variants.py Normal file
View file

@ -0,0 +1,15 @@
import json
# Some setup for conversion between variant id and name
with open("variants.json", 'r') as f:
VARIANTS = json.loads(f.read())
def variant_id(variant_name):
return next(var['id'] for var in VARIANTS if var['name'] == variant_name)
def variant_name(variant_id):
return next(var['name'] for var in VARIANTS if var['id'] == variant_id)
def num_suits(variant_id):
return next(len(var['suits']) for var in VARIANTS if var['id'] == variant_id)