Skip to content

Commit

Permalink
adds individual book files, loader script for books into db
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Castilla committed Jan 12, 2022
1 parent 39e7d9e commit 2afa742
Show file tree
Hide file tree
Showing 673 changed files with 50,381 additions and 0 deletions.
58 changes: 58 additions & 0 deletions ru204/book_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Redis OM defaults to localhost:6379
# This can be overridden by add REDIS_OM_URL env variable with format:
# redis://user:password@hostname:port/db_number'

import os
import io
import json

from redis_om import (
JsonModel,
Field,
Migrator,
)

class Book(JsonModel):
author_name:str = Field(index=True, full_text_search=True)
base_id:int = Field(index=True)
book_description:str = Field(index=True, full_text_search=True)
book_title:str = Field(index=True, full_text_search=True)
editions:list[str]
genres:dict
inventory:list[dict]
metrics:dict
original_book_title:str = Field(index=True, full_text_search=True),
pages:int = Field(index=True),
url:str
year_published:int = Field(index=True)

class Meta:
global_key_prefix = "book:"

def populate_books(directory):
# iterate over files in given directory
for filename in os.listdir(directory):
f = os.path.join(directory, filename)
# checking if it is a file
if os.path.isfile(f):
book_json = io.open(f, encoding="utf-8")
data = json.load(book_json)
Book(
author_name=data['author_name'],
base_id=data['base_id'],
book_description=data['book_description'],
book_title=data['book_title'],
editions=data['editions'],
genres=data['genres'],
inventory=data['inventory'],
metrics=data['metrics'],
original_book_title=data['original_book_title'],
pages=data['pages'],
url=data['url'],
year_published=data['year_published']
).save()


Migrator().run()

