Skip to content

Instantly share code, notes, and snippets.

@melissaboiko
Last active Mar 13, 2021
Embed
What would you like to do?
pspsps – show catgirls on Linux terminal
#!/usr/bin/env python3
# pspsps – show catgirls on Linux terminal
import os
import sys
try:
import ascii_magic
except ModuleNotFoundError:
sys.stderr.write("Install ascii_magic first nya~\n")
sys.stderr.write("pip3 install ascii_magic")
sys.exit(1)
import random
import urllib.request
import xml.etree.ElementTree as ET
COLUMNS=os.getenv('COLUMNS', default=80)
API='https://safebooru.org/index.php?page=dapi&s=post&q=index'
MAXKITTENS=100 # Safebooru limit
TAGS='catgirl' # nyan
response = urllib.request.urlopen('%s&limit=%s&tags=%s' % (API, MAXKITTENS, TAGS))
# TODO: handle exceptions here
posts = ET.fromstring(response.read())
kitten = random.choice(posts.findall('post'))
pic_url = kitten.attrib['file_url']
pic = ascii_magic.from_url(pic_url, columns=COLUMNS)
# TODO: handle exceptions here
ascii_magic.to_terminal(pic)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment