You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#import click
|
|
|
|
#from flask import Flask
|
|
|
|
from app import app, db
|
|
|
|
from app.models import Book
|
|
|
|
from csv import DictReader
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
ap = argparse.ArgumentParser("import csv into flask")
|
|
|
|
ap.add_argument("csv", help = "csv file to import")
|
|
|
|
ap.add_argument("--limit", type=int, default = None, help = "limit to x number of x")
|
|
|
|
args = ap.parse_args()
|
|
|
|
|
|
|
|
with open(args.csv) as f:
|
|
|
|
for row in DictReader(f):
|
|
|
|
#print(row['Title'])
|
|
|
|
book = Book (row['Title'], "", "", row['Format'], row['Shelf'])
|
|
|
|
db.session.add(book)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
#app = Flask(__name__)
|
|
|
|
#books = db.session.query(Book).all()
|
|
|
|
#print(books)
|
|
|
|
|
|
|
|
# @app.cli.command()
|
|
|
|
# @click.argument('name')
|
|
|
|
# def import_csv(name):
|
|
|
|
# print("hello")
|