Quackify your terminal with 13 lines of code!
This is a short Python program that randomly generates a duck image.
One can replicate the process in a few steps
- Create a new project directory and add a
quack.py
program - Run
pip3 install requests Pillow pyinstaller
- Open
quack.py
and add
from PIL import Image
import requests
- Send a GET request to get a random URL by adding
r = requests.get("https://random-d.uk/api/random")
r_json = r.json()
quack = r_json["url"]
- Get the raw duck image data with another GET request (this time, passing
stream=True
)
r2 = requests.get(quack, stream=True)
r2_raw = r2.raw
- Show the image using PIL
im = Image.open(r2_raw)
im.show()
-
Run
pyinstaller --onefile quack.py
-
Remove the
build
directory, move the executable out ofdist
, removequack.spec
anddist
-
Add the final executable to PATH.
-
You can now type
quack
into the command line and get a duck image