Esempio n. 1
0
 def setUp(self):
     self.path = "test_book_standard.json"
     with open(self.path, "w") as handle:
         json.dump([], handle)
     self.book = Book(path=self.path)
     with open(self.path, "r") as handle:
         self.data = json.load(handle)
def main():
    for author in Author.objects:
        books = scrape_author(author.name, author.year)
        for book in books:
            year = book[0]
            title = book[1].encode('ascii', 'ignore')
            link = book[2]
            if not Book.objects(author=author.name, title=title,
                                year=year).count():
                Book(author=author.name,
                     title=title,
                     link=link,
                     year=year,
                     read=False).save()
Esempio n. 3
0
def index():
    # if someone visits the site, (GET request), show them the list of books
    if request.method == 'GET':
        author = request.args.get("author", None)
        # These render_template calls compile the data with the template at \templates\index.html
        if author:
            return render_template('index.html', author=author, books=Book.objects(read=False).order_by("-year"))
        return render_template('index.html', books=Book.objects(read=False).order_by("-year"))
    # handle an add author request
    elif request.method == 'POST':
        author = request.form['author']
        year = request.form['year']
        # Add the author to the database and reload the page
        Author(name=author, year=year).save()
        return redirect('/')
Esempio n. 4
0
def add_books():
    session = get_session(Base, engine)
    fields = request.get_json()

    # validate input
    if not all_fields_present(fields, ["password", "number_of_books", "isbn_code"]) or not validate_fields(fields):
        abort(422, "Невірні дані")

    # validate password
    library = session.query(Library).filter(Library.password == fields["password"]).first()
    if library is None:
        abort(422, "Неправильний пароль")

    # find book or create a new one
    book = session.query(Book).filter(Book.isbn_code == fields["isbn_code"]).first()
    if book is None:
        book_name = get_book_name(fields["isbn_code"])
        if book_name is None:
            abort(422, "Неіснуючий ISBN код")

        session.add(Book(isbn_code=fields["isbn_code"], name=book_name))
        book = session.query(Book).filter(Book.isbn_code == fields["isbn_code"]).first()

    # write or update record
    record = session.query(LibraryBook).filter(LibraryBook.book_id == book.id).filter(
        LibraryBook.library_id == library.id).first()
    if record is None:
        session.add(LibraryBook(library_id=library.id, book_id=book.id, number_of_books=fields["number_of_books"]))
    else:
        record.number_of_books += fields["number_of_books"]

    session.commit()
    return "Книги успішно додано", 200
Esempio n. 5
0
    def save_to_firebase(self):
        validation = self.validate()
        if validation:
            titulo = self.lineEdit_titulo.text()
            isbn = self.lineEdit_ISBN.text()
            numerodepaginas = self.lineEdit_numerodepaginas.text()
            ano = self.lineEdit_ano.text()
            genero = self.lineEdit_Genero.text()
            descricao = self.lineEdit_descricao.text()
            autor = self.lineEdit_autor.text()

            book = Book(isbn, titulo, numerodepaginas, genero, descricao, ano,
                        autor)

            db.child('books').push(book.to_dict())

            msg = QtWidgets.QMessageBox()
            msg.setIcon(QtWidgets.QMessageBox.NoIcon)
            msg.setText("Sucesso")
            msg.setInformativeText("Cadastrado com sucesso!")
            msg.setWindowTitle("Sucesso")
            msg.exec_()

            self.lineEdit_titulo.setText('')
            self.lineEdit_ISBN.setText('')
            self.lineEdit_numerodepaginas.setText('')
            self.lineEdit_ano.setText('')
            self.lineEdit_Genero.setText('')
            self.lineEdit_descricao.setText('')
            self.lineEdit_autor.setText('')

            if self.mainWindow:
                if loggedUser != None and loggedUser.level == LevelOfAccess.ADMIN:
                    self.mainWindow.stackedWidget.setCurrentIndex(4)
                else:
                    self.mainWindow.stackedWidget.setCurrentIndex(0)
        else:
            print("Validation Error")
Esempio n. 6
0
def test_charges_endpoint(client):
    book = Book().json()
    data = json.loads(book)
    response = client.post(
        "/charges",
        json=[data],
        headers={"Content-Type": "application/json"},
    )
    response.headers["Content-type"] = "application/json"
    payload = response.get_json()
    assert response.status_code == 200
    assert isinstance(payload, list)
    assert len(payload) == 1
    assert payload[0]["book_type"] == "REGULAR"
Esempio n. 7
0
async def load_markets():
    logger.info("loading markets")

    global EXS, MKTS
    tasks = [ex.handler.load_markets() for ex in EXS.values()]
    await asyncio.wait(tasks)

    for mkts in CONF['exchanges'].values():
        for mkt in mkts:
            if mkt not in MKTS:
                MKTS[mkt] = Market(mkt)

    for ex, mkts in CONF['exchanges'].items():
        all_markets = EXS[ex].handler.symbols
        for mkt in mkts:
            if mkt not in all_markets:
                logger.error("%s not supported by %s" % (mkt, ex))
                exit(1)

            book = Book(ex, mkt)
            MKTS[mkt].add_exchange(ex, book)
            EXS[ex].add_market(mkt, book)
Esempio n. 8
0
    def search_book(self):
        self.pushButton_editar.setVisible(False)
        self.textBrowser_info.setText('')
        titulo = self.lineEdit_buscar.text().upper()
        if (titulo in self.titulos):
            self.pushButton_editar.setVisible(True)
            for t in self.books:
                if (t.val()['title'].upper() == titulo):
                    self.textBrowser_info.setText(
                        "Título: {}\nAutor: {}\nGênero: {}\nISBN: {}\nDescrição: {}\nAno: {}\nNúmero de páginas: {}\n"
                        .format(t.val()['title'],
                                t.val()['author'],
                                t.val()['genre'],
                                t.val()['isbn'],
                                t.val()['description'],
                                t.val()['year'],
                                t.val()['pages']))
                    self.livro = Book.from_dict(t.val())

        else:
            print("nao achei")
            self.list_books()
Esempio n. 9
0
def readfile(name):
    lines = []
    with open(name, "r") as f:
        lines = f.readlines()
    top = lines[0].strip().split(" ")
    Data.nBooks = int(top[0])
    Data.nLibraries = int(top[1])
    Data.nScanningDays = int(top[2])
    for e in lines[1].strip().split(" "):
        Data.bookScores.append(int(e))

    for i, l in enumerate(lines[2::2]):
        lf = l.strip().split(" ")
        if lf[0] == '':
            continue
        lib = Library(int(lf[0]), int(lf[1]), int(lf[2]), i)
        Data.libraries.append(lib)

    for i, l in enumerate(lines[3::2]):
        lf = l.strip().split(" ")
        for e in lf:
            b = Book(int(e), Data.bookScores[int(e)])
            Data.libraries[i].books.append(b)
Esempio n. 10
0
def test_charges3_novel_less_than_min_days():
    book = Book()
    book.book_type = "NOVEL"
    assert book.charges3 == 4.5
Esempio n. 11
0
def mark_complete():
    the_id = request.args.get('id')
    # Add the book to the database and reload the page
    Book.objects(id=the_id).update(set__read=True)
    return redirect('/')
Esempio n. 12
0
# print(LevelOfAccess.COMMON_USER.value)

line = '192.168.125-00'

import re
line = re.sub('[.-]', '', line)

print(line)

exit()

booksRef = db.child('books')

from data import Book, User, LevelOfAccess

b = Book('1234567890123', 'Teste', "Editora", 'Genero', "Descrição do livro.",
         '2019', ['Fulano'])

print('sending ', b, ' to firebase...')
booksRef.push(b.to_dict())

u = User("*****@*****.**", "Fulano", "123467543091",
         LevelOfAccess.COMMON_USER)
db.child('users').child(u.email).set(u.to_dict())

docs = booksRef.get()

