Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/env python3
"""
Alex Hogen (code.ahogen@outlook.com)
Compare Anybadge to Sheilds.io SVG badges.
"""
import os
import sys
import shutil
import urllib
import requests
import anybadge # I have v1.4.0
if __name__ == '__main__':
if sys.version_info < (3, 5, 0):
sys.stderr.write("You need Python 3.5 or later to run this script\n")
sys.exit(1)
badge_name = 'CppCheck'
badge_text = 'err: 1 | warn: 2 | style: 190 | info: 19'
badge_color = '#E05D44' # red
fname_anybadge = os.path.abspath(badge_name + '.ab.svg')
fname_shieldio = os.path.abspath(badge_name + '.svg')
# GET ANYBADGE BADGE
badge = anybadge.Badge(label=badge_name,
value=badge_text,
default_color=badge_color,
num_padding_chars=0)
print('Anybadge:', fname_anybadge)
badge.write_badge(fname_anybadge, overwrite=True)
# GET SHIELDS.IO BADGE
shield_url = 'http://img.shields.io/badge/' + badge_name + '-'
shield_url += badge_text + '-'
shield_url += badge_color + '.svg?style=flat'
shield_url = urllib.parse.quote(shield_url, safe=':/?-&')
#print("Shield URL: ", shield_url)
req = requests.get(shield_url, stream=True)
if req.status_code == 200:
print('Shields.io:', fname_shieldio)
with open(fname_shieldio, 'wb') as f:
req.raw.decode_content = True
shutil.copyfileobj(req.raw, f)
else:
raise RuntimeWarning('HTTP req returned:', req.status_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment