Created
April 19, 2021 14:55
-
-
Save karlwilcox/d14ccdb9149cb7ce429b337b2478ffbd to your computer and use it in GitHub Desktop.
Code to embed DrawShield shield renders and heraldic definitions in Jupyter Notebooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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