initial commit
This commit is contained in:
35
band
Executable file
35
band
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/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()
|
||||
Reference in New Issue
Block a user