Help Six Degrees Edinburgh with a speciality coffee survey

Skip to main content

The Thermal Printer Project: Part III

Written by . Published on under the IndieWeb category.

Two pieces of thermal paper held up in front of an orange wall

How would you like to send me a message that gets printed so that I can read it on paper? You can do this by sending me a webmention, which is a way of sending comments from your own website that I will then receive. Using webmentions, you can retain ownership over the comments you send other people. I know that webmentions are not widely used, and do require a bit of technical knowledge to use, but for now I can say I support printing webmentions.

Before my thermal printer even arrived, I thought about what it would be like to print out webmentions that were sent to my blog. I see the idea as sort of like a personal fax machine or even like sending a letter, but the content is printed via a thermal printer (almost) on-demand. I wanted to experiment with this idea because it would give me a way to see comments sent to my site in a physical way, rather than viewing them online.

I’m going to spend the next few hundred words chatting about this project and its implementation.

Getting started with webmentions

To start with, I needed to add webmention support to my blog. This was easy thanks to the instructions on the homepage, which is the homepage of the service I use to receive and process webmentions. Those instructions gave me the two HTML tags I needed to get set up. I logged into my account, which I already had, and then asked someone to send me a webmention as a test.

Retrieving webmentions

The next phase of the project was deciding how to actually receive webmentions via paper. I decided that it was impractical to print webmentions on-demand for my use case. Instead, I opted to create a Python script that runs every hour and prints out all of the webmentions I have received within the last hour. To do this, I retrieve all of the webmentions I have received using the “since” attribute of the API. This attribute was very helpful because it means I only retrieve the webmentions I am going to print. I also retrieve all webmentions sent in the last day for rate limiting purposes, which is handled in a separate request.

Here is the code I use to retrieve webmentions sent in the last hour:

import datetime

last_period = - datetime.timedelta(hours=1)

date_for_webmention_last_hour = last_period.strftime("%Y-%m-%dT%H:%M:%S+0000")

all_webmentions_url = "{}".format(date_for_webmention_last_hour)

recent_webmentions = requests.get(all_webmentions_url)

Using this code, I can get all the information I need to print webmentions. The next step was to add validation to make sure that I only print a webmention if the author name, webmention content, and verified date are present. This ensures that I don’t run into any issues when it comes to the actual printing. Then I identify the post type using the wm-property object, which tells me whether a post is a reply, bookmark, like, comment, RSVP, repost, or mention. I relay this information when a webmention is printed so I can see the type of webmention sent to me.

The next section of the program is the fun part: actually printing the webmention. I use the information from the API to print when the webmention was sent, what URL the webmention was sent to, the name of the person who sent the webmention, and the contents of the webmention. Here is a photo of the first webmention I ever printed:

After I confirmed that my program worked as intended, I set up a cron script which retrieves my webmentions and prints them.

Next steps

I am happy with how the project has turned out. If you send a webmention to any page on this website, it will be printed on my thermal printer (assuming, of course, printer ink is available). Your webmention will be printed at the beginning of the next hour, assuming it is valid. I am excited to receive a webmention in the wild from this project rather than one that has been sent for testing purposes.

Working with the thermal printer has been interesting and challenging. I have spent hours writing code for the thermal printer and building modules for my daily update. I now have a working webmention printer. But there is still more for me to explore. I am not presently printing any images but this is something I would like to experiment with in the future. I might add new modules to my daily update as I get new ideas and I might modify my webmention program.

If you’d like to try out the webmention printer, send this page a webmention and say hello!

Also posted on IndieNews.

Go Back to the Top