populate_books('books')
47 changes: 47 additions & 0 deletions ru204/books/100.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"author_name": "Pittacus Lore",
"base_id": 100,
"book_description": "Journal: ( 1 | 2 | 3 | 4 | 5 | 6 | 7 )",
"book_title": "Sam's Journal",
"editions": [
"English"
],
"genres": {
"aliens": 19,
"dystopia": 3,
"fantasy": 17,
"fiction": 9,
"novella": 7,
"science fiction": 36,
"science fiction fantasy": 3,
"short stories": 16,
"supernatural": 3,
"young adult": 42
},
"inventory": [
{
"status": "maintenance",
"stock_number": "100_1"
},
{
"status": "maintenance",
"stock_number": "100_2"
},
{
"status": "maintenance",
"stock_number": "100_3"
},
{
"status": "on_loan",
"stock_number": "100_4"
}
],
"metrics": {
"rating_votes": 2002,
"score": 3.6
},
"original_book_title": "English",
"pages": 1299,
"url": "https://www.goodreads.com/book/show/15845821-sam-s-journal",
"year_published": 2012
}
55 changes: 55 additions & 0 deletions ru204/books/1003.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"author_name": "Margaret Stohl",
"base_id": 1003,
"book_description": "Your heart beats only with their permission.Everything changed on The Day. The day the windows shattered. The day the power stopped. The day Dol's family dropped dead. The day Earth lost a war it didn't know it was fighting.Since then, Dol has lived a simple life in the countryside -- safe from the shadow of the Icon and its terrifying power. Hiding from the one truth she can't avoid.She's different. She survived. Why?When Dol and her best friend, Ro, are captured and taken to the Embassy, off the coast of the sprawling metropolis once known as the City of Angels, they find only more questions. While Ro and fellow hostage Tima rage against their captors, Dol finds herself drawn to Lucas, the Ambassador's privileged son. But the four teens are more alike than they might think, and the timing of their meeting isn't a coincidence. It's a conspiracy.Within the Icon's reach, Dol, Ro, Tima, and Lucas discover that their uncontrollable emotions -- which they've always thought to be their greatest weaknesses -- may actually be their greatest strengths.Bestselling author Margaret Stohl delivers the first book in a heart-pounding series set in a haunting new world where four teens must piece together the mysteries of their pasts -- in order to save the future.",
"book_title": "Icons",
"editions": [
"English"
],
"genres": {
"aliens": 75,
"audiobook": 21,
"dystopia": 201,
"fantasy": 72,
"fiction": 38,
"paranormal": 33,
"post apocalyptic": 45,
"romance": 39,
"science fiction": 160,
"young adult": 293
},
"inventory": [
{
"status": "available",
"stock_number": "1003_1"
},
{
"status": "maintenance",
"stock_number": "1003_2"
},
{
"status": "available",
"stock_number": "1003_3"
},
{
"status": "maintenance",
"stock_number": "1003_4"
},
{
"status": "available",
"stock_number": "1003_5"
},
{
"status": "on_loan",
"stock_number": "1003_6"
}
],
"metrics": {
"rating_votes": 7856,
"score": 3.41
},
"original_book_title": "Icons",
"pages": 219,
"url": "https://www.goodreads.com/book/show/11861715-icons",
"year_published": 2013
}
51 changes: 51 additions & 0 deletions ru204/books/101.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"author_name": "Pittacus Lore",
"base_id": 101,
"book_description": "In this spectacular one-hundred-page companion novella to the New York Times bestselling I Am Number Four series, learn how Loric hacker Lexa became the shadowy figure known as GUARD.A sequel to I Am Number Four: The Lost Files: The Navigator, this novella picks up with Lexa shortly after the Mogadorians raided her hideout and murdered her friend. Determined to get her revenge but knowing she can't take the Mogs head on, Lexa goes in search of a weapon that just might help her do some real damage: the spaceship the Garde flew to Earth. The only problem is it's under lock and key at a highly guarded base in Dulce, New Mexico.Lexa's quest to retrieve the ship and track down the Garde has her cross paths with an ally of Pittacus Lore, come under fire from both the FBI and the Mogs, and team up with a headstrong teenager from Paradise, Ohio, by the name of Mark James. To get her secret weapon, Lexa will do whatever it takes. But as the Mogadorians begin their invasion, will it be enough to help save the Garde\u2014and the world?",
"book_title": "The Guard",
"editions": [
"English"
],
"genres": {
"adventure": 4,
"aliens": 17,
"dystopia": 3,
"fantasy": 32,
"fiction": 16,
"novella": 11,
"science fiction": 33,
"short stories": 10,
"teen": 6,
"young adult": 47
},
"inventory": [
{
"status": "maintenance",
"stock_number": "101_1"
},
{
"status": "on_loan",
"stock_number": "101_2"
},
{
"status": "maintenance",
"stock_number": "101_3"
},
{
"status": "on_loan",
"stock_number": "101_4"
},
{
"status": "maintenance",
"stock_number": "101_5"
}
],
"metrics": {
"rating_votes": 2089,
"score": 4.13
},
"original_book_title": "\n0062364030\n(ISBN13: 9780062364036)\n",
"pages": 459,
"url": "https://www.goodreads.com/book/show/23507369-the-guard",
"year_published": 2015
}
43 changes: 43 additions & 0 deletions ru204/books/1010.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"author_name": "R. Lee Smith",
"base_id": 1010,
"book_description": "It was her last chance:Amber Bierce had nothing left except her sister and two tickets on Earth\u2019s first colony-ship. She entered her Sleeper with a five-year contract and the promise of a better life, but awakened in wreckage on an unknown world. For the survivors, there is no rescue, no way home and no hope until they are found by Meoraq\u2014a holy warrior more deadly than any hungering beast on this hostile new world\u2026but whose eyes show a different sort of hunger when he looks at her.It was his last year of freedom:Uyane Meoraq is a Sword of Sheul, God\u2019s own instrument of judgment, victor of hundreds of trials, with a conqueror\u2019s rights over all men. Or at least he was until his father\u2019s death. Now, without divine intervention, he will be forced to assume stewardship over House Uyane and lose the life he has always known. At the legendary temple of Xi\u2019Matezh, Meoraq hopes to find the deliverance he seeks, but the humans he encounters on his pilgrimage may prove too great a test even for him\u2026especially the one called Amber, behind whose monstrous appearance burns a woman\u2019s heart unlike any he has ever known.",
"book_title": "The Last Hour of Gann",
"editions": [
"English"
],
"genres": {
"adult": 43,
"aliens": 203,
"dark": 104,
"erotica": 45,
"fantasy": 127,
"horror": 36,
"paranormal": 40,
"romance": 232,
"science fiction": 308,
"science fiction romance": 48
},
"inventory": [
{
"status": "maintenance",
"stock_number": "1010_1"
},
{
"status": "available",
"stock_number": "1010_2"
},
{
"status": "on_loan",
"stock_number": "1010_3"
}
],
"metrics": {
"rating_votes": 5474,
"score": 4.09
},
"original_book_title": "The Last Hour of Gann",
"pages": 1342,
"url": "https://www.goodreads.com/book/show/18589656-the-last-hour-of-gann",
"year_published": 2013
}
59 changes: 59 additions & 0 deletions ru204/books/1013.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"author_name": "Nnedi Okorafor",
"base_id": 1013,
"book_description": "When a massive object crashes into the ocean off the coast of Lagos, Nigeria\u2019s most populous and legendary city, three people wandering along Bar Beach (Adaora, the marine biologist- Anthony, the rapper famous throughout Africa- Agu, the troubled soldier) find themselves running a race against time to save the country they love and the world itself\u2026 from itself. Told from multiple points of view and crisscrossing narratives, combining everything from superhero comics to Nigerian mythology to tie together a story about a city consuming itself. \u2018There was no time to flee. No time to turn. No time to shriek. And there was no pain. It was like being thrown into the stars.\u2019",
"book_title": "Lagoon",
"editions": [
"English"
],
"genres": {
"Africa": 102,
"Nigeria": 39,
"adult": 40,
"aliens": 53,
"fantasy": 256,
"fiction": 230,
"science fiction": 494,
"science fiction fantasy": 48,
"speculative fiction": 72,
"urban fantasy": 29
},
"inventory": [
{
"status": "maintenance",
"stock_number": "1013_1"
},
{
"status": "available",
"stock_number": "1013_2"
},
{
"status": "on_loan",
"stock_number": "1013_3"
},
{
"status": "available",
"stock_number": "1013_4"
},
{
"status": "available",
"stock_number": "1013_5"
},
{
"status": "on_loan",
"stock_number": "1013_6"
},
{
"status": "on_loan",
"stock_number": "1013_7"
}
],
"metrics": {
"rating_votes": 5904,
"score": 3.63
},
"original_book_title": "Lagoon",
"pages": 708,
"url": "https://www.goodreads.com/book/show/18753656-lagoon",
"year_published": 2014
}
67 changes: 67 additions & 0 deletions ru204/books/10149.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"author_name": "John Scalzi",
"base_id": 10149,
"book_description": "Ensign Andrew Dahl has just been assigned to the Universal Union Capital Ship Intrepid, flagship of the Universal Union since the year 2456. It\u2019s a prestige posting, and Andrew is thrilled all the more to be assigned to the ship\u2019s Xenobiology laboratory.Life couldn\u2019t be better\u2026until Andrew begins to pick up on the fact that: (1) every Away Mission involves some kind of lethal confrontation with alien forces (2) the ship\u2019s captain, its chief science officer, and the handsome Lieutenant Kerensky always survive these confrontations (3) at least one low-ranked crew member is, sadly, always killed.Not surprisingly, a great deal of energy below decks is expended on avoiding, at all costs, being assigned to an Away Mission. Then Andrew stumbles on information that completely transforms his and his colleagues\u2019 understanding of what the starship Intrepid really is\u2026and offers them a crazy, high-risk chance to save their own lives.",
"book_title": "Redshirts",
"editions": [
"English"
],
"genres": {
"audiobook": 346,
"comedy": 231,
"fantasy": 219,
"fiction": 1161,
"humor": 971,
"science fiction": 3602,
"science fiction fantasy": 289,
"space": 119,
"space opera": 130,
"time travel": 198
},
"inventory": [
{
"status": "available",
"stock_number": "10149_1"
},
{
"status": "maintenance",
"stock_number": "10149_2"
},
{
"status": "available",
"stock_number": "10149_3"
},
{
"status": "available",
"stock_number": "10149_4"
},
{
"status": "maintenance",
"stock_number": "10149_5"
},
{
"status": "available",
"stock_number": "10149_6"
},
{
"status": "available",
"stock_number": "10149_7"
},
{
"status": "available",
"stock_number": "10149_8"
},
{
"status": "available",
"stock_number": "10149_9"
}
],
"metrics": {
"rating_votes": 88771,
"score": 3.85
},
"original_book_title": "Redshirts",
"pages": 871,
"url": "https://www.goodreads.com/book/show/13055592-redshirts",
"year_published": 2012
}
Loading

0 comments on commit 2afa742

Please sign in to comment.