Files
metal-archives/band
Mitch Weaver 39eb9205cf initial commit
2018-04-23 17:56:32 +02:00

36 lines
871 B
Python
Executable File

#!/usr/bin/env python3
#
# http://github.com/mitchweaver/bin
#
# get a given band pic from metal-archives.com
#
# Usage: ./band 'judas iscariot'
#
from bs4 import BeautifulSoup
import urllib
import sys
def band_pic(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[2]).read()
file = open("./band.jpg", 'wb')
file.write(image)
file.close()
except:
print("Error - can't find it?")
def main():
band_pic(sys.argv[1])
if __name__ == "__main__": main()