<commit_before>"""Save and retrieve boog data"""
from datetime import date
import os
import hashlib
import cherrypy
from random import random

from lib.variables import book_empty_default
from lib.sanity_check import sanity_check
import lib.db_books as db_books

def get_book_data(username, book_id):
    """Retrieve and prepare book data for displaying"""
    book_empty = book_empty_default()
    if book_id in ['new_book', 'new_comic', 'new_audiobook']:
        book = book_empty
        book['add_date'] = str(date.today())
        if book_id == 'new_comic':
            book['type'] = 'comic'
        elif book_id == 'new_audiobook':
            book['type'] = 'audiobook'
        else:
            book['type'] = 'book'
    else:
        book = db_books.get_by_id(username, book_id)
        for key, value in book_empty.items():
            if key not in book or book[key] == None:
                book[key] = value
        book['_id'] = str(book['_id'])
    return book

def save_book_data(username, params):
    """Save and clean up book data"""
    book_id = params['book_id']
    params, error = sanity_check(params)
    params['book_id'] = book_id
    if error != "0":
        return None, error
    if params['book_id'] == 'new_book':<commit_msg>Bug fix<commit_after>"""Save and retrieve boog data"""
from datetime import date
import os
import hashlib
import cherrypy
from random import random

from lib.variables import book_empty_default
from lib.sanity_check import sanity_check
import lib.db_books as db_books
from lib.templates import ORDER

def get_book_data(username, book_id):
    """Retrieve and prepare book data for displaying"""
    book_empty = book_empty_default()
    if book_id[4:] in ORDER:
        book = book_empty
        book['add_date'] = str(date.today())
        book['type'] = book_id[4:]
    else:
        book = db_books.get_by_id(username, book_id)
        for key, value in book_empty.items():
            if key not in book or book[key] == None:
                book[key] = value
        book['_id'] = str(book['_id'])
    return book

def save_book_data(username, params):
    """Save and clean up book data"""
    book_id = params['book_id']
    params, error = sanity_check(params)
    params['book_id'] = book_id
    if error != "0":
        return None, error
    if params['book_id'] == 'new_book':
{'fraction_non_alphanumeric': 0.113384484228474, 'fraction_numerical': 0.0017050298380221654, 'mean_word_length': 3.0746527777777777, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5956388', 'n_tokens_mistral': 744, 'n_tokens_neox': 723, 'n_words': 219}