Make a cup of coffee with Git
source link: https://opensource.com/article/22/4/brew-coffee-git-command
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Make a cup of coffee with Git
By
Moshe Zadka (Correspondent)
Pixabay. CC0.
Git can do everything—except make your coffee. But what if it could?
Like most people, I already have a dedicated coffee brewing device listening to HTCPCP requests. All that is left is to hook Git up to it.
The first step is to write the client code, using httpx:
>>> result = httpx.request("BREW", "http://localhost:1111/")
>>> result.text
'start'
Ah, nothing nicer than a coffee pot starting to brew. You need to do a few more steps to make this available to git
.
A proper way to do it would be to put this in a package and use pipx
to manage it. For now, install httpx
into your user environment:
$ pip install --user httpx
Then put this code in a script:
# This script should be in ~/.bin/git-coffee
# Remember to chmod +x ~/.bin/git-coffee
import httpx
result = httpx.request("BREW", "http://10.0.1.22:1111/")
result.raise_for_status()
print(result.text)
Make sure that ~/.bin
is in your path:
$ (echo $PATH | grep -q ~/.bin) || echo "Make sure to add ~/.bin to your path!"
Finally, enjoy as your git
command allows you to enjoy your morning coffee:
start
The finer things in life
Python, Git, and coffee are a good combination for any open source programmer or user. I leave the exercise of implementing a coffee brewing terminal to you (maybe you have a spare Raspberry Pi looking for a purpose?) If you don't have a coffee machine configured for HTTP requests, then at the very least, you've learned how easy it is to use Python and the httpx
module to make HTTP call requests. So go get yourself a coffee. You've earned it!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK