An open API service indexing awesome lists of open source software.

https://github.com/luka-loehr/receipt-ai

Personalized German morning briefings for thermal printers with real-time Google Calendar, Gmail, and AI insights. Perfect for your morning coffee ritual!
https://github.com/luka-loehr/receipt-ai

ai automation calendar daily-briefing esc-pos gmail openai python thermal-printer weather

Last synced: 3 months ago
JSON representation

Personalized German morning briefings for thermal printers with real-time Google Calendar, Gmail, and AI insights. Perfect for your morning coffee ritual!

Awesome Lists containing this project

README

          

# ๐Ÿงพ Receipt Printer

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/)
[![OpenAI](https://img.shields.io/badge/OpenAI-API-green.svg)](https://platform.openai.com/)
[![Thermal Printer](https://img.shields.io/badge/ESC--POS-compatible-lightgrey.svg)](#)

**AI-powered daily briefings โ€” printed to your thermal receipt printer.**

Generate multilingual summaries from your Gmail, Calendar, Tasks, and weather data. Everything is personalized, culturally adapted, and printed using ESC/POS printers.

---

## โœจ Features

- ๐ŸŒ **Multilingual AI** โ€” Any language, culture-aware formatting
- ๐Ÿ“ฌ **Google Integration** โ€” Gmail, Calendar, Tasks
- โ˜€๏ธ **Weather Data** โ€” OpenWeatherMap integration
- ๐Ÿ–จ๏ธ **ESC/POS Support** โ€” USB, network, or file-based printing
- ๐Ÿ–ผ๏ธ **Multiple Outputs** โ€” PNG preview, plain text, ESC/POS commands
- โš™๏ธ **Fully Configurable** โ€” Easy .env setup

---

## ๐Ÿš€ Quick Start

```bash
git clone https://github.com/luka-loehr/receipt-printer.git
cd receipt-printer
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp env.example .env
```

1. Fill in `.env` with your API keys & preferences
2. Setup Google Cloud: enable Gmail, Calendar, Tasks API + OAuth creds
3. Place OAuth JSON file into `cloud_credentials/`
4. Run initial auth:
```bash
python3 oauth_setup.py
```
5. (Optional) Setup USB printer:
```bash
python3 printer_setup.py
```
6. Generate your daily briefing:
```bash
python3 daily_brief.py
```

---

## โš™๏ธ Configuration

| Variable | Description | Default |
|----------------------|-----------------------------------------|-------------------|
| `USER_NAME` | Personalization | `Luka` |
| `RECEIPT_LANGUAGE` | AI response language | `german` |
| `USER_TIMEZONE` | Your timezone | `Europe/Berlin` |
| `WEATHER_LOCATION` | Weather city & country | `Karlsruhe,DE` |
| `THERMAL_PRINTER_TYPE`| `usb`, `network`, or `file_test` | `file_test` |
| `PREVIEW_PNG` | Auto-open preview | `true` |
| `PRINTER_CONSOLE_HOST`| Printer Console bind host | `127.0.0.1` |
| `PRINTER_CONSOLE_PORT`| Printer Console port (uncommon) | `8765` |
| `PRINTER_CONSOLE_DEBUG`| Enable Flask debug mode | `false` |

---

## ๐Ÿ—‚๏ธ Project Structure

```txt
receipt-printer/
โ”œโ”€โ”€ daily_brief.py # Main script
โ”œโ”€โ”€ oauth_setup.py # Google OAuth flow
โ”œโ”€โ”€ printer_setup.py # USB printer config
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ daily_brief.py # Summary generation
โ”‚ โ”œโ”€โ”€ data_services.py # Gmail, Calendar, Weather
โ”‚ โ”œโ”€โ”€ thermal_printer.py # ESC/POS logic
โ”‚ โ””โ”€โ”€ ...
โ”œโ”€โ”€ outputs/ # PNG, TXT, ESC/POS files
โ”œโ”€โ”€ cloud_credentials/ # OAuth JSON file
```

---

## ๐Ÿงช Requirements

- โœ… Python 3.8+
- โœ… OpenAI API key
- ๐Ÿ”„ Google Cloud Project (OAuth2 + APIs enabled)
- ๐ŸŒฆ๏ธ OpenWeatherMap API (optional)
- ๐Ÿ–จ๏ธ Any ESC/POS-compatible thermal printer (USB, network)

---

## ๐Ÿ›  Troubleshooting

- **No printer found**: Try `printer_setup.py` and check USB power
- **OAuth fails**: Recheck `.json` in `cloud_credentials/` and enabled APIs
- **Empty output**: Validate your OpenAI key and internet connection

---

## ๐Ÿ–จ๏ธ Print Custom Text

Use the helper script to print arbitrary text.

Interactive (paste a single line, then press Enter):

```bash
python3 scripts/print_text.py
```

Pass text as CLI arguments:

```bash
python3 scripts/print_text.py "Hello world"
```

Pipe multi-line input:

```bash
printf "Line 1\nLine 2\n" | python3 scripts/print_text.py
```

Note (file transport โ†’ CUPS): If your `.env` uses a file-based printer (`THERMAL_PRINTER_TYPE=file` or `file_test`), the script writes ESC/POS to `PRINTER_FILE_PATH` and, when `CUPS_PRINTER` is set, auto-forwards it to CUPS using `lp -o raw` (same behavior as the daily brief).

---

## ๐Ÿค Contributing

```bash
# 1. Fork & clone the repo
# 2. Create a new feature branch
# 3. Make and test your changes
# 4. Submit a PR ๐Ÿ™Œ
```

---

## ๐Ÿ“„ License

MIT License โ€” see [`LICENSE`](LICENSE) file.

---

## ๐Ÿ’ฌ Support & Feedback

- [GitHub Issues](https://github.com/luka-loehr/receipt-printer/issues)
- [Discussions](https://github.com/luka-loehr/receipt-printer/discussions)

---

## ๐Ÿ–ฅ๏ธ Printer Console (Always-On UI)

Run a local UI to trigger the daily brief and quick text prints.

Start the console:

```bash
python3 -m src.server_app
```

Environment variables:

- `PRINTER_CONSOLE_HOST`: default `127.0.0.1`
- `PRINTER_CONSOLE_PORT`: default `8765` (uncommon to avoid conflicts)
- `PRINTER_CONSOLE_DEBUG`: `true/false`

Then open `http://127.0.0.1:8765/` (or your configured host/port).

### Autostart on boot (systemd user service)

You can create a systemd user service to start the console on login/boot. Example unit:

```ini
[Unit]
Description=Receipt Printer Console
After=network-online.target

[Service]
Type=simple
Environment=PYTHONUNBUFFERED=1
Environment=PRINTER_CONSOLE_HOST=127.0.0.1
Environment=PRINTER_CONSOLE_PORT=8765
WorkingDirectory=%h/Documents/receipt-printer
ExecStart=%h/Documents/receipt-printer/venv/bin/python -m src.server_app
Restart=on-failure

[Install]
WantedBy=default.target
```

Save to `~/.config/systemd/user/receipt-printer-console.service`, then run:

```bash
systemctl --user daemon-reload
systemctl --user enable receipt-printer-console.service
systemctl --user start receipt-printer-console.service
systemctl --user status receipt-printer-console.service
```