#!/usr/bin/env python3 # # http://github.com/mitchweaver/bin # # get a given band logo from metal-archives.com # from bs4 import BeautifulSoup import urllib import sys def band_logo(band): try: url = 'https://www.metal-archives.com/bands/' + band.replace(' ', '_').lower() def get_soup(url,header): return BeautifulSoup(urllib.request.urlopen(urllib.request.Request(url,headers=header)), "html5lib") header = {'User-Agent': 'Mozilla/5.0'} image_urls = [a['src'] for a in get_soup(url, header).find_all("img")] image = urllib.request.urlopen(image_urls[1]).read() file = open("./logo.jpg", 'wb') file.write(image) file.close() except: print("Error - can't find it?") def main(): band_logo(sys.argv[1]) if __name__ == "__main__": main()