update emojis

This commit is contained in:
2025-03-24 10:04:11 -05:00
parent 0f7bda0942
commit 1846dc1065
4 changed files with 76 additions and 59 deletions

View File

@@ -1,35 +1,13 @@
# Render markdown template for nKode enrollment
from pathlib import Path
import numpy as np
from jinja2 import Environment, FileSystemLoader, select_autoescape
from secrets import choice
from string import ascii_lowercase
from docs.scripts.utils import render_markdown_template, emojis
from src.models import NKodePolicy, KeypadSize
from src.nkode_api import NKodeAPI
from src.utils import select_keys_with_passcode_values
def render_markdown_template(template_path, output_path, context):
template_dir = template_path.parent
template_file = template_path.name
env = Environment(
loader=FileSystemLoader(template_dir),
autoescape=select_autoescape(['html', 'xml']),
trim_blocks=True,
lstrip_blocks=True
)
template = env.get_template(template_file)
rendered = template.render(**context)
with open(output_path, 'w') as f:
f.write(rendered)
print(f"Template rendered to {output_path}")
def display_icons(icons_array: np.ndarray, kp: KeypadSize) -> str:
icons = "["
for row in icons_array.reshape(-1, kp.numb_of_keys):
@@ -49,14 +27,7 @@ def display_icons_keypad(icons_array: np.ndarray, props_per_key: int) -> str:
if __name__ == "__main__":
api = NKodeAPI()
user_icons = np.array([
"😀", "😂", "🥳", "😍", "🤓",
"😎", "🥺", "😡", "😱", "🤯",
"🥰", "😴", "🤔", "🙃", "😇",
"🤖", "👽", "👾", "🐱", "🐶",
"🦁", "🐻", "🐸", "🐙", "🦄",
"🌟", "", "🔥", "🍕", "🎉"
])
policy = NKodePolicy(
max_nkode_len=10,
min_nkode_len=4,
@@ -64,12 +35,12 @@ if __name__ == "__main__":
distinct_properties=4,
)
keypad_size = KeypadSize(
numb_of_keys=5,
props_per_key=6
numb_of_keys=6,
props_per_key=9
)
customer_id = api.create_new_customer(keypad_size, policy)
signup_session_id, set_signup_keypad = api.generate_signup_keypad(customer_id)
ordered_set_icons = user_icons[set_signup_keypad]
ordered_set_icons = emojis[set_signup_keypad]
username = "test_username" + "".join([choice(ascii_lowercase) for _ in range(6)])
passcode_len = 4
passcode_property_indices = np.random.choice(set_signup_keypad.reshape(-1), size=passcode_len,
@@ -79,16 +50,16 @@ if __name__ == "__main__":
confirm_keypad = api.set_nkode(username, customer_id, selected_keys_set, signup_session_id)
selected_keys_confirm = select_keys_with_passcode_values(passcode_property_indices, confirm_keypad,
keypad_size.numb_of_keys)
ordered_confirm_icons = user_icons[confirm_keypad]
ordered_confirm_icons = emojis[confirm_keypad]
print(f"Selected Keys\n{selected_keys_confirm}")
success = api.confirm_nkode(username, customer_id, selected_keys_confirm, signup_session_id)
context = {
"email": "user@example.com",
"signup_session_id": signup_session_id,
"set_keypad": display_icons_keypad(set_signup_keypad.reshape(-1, keypad_size.numb_of_keys), keypad_size.numb_of_keys),
"keypad_icons": display_icons(user_icons, keypad_size),
"keypad_icons": display_icons(emojis[:keypad_size.total_props], keypad_size),
"ordered_keypad": display_icons_keypad(ordered_set_icons, keypad_size.numb_of_keys),
"passcode_user_icons": str(user_icons[passcode_property_indices]),
"passcode_user_icons": str(emojis[passcode_property_indices]),
"selected_keys_set": str(selected_keys_set),
"confirm_keypad": display_icons_keypad(confirm_keypad.reshape(-1, keypad_size.numb_of_keys), keypad_size.numb_of_keys),
"confirm_ordered_keypad": display_icons_keypad(ordered_confirm_icons.reshape(-1, keypad_size.numb_of_keys), keypad_size.numb_of_keys),
@@ -98,13 +69,13 @@ if __name__ == "__main__":
login_keypad = api.get_login_keypad(username, customer_id)
selected_keys_login = select_keys_with_passcode_values(passcode_property_indices, login_keypad,
keypad_size.props_per_key)
ordered_login_keypad = user_icons[login_keypad]
ordered_login_keypad = emojis[login_keypad]
context = {
"email": "user@example.com",
"keypad_icons": display_icons(user_icons, keypad_size),
"keypad_icons": display_icons(emojis[:keypad_size.total_props], keypad_size),
"login_keypad": display_icons_keypad(login_keypad.reshape(-1, keypad_size.props_per_key), keypad_size.props_per_key),
"ordered_login_icons": display_icons_keypad(ordered_login_keypad.reshape(-1, keypad_size.props_per_key),keypad_size.props_per_key),
"passcode_user_icons": str(user_icons[passcode_property_indices]),
"passcode_user_icons": str(emojis[passcode_property_indices]),
"selected_keys_login": str(selected_keys_login)
}
api.login(customer_id, username, selected_keys_login)

46
docs/scripts/utils.py Normal file
View File

@@ -0,0 +1,46 @@
import numpy as np
from jinja2 import Environment, FileSystemLoader, select_autoescape
emojis = np.array([
"🍎", "🍏", "🍊", "🍋", "🍌", "🍉", "🍇", "🍓", "🍒", "🍑",
"🥭", "🍍", "🥥", "🥝", "🍅", "🍆", "🥑", "🥕", "🌽", "🥔",
"🍠", "🥐", "🥖", "🥨", "🥯", "🥞", "🧀", "🍖", "🍗", "🥚",
"🍔", "🍟", "🍕", "🌭", "🥪", "🌮", "🌯", "🍣", "🍤", "🍙",
"🍚", "🍜", "🍲", "🍛", "🍱", "🥟", "🍦", "🍧", "🍨", "🍩",
"🍪", "🎂", "🍰", "🧁", "🍫", "🍬", "🍭", "🍮", "", "🍵",
"🥤", "🧃", "🍷", "🍸", "🍹", "🍺", "🥂", "🥃", "🐶", "🐱",
"🐭", "🐹", "🐰", "🦊", "🐻", "🐼", "🐨", "🐯", "🦁", "🐮",
"🐷", "🐽", "🐴", "🦄", "🦓", "🦒", "🐘", "🦏", "🐪", "🐫",
"🐑", "🐐", "🐓", "🐔", "🐣", "🐤", "🐦", "🦅", "🦇", "🦉",
"🐺", "🐍", "🐢", "🦎", "🐙", "🦑", "🦐", "🦀", "🐡", "🐠",
"🐟", "🐬", "🐳", "🦈", "🐊", "🐅", "🐆", "🐾", "🦋", "🐞",
"🐝", "🐜", "🕷️", "🕸️", "🌸", "🌹", "🌺", "🌻", "🌼", "🌷",
"🌱", "🌲", "🌳", "🌴", "🌵", "🌾", "🌿", "🍀", "🍁", "🍂",
"🍃", "", "🌟", "", "⚡️", "☄️", "☀️", "🌤️", "", "🌥️",
"☁️", "🌦️", "🌧️", "⛈️", "🌩️", "❄️", "🌬️", "💨", "🌈", "",
"💧", "🌊", "🔥", "💥", "", "🌋", "⛰️", "🏔️", "🏕️", "🏖️",
"🏜️", "🏝️", "🏞️", "🏟️", "🏠", "🏡", "🏢", "🏣", "🏤", "🏥",
"🏦", "🏨", "🏩", "🏪", "🏫", "🏬", "🏭", "🏯", "🏰", "",
"⛩️", "🕌", "🕍", "🗿", "🎡", "🎢", "🎠", "🎪", "🎨", "🎬",
"🎤", "🎧", "🎼", "🎹", "🎺", "🎸", "🥁", "🎻", "🎮", "🎲"
])
def render_markdown_template(template_path, output_path, context: dict):
template_dir = template_path.parent
template_file = template_path.name
env = Environment(
loader=FileSystemLoader(template_dir),
autoescape=select_autoescape(['html', 'xml']),
trim_blocks=True,
lstrip_blocks=True
)
template = env.get_template(template_file)
rendered = template.render(**context)
with open(output_path, 'w') as f:
f.write(rendered)
print(f"Template rendered to {output_path}")