mirror of
https://github.com/jessebot/tiny_personal_website.git
synced 2025-10-01 01:48:43 +00:00
added get-all arg, also pep8ed
This commit is contained in:
parent
ea413dd8ac
commit
8b9baa5583
1 changed files with 59 additions and 18 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue