def view_authros(): authors = None if request.method == 'GET': req = request.args if req.get('name') and req.get('name') != "": authors = Author.find_by_name(req.get('name')) return render_template('authors.html', authors=[authors]) if not authors: authors = Author.get_all_authors() if authors: return render_template('authors.html', authors=authors) return render_template('index.html') if request.method == 'POST': form = request.form if form["target"] == 'delete': if Author.delete_author_by_id(form["id"]): authors = Author.get_all_authors() if (authors): return render_template('authors.html', authors=authors) return render_template('index.html')
def update_author(): authors = None author = None if request.method == 'GET': author = Author.find_by_id(request.args.get('id')) if request.method == 'POST': form = request.form author = Author.find_by_id(form('id')) if author: author.name = form['name'] author.update_author() if author: author.set_author_books() return render_template('authors.html', authors=[author]) authors = Book.get_all_authors() if authors: for author in authors: author.set_author_books() return render_template('authors.html', authors=authors) return render_template('index.html')
def setUp(self): db.create_all() author1 = Author('Matt') author2 = Author('Elie') tag1 = Tag('Sci Fi') tag2 = Tag('Horror') tag3 = Tag('Biography') db.session.add_all([author1, author2, tag1, tag2, tag3]) db.session.commit() book1 = Book('Night of the Living Decorator', author2.id) book1.tags = [tag2] book2 = Book("Matt's Scary Sci Fi book", author1.id) book2.tags = [tag1, tag2] db.session.add_all([book1, book2]) db.session.commit()
def test_duplicate_author(self): author = Author("Rafael") db.session.add(author) db.session.commit() self.args['author_name'] = 'Rafael' json_result = rating_book_request_impl(self.args) assert "error" not in json_result
def _add_authors() -> List[Author]: """Dodawanie autorów książki.""" next_author: str = 't' authors: List[str] = [] while next_author == 't': authors.append(input("Imię i nazwisko autora: ")) next_author = input("Następny autor [t/n]?") result: List[Author] = [] for author_name in authors: try: first_name, last_name = author_name.split(' ') except ValueError: first_name, last_name = author_name, None author = Author().get_or_create( first_name=FirstName().get_or_create(name=first_name)[0], last_name=LastName().get_or_create( name=last_name)[0] if last_name else None, )[0] result.append(author) return result
def add_author(self): self.author = Author(first_name=self.author_first_name, last_name=self.author_last_name, image='', image_caption='') db.session.add(self.author) db.session.commit()
def post(self): info = json.loads(request.data) parse = info['author'] try: result = Author( first_name=parse['first_name'], last_name=parse['last_name'], ) orm.commit() return jsonify(result.to_dict()) except Exception as exception: return exception
def select_all(): authors = [] sql = "SELECT * FROM authors" results = run_sql(sql) for row in results: author = Author(row['name'], row['id']) authors.append(author) return authors
def select(id): author = None sql = "SELECT * FROM authors WHERE id=%s" values = [id] result = run_sql(sql, values)[0] if result is not None: author = Author(result['name'], result['id']) return author
def select(id): author = None sql = "SELECT * FROM authors WHERE id = %s" values = [id] result = run_sql(sql, values) if result is not None: author = Author(result[0]["name"], result[0]["id"]) return author
def add_author(self, name_): # on controle l'author s'il deja exist à dictionnaires if not (name_ in self.authors): self.authors[name_] = Author(name_) self.id2aut[self.naut] = name_ self.naut += 1 # si Oui on eleve un Exception personnalisee else: raise AuthorError(name_)
def get(self, id): try: if not Author.exists(lambda author: author.id == int(id)): return None, 404 return jsonify(Author[int(id)].to_dict()) except Exception as exception: return exception, 404
def select_all(): authors = [] sql = "SELECT * FROM authors" results = run_sql(sql) for row in results: author = Author(row["name"], row["books_written"], row["id"]) authors.append(author) return authors
def authors(author): authors = [] sql = "SELECT * FROM authors WHERE author_id = %s" values = [author.id] results = run_sql(sql, values) for row in results: author = Author(row['first_name'], row['last_name'], row['id']) authors.append(author) return authors
def __init__(self, user): self.user = user.id self.user_vec = ProfileOneHotEncoder.add_info_to_vec(self.user.vector, self.user.gender, self.user.location, self.user.emotion) self.graph = Author.load_graph() self.graph.add_node(user.id) favorite_tweets = DB.get_instance().query(Favorite.tweet_id).filter(Favorite.user_id == user.id) self.authors_liked = DB.get_instance().query(Tweet.user_name).filter( Tweet.id.in_(favorite_tweets.subquery())).all() for a in self.authors_liked: self.graph.add_edge(user.id, a[0])
def select_all(): authors = [] sql = "SELECT * FROM authors" results = run_sql(sql) for row in results: book = book_repository.select(row['book_id']) author = Author(row['first_name'], row['last_name'], row['id']) authors.append(author) return authors
def select_author_by(id): # Create the sql query sql = 'SELECT * FROM authors WHERE id = %s' values = [id] result = run_sql(sql, values) # Create a new author object if a result is returned from db if len(result) > 0: new_author = Author(result[0]['first_name'], result[0]['last_name'], result[0]['id']) return new_author
def select_all(): author_list = [] sql = "SELECT * FROM authors" results = run_sql(sql) for row in results: author = Author(row['first_name'], row["last_name"]) author_list.append(author) return author_list
def delete(self, id): try: if not Author.exists(lambda author: author.id == int(id)): return None, 404 Author[int(id)].delete() return None, 200 except Exception as exception: return exception
def get_author(self, author_id: int, project_uid: int, model_id: int, similarity=None, source_id=None) -> Author: query = """ MATCH (a:Author) WHERE a.prior_{uid}=TRUE AND a.author_id= $aId RETURN a.author_id, a.name""".format(uid=project_uid, _id=model_id) parameters = { "aId": int(author_id), } if (source_id is not None): query += ", EXISTS((a)-[:prior_{uid}]-(:Author ".format( uid=project_uid) query += "{ author_id: $source_id })) AS acquaintance" query += ", EXISTS((a)-[:test_{uid}]-(:Author ".format( uid=project_uid) query += "{ author_id: $source_id })) AS real_connected" parameters["source_id"] = int(source_id) result = { "author_id": None, "name": None, "similarity": None, "acquaintance": None, "real_connected": None } for row in db.run(query, parameters=parameters): result["author_id"] = int(row[0]) result["name"] = row[1] result["similarity"] = similarity if (source_id is not None): result["acquaintance"] = row[2] result["real_connected"] = row[3] if (result["name"] is None): return None result = Author( result["author_id"], result["name"], result["similarity"], result["acquaintance"], result["real_connected"], ) return result
def get_author(self, author): db = Data_base().library writer = str() for man in Author.objects(name__first=author.split()[0], name__second=author.split()[-1]): writer = { 'name': man.name, 'born': man.born, 'img': self.get_image(man.img), 'description': man.description } return writer
async def get_book_with_isbn(isbn: str): author_dict = {"name": "author1", "book": ["book1", "book2"]} author1 = Author(**author_dict) book_dict = { "isbn": "isbn1", "name": "book1", "author": author1, "year": 2016 } book1 = Book(**book_dict) return book1
def parse_entry(self, entry): return Entry( id=entry.find('id').text, title=entry.find('title').text, link=entry.find('link')['href'], updated=entry.find('updated').text, summary=entry.find('summary').text, content=entry.find('content').text.replace('\r', '').replace('\n', ''), author=Author(name=entry.find('author').find('name').text, uri=entry.find('author').find('uri').text, email=entry.find('author').find('email').text))
def _init_author(self, r): if self.author is not None: return author_info = r['ret_array'][0]['author'] author = Author( author_info['name'][0], author_info['basic_piclink'][0], author_info['basic_description'][0], author_info['basic_source_url'][0], ) self.author = author
async def get_book_with_isbn(isbn: str): result = await re.redis.get(isbn) if result: result_book = pickle.loads(result) return result_book else: book = await db_get_book_with_isbn(isbn) author = await db_get_author_name(book['author']) author_obj = Author(**author) book["author"] = author_obj result_book = Book(**book) await re.redis.set(isbn, pickle.dumps(result_book)) return result_book
def select_all(): # Create authors == empty list authors = [] # Create the sql query sql = 'SELECT * FROM authors' results = run_sql(sql) # Loop through the results for row in results: new_author = Author(row['first_name'], row['last_name'], row['id']) authors.append(new_author) return authors
def create_book(): book_list = book_repository.select_all() for book in book_list: if book.author.name == request.form["author"]: new_book = Book(request.form["title"], book.author) book_repository.save(new_book) return else: new_author = Author(request.form["author"]) author_repository.save(new_author) new_book = Book(request.form["title"], new_author) book_repository.save(new_book) return redirect("/books")
def add_authors(self, authors: List[str]) -> List[Author] or None: # List wymusza na nas typowanie result = [] for author_name in authors: try: first_name, last_name= author_name.split(' ') except ValueError: first_name, last_name = author_name, None author = Author().get_or_create( first_name = FirstName().get_or_create(name=first_name)[0], last_name = LastName().get_or_create(name=last_name)[0] if last_name else None )[0] result.append(author) return result
async def get_book_with_isbn(isbn: str,settings: Settings = Depends(get_settings)): result = await settings.redis.get(isbn) if result: result_book = pickle.loads(result) return result_book else: book = await db_get_book_with_isbn(isbn) author = await db_get_author(book["author"]) author_obj = Author(**author) book["author"] = author_obj result_book = Book(**book) await settings.redis.set(isbn, pickle.dumps(result_book)) return result_book
def main(): current_page = args.page_number try: print("Processing page {}...".format(current_page)) result = make_request(args, current_page) if 'error' in result: exit() res = result['response']['search']['offers']['entities'] # res = list(filter(lambda r: r['building'].get('buildingId'), res)) for e in convert(res): session.merge(Author(*e['author'])) if e['site']: session.merge(Site(*e['site'])) if e['building']: session.merge(Building(*e['building'])) nbid = None else: nb = session.merge(NewBuilding(*e['new_building'])) session.commit( ) # todo it's working now only for new buildings autoinc IDs nbid = nb.id o = (nbid, ) + e['offer'] session.merge(Offer(*o)) # session.merge(Photo(*e['photo'])) # for ent in res: # session.merge(Offer( # ent['offerId'], # ent['active'], # ent['area']['value'], # ent['building'].get('houseId') # )) session.commit() current_page += 1 print("Waiting {0} seconds".format(args.delay)) time.sleep(args.delay) except Exception as e: print(e) print("Unknown exception, waiting 60 seconds.") time.sleep(60) except KeyboardInterrupt: print("Finishing...") exit() print("Done")