print("Data:")
print(docs.val())
'''
for doc in docs.val():
    print('Retrieved document ', doc.id, ' from Firebase: ', Book.from_dict(doc.to_dict()))
Esempio n. 13
0
class TestCard(unittest.TestCase):

    def setUp(self):
        self.path = "test_book_standard.json"
        with open(self.path, "w") as handle:
            json.dump([], handle)
        self.book = Book(path=self.path)
        with open(self.path, "r") as handle:
            self.data = json.load(handle)

    def tearDown(self):
        with open(self.path, "w") as handle:
            json.dump(self.data, handle, indent=2)

    def test_add_common(self):
        note = {"name": "Testname", "surname": "Testsurname", "phone": "88126215634", "birth_date": "01.01.1991"}
        self.book._add(note=note)
        self.assertTrue(self.book._exists(note=note))

    def test_add_existing(self):
        note = {"name": "Testname", "surname": "Testsurname", "phone": "88126215634", "birth_date": "01.01.1991"}
        self.book._add(note=note)
        with self.assertRaises(errors.DuplicateNote):
            self.book._add(note=note)

    def test_edit_name(self):
        note = {"name": "Testname", "surname": "Testsurname", "phone": "88126215634", "birth_date": "01.01.1991"}
        self.book._add(note=note)
        self.book._edit(_id=-1, to_edit={'name': "Editedname"})
        self.assertTrue(self.book._get(note_id=-1)['name'] == 'Editedname')

    def test_edit_all(self):
        note = {"name": "Testname", "surname": "Testsurname", "phone": "88126215634", "birth_date": "01.01.1991"}
        self.book._add(note=note)
        edited = {"name": "Editedname", "surname": "Editedsurname", "phone": "89361954672", "birth_date": "12.12.2009"}
        self.book._edit(_id=-1, to_edit=edited)
        self.assertDictEqual(self.book._get(note_id=-1), edited)

    def test_age(self):
        note = {"name": "Testname", "surname": "Testsurname", "phone": "88126215634", "birth_date": "01.01.1991"}
        self.book._add(note=note)
        self.assertEqual(self.book._age(note_id=-1)['years'], 29)

    def test_get(self):
        note = {"name": "Testname", "surname": "Testsurname", "phone": "88126215634", "birth_date": "01.01.1991"}
        self.book._add(note=note)
        self.assertDictEqual(self.book._get(note_id=-1), note)

    def test_get_all(self):
        with open(self.path, "r") as handle:
            read_json = json.load(handle)
            self.assertListEqual(read_json, self.book._get_all())

    def test_gap(self):
        self.assertEqual(self.book._gap(date=(datetime.now().day, datetime.now().month, datetime.now().year)), 365)

    def test_get_birthday_in(self):
        with open(self.path, "w") as handle:
            json.dump([], handle, indent=2)
        correct = []
        for i in range(10):
            day = (datetime.now().day + random.randint(0, 10)) % 30 + 1
            month = (datetime.now().month - random.randint(0, 1))
            date = ''.join(f"{day}.{month}.{datetime.now().year}")
            note = {"name": f"Testname_{i}",
                    "surname": f"Testsurname_{i}",
                    "phone": f"8812621563{i}",
                    "birth_date": date}
            if datetime.now().month == month:
                correct.append(note['name'])
            self.book._add(note=note)
        self.assertEqual(set([got['name'] for got in self.book.get_birthday_in(30)]), set(correct))

    def test_is_date_correct(self):
        self.assertTrue(self.book.is_date('01.01.2001'))

    def test_is_date_incorrect(self):
        self.assertFalse(self.book.is_date('56.01.2001'))

    def test_is_date_nodate(self):
        self.assertFalse(self.book.is_date('abc'))

    def test_phone_correct_1(self):
        self.assertEqual(self.book.correct_phone("+71234567890"), "81234567890")

    def test_phone_correct_2(self):
        self.assertEqual(self.book.correct_phone("+81234567890"), "81234567890")

    def test_phone_correct_3(self):
        self.assertEqual(self.book.correct_phone("71234567890"), "81234567890")

    def test_phone_incorrect_1(self):
        self.assertEqual(self.book.correct_phone("+712345678900"), "phone_error")

    def test_phone_incorrect_2(self):
        self.assertEqual(self.book.correct_phone("+71234"), "phone_error")

    def test_phone_incorrect_3(self):
        self.assertEqual(self.book.correct_phone("abcd"), "phone_error")

    def test_is_name_correct(self):
        self.assertTrue(self.book.is_name("Alex"))

    def test_is_name_correct_digits(self):
        self.assertTrue(self.book.is_name("Alex123"))

    def test_is_name_correct_spaces(self):
        self.assertTrue(self.book.is_name("Al ex"))

    def test_is_name_correct_short(self):
        self.assertTrue(self.book.is_name("Al"))

    def test_is_name_correct_spaces_digits(self):
        self.assertTrue(self.book.is_name("Al ex 34"))

    def test_is_name_incorrect(self):
        self.assertFalse(self.book.is_name("543"))

    def test_is_name_incorrect_lower(self):
        self.assertFalse(self.book.is_name("alex"))

    def test_is_name_incorrect_upper(self):
        self.assertFalse(self.book.is_name("ALEX"))

    def test_is_name_incorrect_middle_upper(self):
        self.assertFalse(self.book.is_name("AlEx"))

    def test_is_name_incorrect_empty(self):
        self.assertFalse(self.book.is_name(""))

    def test_is_name_incorrect_single(self):
        self.assertFalse(self.book.is_name("A"))

    def test_search_name_strict(self):
        for i in range(10):
            day = (datetime.now().day + random.randint(0, 10)) % 30 + 1
            month = (datetime.now().month - random.randint(0, 1))
            date = ''.join(f"{day}.{month}.{datetime.now().year}")
            note = {"name": f"Testname_{i}",
                    "surname": f"Testsurname_{i}",
                    "phone": f"8812621563{i}",
                    "birth_date": date}
            self.book._add(note=note)
        self.assertEqual(self.book.search(name='Testname_3', is_strict=True), 3)

    def test_search_surname_strict(self):
        for i in range(10):
            day = (datetime.now().day + random.randint(0, 10)) % 30 + 1
            month = (datetime.now().month - random.randint(0, 1))
            date = ''.join(f"{day}.{month}.{datetime.now().year}")
            note = {"name": f"Testname_{i}",
                    "surname": f"Testsurname_{i}",
                    "phone": f"8812621563{i}",
                    "birth_date": date}
            self.book._add(note=note)
        self.assertEqual(self.book.search(surname='Testsurname_2', is_strict=True), 2)

    def test_search_phone_strict(self):
        for i in range(10):
            day = (datetime.now().day + random.randint(0, 10)) % 30 + 1
            month = (datetime.now().month - random.randint(0, 1))
            date = ''.join(f"{day}.{month}.{datetime.now().year}")
            note = {"name": f"Testname_{i}",
                    "surname": f"Testsurname_{i}",
                    "phone": f"8812621563{i}",
                    "birth_date": date}
            self.book._add(note=note)
        self.assertEqual(self.book.search(phone='88126215632', is_strict=True), 2)

    def test_search_date_strict(self):
        _date = ''
        for i in range(10):
            day = (datetime.now().day + random.randint(0, 10)) % 30 + 1
            month = (datetime.now().month - random.randint(0, 1))
            date = ''.join(f"{day}.{month}.{datetime.now().year}")
            if i == 2:
                _date = date
            note = {"name": f"Testname_{i}",
                    "surname": f"Testsurname_{i}",
                    "phone": f"8812621563{i}",
                    "birth_date": date}
            self.book._add(note=note)
        self.assertEqual(self.book.search(birth_date=_date, is_strict=True), 2)

    def test_search_name_fuzzy(self):
        for i in range(10):
            day = (datetime.now().day + random.randint(0, 10)) % 30 + 1
            month = (datetime.now().month - random.randint(0, 1))
            date = ''.join(f"{day}.{month}.{datetime.now().year}")
            note = {"name": f"Testname_{i}",
                    "surname": f"Testsurname_{i}",
                    "phone": f"8812621563{i}",
                    "birth_date": date}
            note_2 = {"name": f"Nonono_{i}",
                    "surname": f"Testsurname_{i}",
                    "phone": f"8812621563{i}",
                    "birth_date": date}
            self.book._add(note=note)
            self.book._add(note=note_2)
        self.assertEqual(self.book.search(name='Testname_1', is_strict=False, output_range=3), [2, 0, 4])
Esempio n. 14
0
def test_charges3_fiction_1_days():
    book = Book(return_date=date.today() + timedelta(days=1))
    book.book_type = "FICTION"
    assert book.charges3 == 3
Esempio n. 15
0
def test_charges2_1_days():
    book = Book(return_date=date.today() + timedelta(days=1))
    assert book.charges2 == 1.5
Esempio n. 16
0
def test_charges3_novel_greater_than_min_days():
    book = Book(return_date=date.today() + timedelta(days=4))
    book.book_type = "NOVEL"
    assert book.charges3 == 6
Esempio n. 17
0
    except RuntimeError as e:
        print(e)

parser = argparse.ArgumentParser()
parser.add_argument("--embed_size", type=int, default=128)
parser.add_argument("--lr", type=float, default=1e-4)
parser.add_argument("--weight_decay", type=float, default=1e-4)
parser.add_argument("--epoch_size", type=int, default=10)
parser.add_argument("--batch_size", type=int, default=512)
parser.add_argument("--alpha", type=float, default=0.3)
parser.add_argument("-beta", type=float, default=10.)
parser.add_argument("--num_sample_step", type=int, default=100)
parser.add_argument("--seq_len", type=int, default=10)
arg = parser.parse_args()

book = Book()
book.g.discrete(arg.seq_len)
sample = RandomTemporalSubGraph(book.g, arg.batch_size, arg.num_sample_step)

# supervised
data = sample.supervised()
nodes = keras.layers.Input(shape=(), batch_size=arg.batch_size)
adjs = keras.layers.Input(shape=(arg.seq_len, None), batch_size=arg.batch_size)
nodes_embed = keras.layers.Embedding(input_dim=book.g.node_size,
                                     output_dim=arg.embed_size)(nodes)
o = keras.layers.RNN(
    GCRN2Cell(arg.embed_size, GraphAttention,
              {"units": arg.embed_size}))(adjs, initial_state=nodes_embed)
cls_o = keras.layers.Dense(book.g.label_size, activation="sigmoid")(o)
supervised_gcrn_ = keras.Model(inputs=(nodes, adjs), outputs=o)
supervised_gcrn = keras.Model(inputs=[nodes, adjs], outputs=cls_o)
Esempio n. 18
0
def test_charges3_regular_equal_to_min_days():
    book = Book(return_date=date.today() + timedelta(days=2))
    assert book.charges3 == 2
Esempio n. 19
0
def test_charges3_regular_less_than_min_days():
    book = Book()
    assert book.charges3 == 2
Esempio n. 20
0
def test_charges2_0_days():
    book = Book()
    assert book.charges2 == 0