added get-all arg, also pep8ed

This commit is contained in:
JesseBot 2019-01-08 08:15:05 +00:00
parent ea413dd8ac
commit 8b9baa5583

View file

@ -6,39 +6,80 @@ import sqlite3
import datetime
import time
def adapt_datetime(ts):
"""
Internet says I need dis
"""
return time.mktime(ts.timetuple())
def main ():
def add_new_band(band):
"""
Takes a str of a bands name and adds it to a sqlite3 db
returns True?
"""
now = str(datetime.datetime.now())
conn = sqlite3.connect('bands.db')
c = conn.cursor()
# Insert a row of data
insert = '''INSERT INTO bands VALUES ('{0}','{1}')'''.format(args.band,
now)
c.execute(insert)
# Save (commit) the changes
conn.commit()
# close connection
conn.close()
# uh, idunno
return True
def get_all_bands():
"""
grabs all the bands from sqlite3 db
- returns a list of tuples with 2 strings of band_name, and time_stamp
"""
conn = sqlite3.connect('bands.db')
c = conn.cursor()
# Insert a row of data
get = '''SELECT * FROM bands'''
c.execute(get)
# print(c.fetchall())
all_bands = c.fetchall()
# close connection
conn.close()
return all_bands
def main():
"""
Let's get it on! *cracks whip*
"""
parser = argparse.ArgumentParser(description='Document cool band names.')
parser.add_argument('--band', nargs='?', type=str,
help='a COOL band name')
parser.add_argument('--get-all-bands', dest='get_all', action='store_true',
help='list all cool band names')
args = parser.parse_args()
print((args.band))
now = str(datetime.datetime.now())
conn = sqlite3.connect('bands.db')
c = conn.cursor()
if args.band:
add_new_band(args.band)
if args.get_all:
get_all_bands()
# Insert a row of data
insert = '''INSERT INTO bands VALUES ('{0}','{1}')'''.format(args.band, now)
c.execute(insert)
# Save (commit) the changes
conn.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()
if __name__ == "__main__":
main()