mirror of
https://github.com/jessebot/tiny_personal_website.git
synced 2025-10-01 01:48:43 +00:00
it downloads images now!
This commit is contained in:
parent
58ee4cf48f
commit
5028e05139
2 changed files with 21 additions and 11 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -13,3 +13,4 @@ robots.txt
|
|||
bands.db
|
||||
images/favicon.ico
|
||||
images/jesserecent.jpg
|
||||
views/google1ab5c73d1f31729d.html
|
||||
|
|
|
@ -1,19 +1,25 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# script by jessebot@linux.com to get the bands and do the things
|
||||
# 1/7/19 -- 2019? D:
|
||||
import argparse
|
||||
import datetime
|
||||
import random
|
||||
import sqlite3
|
||||
from google_images_download import google_images_download
|
||||
|
||||
|
||||
def generate_band_art(band):
|
||||
categories = ['abstract', 'animals', 'business', 'cats', 'city', 'food',
|
||||
'night', 'life', 'fashion', 'people', 'nature', 'sports',
|
||||
'technics', 'transport']
|
||||
category = random.choice(categories)
|
||||
url = "http://lorempixel.com/400/400/{0}/{1}".format(category, band)
|
||||
|
||||
# change image results by making different key words
|
||||
band_list = band.split()
|
||||
last_item = len(band_list) - 1
|
||||
keywd = band_list[last_item]
|
||||
# google image
|
||||
response = google_images_download.googleimagesdownload()
|
||||
absolute_img_paths = response.download({"keywords":keywd, "size":"medium",
|
||||
"output_directory":"./images/band",
|
||||
"no_directory":"true", "limit":1})
|
||||
print(type(absolute_img_paths))
|
||||
print(absolute_img_paths)
|
||||
|
||||
def add_new_band(band):
|
||||
"""
|
||||
|
@ -34,8 +40,11 @@ def add_new_band(band):
|
|||
except Exception as e:
|
||||
return e
|
||||
|
||||
# close connection
|
||||
# close db connection
|
||||
conn.close()
|
||||
|
||||
# create the band art!
|
||||
generate_band_art(band)
|
||||
|
||||
# uh, idunno
|
||||
return "Success"
|
||||
|
@ -68,7 +77,7 @@ def main():
|
|||
Let's get it on! *cracks whip*
|
||||
"""
|
||||
parser = argparse.ArgumentParser(description='Document cool band names.')
|
||||
parser.add_argument('--band', nargs='?', type=str,
|
||||
parser.add_argument('--add-band', dest='band', nargs='?', type=str,
|
||||
help='a COOL band name')
|
||||
parser.add_argument('--get-all', dest='get_all', action='store_true',
|
||||
help='list all cool band names')
|
||||
|
@ -76,10 +85,10 @@ def main():
|
|||
args = parser.parse_args()
|
||||
|
||||
if args.band:
|
||||
print add_new_band(args.band)
|
||||
print(add_new_band(args.band))
|
||||
|
||||
if args.get_all:
|
||||
print get_all_bands()
|
||||
print(get_all_bands())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue