Skip to content

Instantly share code, notes, and snippets.

@karlwilcox
Created April 19, 2021 14:55
Show Gist options
  • Save karlwilcox/d14ccdb9149cb7ce429b337b2478ffbd to your computer and use it in GitHub Desktop.
Save karlwilcox/d14ccdb9149cb7ce429b337b2478ffbd to your computer and use it in GitHub Desktop.
Code to embed DrawShield shield renders and heraldic definitions in Jupyter Notebooks
import requests
import base64
from IPython.display import Image, display
# example usage:
# drawshield("azure a bend or")
# For more detailed information use
# drawshield("azure a bend or", True)
def drawshield(blazon, debug = False):
url = "https://drawshield.net/include/drawshield.php"
outputformat = "png"
if (debug):
outputformat = "json"
payload = ""
querystring = {
"blazon":blazon,
"outputformat":outputformat,
"size":"400"
}
headers = {
'cache-control': "no-cache"
}
r = requests.get(url,data=payload, headers=headers, params=querystring, stream=all)
if (debug):
result = r.json()
for message in result['messages']:
if message['category'] != 'legal':
messagetext = message['content']
if 'context' in message:
messagetext += " " + message['context']
print(messagetext)
display(Image(base64.b64decode(result['image'])))
print(result['mintree'])
else:
display(Image(r.content))
def define(term):
url = "https://drawshield.net/api/define/" + term
payload = ""
querystring = {
}
headers = {
'cache-control': "no-cache"
}
r = requests.get(url,data=payload, headers=headers, params=querystring, stream=all)
entry = r.json()
if 'error' in entry:
print(entry['error'])
else:
print(entry['content'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment