NOJIRA more string replacement + vanity
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import re
|
||||
from typing import List, Dict
|
||||
|
||||
import Levenshtein
|
||||
@@ -11,6 +12,10 @@ class ItemService:
|
||||
def _translate_part(item_names: List[str], old: str, new: str) -> List[str]:
|
||||
return [i.replace(old, new) for i in item_names]
|
||||
|
||||
@staticmethod
|
||||
def _translate_part_regex(item_names: List[str], regex: str, new: str) -> List[str]:
|
||||
return [re.sub(regex, new, i) for i in item_names]
|
||||
|
||||
@staticmethod
|
||||
def _translate_whole(item_names: List[str], old: str, new: str) -> List[str]:
|
||||
return [new if i == old else i for i in item_names]
|
||||
@@ -25,7 +30,7 @@ class ItemService:
|
||||
distance = Levenshtein.distance(lhs, rhs)
|
||||
if distance <= 2:
|
||||
print(lhs + ":" + rhs + " = " + str(distance))
|
||||
ItemService._translate_whole(item_names, lhs, rhs)
|
||||
item_names = ItemService._translate_whole(item_names, lhs, rhs)
|
||||
return item_names
|
||||
|
||||
@staticmethod
|
||||
@@ -40,6 +45,11 @@ class ItemService:
|
||||
@staticmethod
|
||||
def get_items_from_orders(orders: List[Order]):
|
||||
item_names: List[str] = _flatten([o.items for o in orders])
|
||||
item_names = ItemService._translate_part_regex(item_names, r" ?\+ ?", " + ")
|
||||
item_names = ItemService._translate_part_regex(item_names, r" met$", " met mayo")
|
||||
item_names = ItemService._translate_part_regex(item_names, r" (mayo[^ ]*)", " mayo")
|
||||
item_names = ItemService._translate_part_regex(item_names, r" sat[eé](saus)?", " saté")
|
||||
item_names = ItemService._translate_part(item_names, "patat", "friet")
|
||||
item_names = ItemService._translate_part(item_names, "frietje", "friet")
|
||||
item_names = ItemService._translate_part(item_names, "krul friet", "twister")
|
||||
item_names = ItemService._translate_part(item_names, "krulfriet", "twister")
|
||||
|
||||
@@ -6,20 +6,21 @@
|
||||
</head>
|
||||
<body>
|
||||
<div class="markdown-body">
|
||||
<h1>Reeds besteld</h1>
|
||||
<h1>Frietlijst by Ivo</h1>
|
||||
<h2>Reeds besteld</h2>
|
||||
<ol>
|
||||
{% for applicant in applicants %}
|
||||
<li>{{ applicant }}</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
|
||||
<h1>Streeplijst - {{ item_count }} stuks</h1>
|
||||
<h2>Streeplijst - {{ item_count }} stuks</h2>
|
||||
<ul>
|
||||
{% for item in items %}
|
||||
<li>{{ item.name }}: {{ item.amount }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<h1>Totaaloverzicht</h1>
|
||||
<h2>Totaaloverzicht</h2>
|
||||
<ul>
|
||||
{% for order in orders %}
|
||||
<li>
|
||||
|
||||
Reference in New Issue
Block a user