commit
972f5f5ec7
@ -0,0 +1 @@
|
||||
database/*
|
@ -0,0 +1,87 @@
|
||||
#!/bin/python
|
||||
#My personal small anime database \\ ^^ //
|
||||
|
||||
import sqlite3
|
||||
import sys, getopt
|
||||
|
||||
def main(argv):
|
||||
#global variables
|
||||
|
||||
##
|
||||
try:
|
||||
opts, args = getopt.getopt(argv, 'ail')
|
||||
except getopt.GetoptError:
|
||||
help()
|
||||
sys.exit(2)
|
||||
|
||||
#check if we got an cli option
|
||||
if not opts:
|
||||
help()
|
||||
sys.exit(2)
|
||||
|
||||
#loop over all options
|
||||
for opt, arg in opts:
|
||||
if opt == '-h':
|
||||
help()
|
||||
sys.exit()
|
||||
elif opt == '-i':
|
||||
int_db()
|
||||
elif opt == '-l':
|
||||
show_db()
|
||||
elif opt == '-a':
|
||||
add_db(get_input())
|
||||
def help():
|
||||
print(""" usage:
|
||||
-i init db
|
||||
-l show db
|
||||
-a add entry to db
|
||||
-f file (parse text from a file)
|
||||
""")
|
||||
|
||||
def int_db():
|
||||
conn.execute('''CREATE TABLE anime
|
||||
(id INT PRIMARY KEY NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
curep INT NOT NULL,
|
||||
maxep INT,
|
||||
state TEXT,
|
||||
rating INT);''')
|
||||
print ('Database created successfully')
|
||||
|
||||
def show_db():
|
||||
for row in conn.execute('SELECT * FROM anime ORDER BY id'):
|
||||
print(row)
|
||||
|
||||
def add_db(db_input):
|
||||
conn.execute("insert into anime values (?, ?, ?, ?, ?, ?)", (db_input))
|
||||
conn.commit()
|
||||
|
||||
def get_input():
|
||||
db_input = ()
|
||||
|
||||
#Get last DB ID and add +1
|
||||
cursor = conn.execute("SELECT max(id) FROM anime")
|
||||
id = cursor.fetchone()[0]
|
||||
if id != None:
|
||||
id += 1
|
||||
else:
|
||||
id = 1
|
||||
|
||||
|
||||
name = input('Name: ')
|
||||
curep = input('Current Episode: ')
|
||||
maxep = input('Maximum number of Episodes: ')
|
||||
state = input('State: (planning, running, finished, dropped) ')
|
||||
rating = input('Rating: (1-10) ')
|
||||
|
||||
#TODO: Input validation
|
||||
|
||||
db_input = (id, name, curep, maxep, state, rating)
|
||||
#print(db_input)
|
||||
return db_input
|
||||
|
||||
|
||||
#Start of Programm
|
||||
#always try to open db
|
||||
conn = sqlite3.connect('../database/test.db')
|
||||
main(sys.argv[1:])
|
Loading…
Reference in new issue