BreakingExpress

Make a cup of espresso with Git

Git can do the whole lot—besides make your espresso. But what if it might?

Like most individuals, I have already got a devoted espresso brewing gadget listening to HTCPCP requests. All that’s left is to hook Git as much as it.

The first step is to jot down the shopper code, utilizing httpx:

>>> import httpx
>>> end result = httpx.request("BREW", "http://localhost:1111/")
>>> end result.textual content
'begin'

Ah, nothing nicer than a espresso pot beginning to brew. You must do a number of extra steps to make this accessible to git.

A correct method to do it could be to place this in a bundle and use pipx to handle it. For now, set up httpx into your person surroundings:

$ pip set up --user httpx

Then put this code in a script:

#!/usr/bin/env python
# This script must be in ~/.bin/git-coffee
# Remember to chmod +x ~/.bin/git-coffee
import httpx
end result = httpx.request("BREW", "http://10.0.1.22:1111/")
end result.raise_for_status()
print(end result.textual content)

Make positive that ~/.bin is in your path:

$ (echo $PATH | grep -q ~/.bin) || echo "Make sure to add ~/.bin to your path!"

Finally, get pleasure from as your git command means that you can get pleasure from your morning espresso:


The finer issues in life

Python, Git, and occasional are a great mixture for any open supply programmer or person. I depart the train of implementing a espresso brewing terminal to you (possibly you’ve got a spare Raspberry Pi in search of a goal?) If you do not have a espresso machine configured for HTTP requests, then on the very least, you have realized how simple it’s to make use of Python and the httpx module to make HTTP name requests. So go get your self a espresso. You’ve earned it!

Exit mobile version