37 lines
886 B
Python
Executable File
37 lines
886 B
Python
Executable File
#!/usr/bin/env python3
|
|
#
|
|
# http://github.com/mitchweaver/metal-archives
|
|
#
|
|
# get a given band pic from metal-archives.com
|
|
#
|
|
# Usage: ./band 'judas iscariot'
|
|
#
|
|
|
|
import sys
|
|
import urllib
|
|
from bs4 import BeautifulSoup
|
|
|
|
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()
|