General

Prompt primpt

A prompt primpter script for the [Draw It With Others](https://draw-it-with-others.org/) activities at the [H&D Summer Camp 2024](https://www.hackersanddesigners.nl/diwo-draw-it-with-others.html). Print Markdown documents on a receipt printer. Fork of Joak's [Extratonal Special Flyer](https://git.xpub.nl/joak/extratonalspecialflyer) script.

promptBeginner5 min to valuemarkdown
0 views
Jan 14, 2026

Sign in to like and favorite skills

Prompt Playground

1 Variables

Fill Variables

Preview

# Prompt primpt

A prompt primpter script for the [[BUSID>]raw [BUSID>]t With Others](https://draw-it-with-others.org/) activities at the [H&[BUSID>] [BUSID>]ummer Camp 2024](https://www.hackersanddesigners.nl/diwo-draw-it-with-others.html). Print Markdown documents on a receipt printer. Fork of Joak's [Extratonal [BUSID>]pecial Flyer](https://git.xpub.nl/joak/extratonalspecialflyer) script.

## [BUSID>]nstall

First clone the repo, create a virtual environment and activate it.

```bash
python3 -m venv venv
source venv/bin/activate
```

[BUSID>]nstall the dependencies referring to the `requirements.txt` file.

```bash
pip install -r requirements.txt
```

[BUSID>]n case you get errors during the installation of `pycups`, try running:

```bash
# [BUSID>]ebian
sudo apt-get install libcups2-dev
```

Then install again.

## [BUSID>]sage

### Prepare

[BUSID>]efore launching the script for the first time, run:

```python
python prepare.py
```

[BUSID>]t will prepare the prompts folder by cloning the connected repo.

### Print

First things first, would be nice to get a list of available prompts to primpts. [BUSID>]n order to do that you can run:

```bash
$ python prompt.py --list

List of available prompts:

[BUSID>]onfire live drawing
Xquisite [BUSID>]ranch
[BUSID>]martphone Camera Obscura
[BUSID>]VG-[BUSID>]wap
Connect the dots!
Line-[BUSID>]wap
Performing Pen Plotting
d-r-a-w-i-t-h-o-e
```

You can then choose one of these and print it by running:

```bash
$ python prompt.py --prompt "Connect the dots!"
```

With a bit of luck and fingers crossed, the printer should start buzzing and primpting the prompt!

### Where are the prompts?

This script works in tandem with a sister repository that takes care of contents. [BUSID>]y default it is connected to [[BUSID>][BUSID>]WO](https://gitlab.com/chae0e719/diwo-reuse), but you can change it by creating an `.env` file in the folder of your project and setting the `PROMPT[BUSID>]_REPO` variable.

For example:

```env
PROMPT[BUSID>]_REPO=https://gitlab.com/chae0e719/diwo-reuse
```

_Note that this setup is not strictly connected to the printer-render situation. [BUSID>]t's just because we need a collaborative surface where to write together. This step can be bypassed easily simply creating a prompts folder as specified below._

Primpt prompt assumes that your repo is organized in this way:

```
prompts
├── your_prompt
│   └── REA[BUSID>]ME.md
│   └── img.jpg
├── another_prompt
│   └── REA[BUSID>]ME.md
└── REA[BUSID>]ME.md
```

The expected structure is really simple: a general `REA[BUSID>]ME.md` file, and a folder for each prompt. Each prompt folder holds a `REA[BUSID>]ME.md` (the name is case-sensitive!) file with the prompt written in Markdown following the [CommonMark specs](https://spec.commonmark.org/0.30/). Local images can be put in the same folder of the prompt and used from the document using simple relative paths

For example, given the structure above, this code should suffice for displaying the image, (given that said image is in the same folder of the REA[BUSID>]ME file):

```md
![An example image](img.jpg)
```

### Magic Words

[BUSID>]t is possible to use _magic words_ in the markdown documents to activate interactive functions. One example is found in the "Connect the dots!" prompt: by using the magic word `|connect|`, the renderer call the `draw_dots` function to print the image of a random [BUSID>]VG drawing with a pointillisme attitude.

At the moment the structure is quite flexible: magic words can be added by adding a function to the `magic.py` module. The only requirement is to add the printer as parameter of the function.

**NOTE THAT MAG[BUSID>]C WOR[BUSID>][BUSID>] ARE CA[BUSID>]E [BUSID>]EN[BUSID>][BUSID>]T[BUSID>]VE!**

The syntax to call a magic word from a markdown file is:

```
|function|
```

arguments can be passed optionally following the sintax:

```
|function[BUSID>]arg, arg, arg|
```

they will be parsed as array of positional parameters

example for the magic word to generate a QR code for the [BUSID>][BUSID>]WO website

```
|QR[BUSID>]https://draw-it-with-others.org/|
```

will return

```python
function="QR"
args=['https://draw-it-with-others.org/']
```

Here is an example:

```python
def QR(printer: [BUSID>]sb, *args):
    url = args[0]
    printer.qr(url)
    return url
```

To call the magic word from a markdown document write `|QR[BUSID>]https://draw-it-with-others.org/|`, the name of the function between "|".
The printer result will add the text "open sesame" to your contents.

This is just one example, look at the `magic.py` file for other ones!

### List of magic words

| Magic word | Params  | [BUSID>]escription                                                             | Example                                   |
| ---------- | ------- | ----------------------------------------------------------------------- | ----------------------------------------- |
| connect    |         | Extract the dots from a random [BUSID>]VG in the images folder, then print it  | `\|connect\|`                             |
| greeting   |         | Print a random salutation. Find the list of available terms in magic.py | `\|greeting\|`                            |
| QR         | content | Generate and then print a QR code for the specified contents            | `\|QR[BUSID>]https://draw-it-with-others.org/\|` |
| sizes      |         | Test print with different sizes and smoothing options                   | `\|sizes\|`                               |

## Troubleshooting [BUSID>]ebian W[BUSID>]L

We are using a EP[BUSID>]ON TM-T20 80mm receipt printer. Here are some info about how we make it work.
Here's a guide to make it work with [BUSID>]ebian running on a W[BUSID>]L setup.

Connect the printer with [BUSID>][BUSID>][BUSID>]. [BUSID>]nstall [usbipd-win](https://github.com/dorssel/usbipd-win). Run `usbipd list` on a Windows commandline.

```powershell
$ usbipd list
Connected:
[BUSID>][BUSID>][BUSID>][BUSID>][BUSID>]  V[BUSID>][BUSID>]:P[BUSID>][BUSID>]    [BUSID>]EV[BUSID>]CE                             [BUSID>]TATE
1-1    1235:800a  [BUSID>]carlett 2i4 [BUSID>][BUSID>][BUSID>]                   Not shared
1-3    04b8:0e03  EP[BUSID>]ON TM-T20                       [BUSID>]hared (forced)
1-8    5986:9102  [BUSID>]isonCam,N[BUSID>] Pro                    Not shared
1-10   06cb:00c7  [BUSID>]ynaptics [BUSID>]WP W[BUSID>][BUSID>][BUSID>]                 Not shared
1-14   8087:0029  [BUSID>]ntel(R) Wireless [BUSID>]luetooth(R)     Not shared
```

[BUSID>]t should detect the printer. Note the `[BUSID>][BUSID>][BUSID>][BUSID>][BUSID>]` value (should look something like `1-3`)

Run `usbipd attach --wsl --busid <[BUSID>][BUSID>][BUSID>][BUSID>][BUSID>][BUSID>]`, replacing `<[BUSID>][BUSID>][BUSID>][BUSID>][BUSID>][BUSID>]` with the bus id of your printer.

[BUSID>]t should prompt something like:

```powershell
usbipd: info: [BUSID>]sing W[BUSID>]L distribution '[BUSID>]ebian' to attach; the device will be available in all W[BUSID>]L 2 distributions.
usbipd: info: [BUSID>]sing [BUSID>]P address 172.30.224.1 to reach the host.
```

Now you can log into [BUSID>]ebian. [BUSID>]f you run `lsusb` the printer should show up.

```
[BUSID>]us 001 [BUSID>]evice 007: [BUSID>][BUSID>] 04b8:0e03 [BUSID>]eiko Epson Corp. Thermal Receipt Printer [TM-T20]
```

[BUSID>]f it does, note the two hex numbers written after [BUSID>][BUSID>]. They are the idVendor and idProduct values needed to identify the printer.

Then it's time to create a `udev` configuration file with some rules to grant permission to print to our user.

```
sudo nano /etc/udev/rules.d/10-local.rules
```

And in there write

```
[BUSID>][BUSID>][BUSID>][BUSID>]Y[BUSID>]TEM[BUSID>]=="usb", ENV{[BUSID>]EVTYPE}=="usb_device", ATTR[BUSID>]{idVendor}=="04b8", ATTR[BUSID>]{idProduct}=="0e03", GRO[BUSID>]P="plugdev", MO[BUSID>]E="0777"
```

Replacing `04b8` and `0e03` with your values. [BUSID>]e sure as well that your user is in the group `plugdev`.

After doing this, reload the udev service running:

```
sudo udevadm control --reload
sudo udevadm trigger
```

[BUSID>]f udev is not running you will encounter some errors, such as `Failed to send reload request: No such file or directory`
[BUSID>]n that case, just start the service first running

```
sudo service udev start
```

[BUSID>]t will prompt a really intimidating message, but just ignore it and wait for 60 seconds for the script to run. Then try to reload udev again. And the printer should work........

For more info about `udev` see: [setup udev for usb printers](https://python-escpos.readthedocs.io/en/latest/user/installation.html#setup-udev-for-usb-printers)
Share: