add interface to read variants.json file
This commit is contained in:
parent
d0ba1f4b4a
commit
46cc2c50ee
2 changed files with 16 additions and 11 deletions
12
compress.py
12
compress.py
|
@ -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
15
variants.py
Normal 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)
|
Loading…
Reference in a new issue