Skip to content

Instantly share code, notes, and snippets.

@brianredbeard
Created December 5, 2017 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianredbeard/54e3df4bb35c11f8972bd0342ce25f9e to your computer and use it in GitHub Desktop.
Save brianredbeard/54e3df4bb35c11f8972bd0342ce25f9e to your computer and use it in GitHub Desktop.
Tool for fixing up CC output from The Noun Project
#!/usr/bin/env python3
# Brian 'redbeard' Harrington
# License: GPLv3
# For my presentations, I'm a huge fan of visual consistency and attribution
# This strips ugliness from assets from the noun projevct and outputs the things
# i need to attribute for my slides
`
import pathlib
import sys
from lxml import etree
def deleteNode(element):
for item in element:
item.getparent().remove(item)
def getNode(element):
for item in element:
return item.text
imagefile = pathlib.PurePath(sys.argv[1])
root = etree.parse(imagefile.as_posix()).getroot()
author = root.xpath(".//*[text()[contains(.,'Created by')]]")
site = root.xpath(".//*[text()[contains(.,'the Noun Project')]]")
a = getNode(author)
s = getNode(site)
print(a + ". Retrieved", s)
deleteNode(author)
deleteNode(site)
et = etree.ElementTree(root)
outfile = imagefile.with_suffix('.strip.svg')
et.write(outfile.as_posix())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment