Compare commits
10 Commits
189f587fc7
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 73b31b1935 | |||
|
|
ae428e12c7 | ||
|
|
3833d734cd | ||
|
|
aeb1670c83 | ||
|
|
9325ebe159 | ||
|
|
1713aeb247 | ||
|
|
675dacb3c2 | ||
| 89dc57ac40 | |||
| 2d3c089423 | |||
| cda44c63f9 |
25
.gitea/workflows/build-and-publish.yaml
Normal file
25
.gitea/workflows/build-and-publish.yaml
Normal file
@@ -0,0 +1,25 @@
|
||||
name: Build and Publish
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup token file
|
||||
run: |
|
||||
printf "%s" "$TOKEN" > src/token.json
|
||||
env:
|
||||
TOKEN: ${{ secrets.TOKEN }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
run: docker build -t 172.19.0.2:32768/frietlijst:$(git rev-parse --short HEAD) .
|
||||
13
Dockerfile
Normal file
13
Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
||||
FROM python:latest
|
||||
|
||||
WORKDIR /app
|
||||
EXPOSE 5000
|
||||
|
||||
COPY src/requirements.txt .
|
||||
RUN pip3 install -r requirements.txt
|
||||
|
||||
COPY src .
|
||||
|
||||
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
|
||||
|
||||
|
||||
@@ -1,13 +1,26 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from flask import render_template
|
||||
from cachetools import cached, TTLCache
|
||||
from flask import render_template, Flask
|
||||
|
||||
from item_service import ItemService
|
||||
from order_repository import OrderRepository
|
||||
|
||||
app = Flask(__name__)
|
||||
_repository = OrderRepository(
|
||||
sa_file_name='token.json',
|
||||
spreadsheet_id='18vCgc5DGUiFZN1NX_GBmxSBCb47KdsBkV6Glf9Sx-wE',
|
||||
spreadsheet_range='Friet bestelling!A2:F',
|
||||
)
|
||||
|
||||
def process(_) -> str:
|
||||
min_datetime = datetime.now() - timedelta(days=200)
|
||||
@app.route('/')
|
||||
def process() -> str:
|
||||
return process_cached()
|
||||
|
||||
|
||||
@cached(cache=TTLCache(maxsize=1, ttl=10))
|
||||
def process_cached() -> str:
|
||||
min_datetime = datetime.now() - timedelta(days=2)
|
||||
orders = _repository.find_by_datetime_placed_greater_than(min_datetime)
|
||||
|
||||
items = ItemService.get_items_from_orders(orders)
|
||||
@@ -23,8 +36,4 @@ def process(_) -> str:
|
||||
|
||||
|
||||
if __name__ == 'main':
|
||||
_repository = OrderRepository(
|
||||
sa_file_name='token.json',
|
||||
spreadsheet_id='18vCgc5DGUiFZN1NX_GBmxSBCb47KdsBkV6Glf9Sx-wE',
|
||||
spreadsheet_range='Friet bestelling!A2:F',
|
||||
)
|
||||
app.run(debug==True)
|
||||
@@ -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")
|
||||
|
||||
@@ -23,7 +23,6 @@ class OrderRepository:
|
||||
self.__spreadsheet_id = spreadsheet_id
|
||||
self.__spreadsheet_range = spreadsheet_range
|
||||
|
||||
@cached(cache=TTLCache(maxsize=1, ttl=10))
|
||||
def find_by_datetime_placed_greater_than(self, min_datetime: datetime) -> List[Order]:
|
||||
result: List[List[str]] = self.__sheets.values().get(
|
||||
spreadsheetId=self.__spreadsheet_id,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
cachetools==4.2.2
|
||||
flask==2.0.1
|
||||
google-api-python-client==2.20.0
|
||||
google-auth-httplib2==0.1.0
|
||||
google-auth-oauthlib==0.4.6
|
||||
python-Levenshtein==0.12.2
|
||||
cachetools
|
||||
flask
|
||||
google-api-python-client
|
||||
google-auth-httplib2
|
||||
google-auth-oauthlib
|
||||
python-Levenshtein
|
||||
|
||||
@@ -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>
|
||||
@@ -36,7 +37,7 @@
|
||||
<a href="https://docs.google.com/forms/d/e/1FAIpQLSddGpp9kbvW9QfLVATOM3pJqhq1ci0_gdZdpGmXmkPRMoiLEw/viewform?usp=sf_link"
|
||||
target="_blank">Klik hier!</a></p>
|
||||
<p>Wil je de code van deze pagina zien of hieraan bijdragen?
|
||||
<a href="https://github.com/spijkercenter/frietlijst"
|
||||
<a href="https://git.spijkerman.com/ivo/frietlijst"
|
||||
target="_blank">Klik hier!</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user