mirror of
https://github.com/jessebot/tiny_personal_website.git
synced 2025-10-01 01:48:43 +00:00
hahaha this is so hacky and bad
This commit is contained in:
parent
097a96e6a1
commit
9c64bfc955
2 changed files with 35 additions and 31 deletions
|
@ -1,8 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
#!/usr/bin/env python
|
||||
# script by jessebot@linux.com to get the bands and do the things
|
||||
# 1/7/19 -- 2019? D:
|
||||
import argparse
|
||||
import datetime
|
||||
import subprocess
|
||||
import sqlite3
|
||||
|
||||
|
@ -12,30 +11,12 @@ def add_new_band(band):
|
|||
Takes a str of a bands name and adds it to a sqlite3 db
|
||||
returns the string "Success" if all went well.
|
||||
"""
|
||||
now = str(datetime.datetime.now())
|
||||
|
||||
conn = sqlite3.connect('my-next-band.db')
|
||||
c = conn.cursor()
|
||||
|
||||
# Insert a row of data
|
||||
insert = '''INSERT INTO bands VALUES ('{0}','{1}')'''.format(band, now)
|
||||
try:
|
||||
c.execute(insert)
|
||||
# Save (commit) the changes
|
||||
conn.commit()
|
||||
except Exception as e:
|
||||
return e
|
||||
|
||||
# close db connection
|
||||
conn.close()
|
||||
|
||||
# create the band art!
|
||||
bashCommand = './generate_band_art.py --band "{0}"'.format(band)
|
||||
bashCommand = "./generate_band_art.py --band {0}".format(band)
|
||||
print bashCommand
|
||||
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
|
||||
output, error = process.communicate()
|
||||
log.info(output)
|
||||
if error:
|
||||
log.error(error)
|
||||
print output
|
||||
|
||||
# uh, idunno
|
||||
return "Success"
|
||||
|
|
39
generate_band_art.py
Normal file → Executable file
39
generate_band_art.py
Normal file → Executable file
|
@ -2,7 +2,9 @@
|
|||
# script by jessebot@linux.com to get the bands' art and do the things
|
||||
# 1/10/19 -- 2019? D:
|
||||
import argparse
|
||||
import datetime
|
||||
from google_images_download import google_images_download
|
||||
import sqlite3
|
||||
|
||||
|
||||
def generate_band_art(band):
|
||||
|
@ -14,22 +16,43 @@ def generate_band_art(band):
|
|||
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)
|
||||
"no_directory":"true",
|
||||
"no_numbering":"true", "limit":1})
|
||||
path = absolute_img_paths[keywd][0]
|
||||
art = path.replace("/var/www/jessebot.io/images/band/","")
|
||||
|
||||
conn = sqlite3.connect('my-next-band.db')
|
||||
c = conn.cursor()
|
||||
|
||||
# timestamp!
|
||||
now = str(datetime.datetime.now())
|
||||
|
||||
# Insert a row of data
|
||||
insert = '''INSERT INTO bands VALUES ('{0}','{1}','{2}')'''.format(band,
|
||||
now,
|
||||
art)
|
||||
print(insert)
|
||||
c.execute(insert)
|
||||
# Save (commit) the changes
|
||||
conn.commit()
|
||||
|
||||
# close db connection
|
||||
conn.close()
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Document cool band names.')
|
||||
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')
|
||||
parser.add_argument('--band', type=str, nargs='+', help='a COOL band name')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.band:
|
||||
generate_band_art(args.band)
|
||||
if type(args.band) == list:
|
||||
band = " ".join(args.band)
|
||||
else:
|
||||
band = args.band
|
||||
# make art
|
||||
generate_band_art(band)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue