42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
#!/usr/bin/env python
|
|
|
|
from sqlalchemy.orm import Session
|
|
from src.infra.publication import (
|
|
PublicationEntryModel,
|
|
PublicationSequenceModel,
|
|
PublicationModel,
|
|
PublicationOrderModel,
|
|
)
|
|
import argparse
|
|
import os
|
|
from src.config.database import Database
|
|
from src.infra.db import get_database
|
|
|
|
if __name__ == '__main__':
|
|
arg_parser = argparse.ArgumentParser('seed.py', 'run to load seed data into a database')
|
|
arg_parser.add_argument('-u', '--url', help='The URL for the database', required=True)
|
|
arg_parser.add_argument('-d', '--data', help='the directory containing large content files', required=True)
|
|
args = arg_parser.parse_args()
|
|
|
|
with open(os.path.join(args.data, './a-study-in-scarlet.txt')) as infile:
|
|
text = infile.read()
|
|
|
|
db = get_database(Database(url=args.url, echo=True))
|
|
with Session(db) as session:
|
|
entry = PublicationEntryModel(text=text)
|
|
session.add(entry)
|
|
publication = PublicationModel(
|
|
title='Sherlock Holmes Canon',
|
|
description='A collection of detective mystery novels featuring Sherlock Holmes',
|
|
by_line='Sir Arthur Conan Doyle',
|
|
)
|
|
session.flush()
|
|
order = PublicationOrderModel(title='Published Timeline', publication_id=publication.id)
|
|
session.flush()
|
|
sequence = PublicationSequenceModel(
|
|
position=0,
|
|
entry_id=entry.id,
|
|
order_id=order.id,
|
|
duration=None,
|
|
)
|
|
session.commit()
|