commit 619f5f51f8b155ff568f336e80e70d58a2315783 Author: subnixr Date: Sat Feb 3 02:19:32 2018 +0100 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e457a6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,102 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# dotenv +.env + +# virtualenv +.venv +venv/ +ENV/ + +# Spyder project settings +.spyderproject + +# Rope project settings +.ropeproject + +# macao-pos files +conf/ +pos.db +pos.log* + +# configurations +config.json \ No newline at end of file diff --git a/autostampa.py b/autostampa.py new file mode 100644 index 0000000..2c9f26e --- /dev/null +++ b/autostampa.py @@ -0,0 +1,42 @@ +import json + +from escpos import printer + + +class Item: + def __init__(self, text, icon): + self.text = text + self.icon = icon + + def print(self, conn): + conn.text(f"{self.text}\n") + # TODO: conn.image(self.icon) + conn.cut() + + +def connect(connection_cfg): + if "file" in connection_cfg: + return printer.File(connection_cfg["file"]) + else: + return printer.Dummy() + + +def load_items(items_cfg): + return [Item(c['text'], c['img']) for c in items_cfg] + + +def main(): + with open("config.json") as fh: + cfg = json.load(fh) + + items = load_items(cfg['items']) + conn = connect(cfg["connection"]) + + for i in items: + i.print(conn) + + print(conn.output.decode('UTF-8')) + + +if __name__ == "__main__": + main() diff --git a/config.json.skel b/config.json.skel new file mode 100644 index 0000000..a03dbf5 --- /dev/null +++ b/config.json.skel @@ -0,0 +1,14 @@ +{ + // for now dummy only + "connection": {}, + "items": [ + { + "text": "birra", + "img": "assets/birra.jpg" + }, + { + "text": "acqua", + "img": "assets/acqua.jpg" + } + ] +} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ab7b160 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,17 @@ +appdirs==1.4.3 +argcomplete==1.9.3 +astroid==1.6.1 +autopep8==1.3.4 +isort==4.3.1 +lazy-object-proxy==1.3.1 +mccabe==0.6.1 +Pillow==5.0.0 +pycodestyle==2.3.1 +pylint==1.8.2 +pyserial==3.4 +python-escpos==2.2.0 +pyusb==1.0.2 +PyYAML==3.12 +qrcode==5.3 +six==1.11.0 +wrapt==1.10.11