def invite_user(data): if data['invited_user'] == data['username']: send({'msg': "Cannot invite yourself!"}) raise ApplicationError("Can't invite yourself", 404) else: check = False if not search_and_invite(data['username'], data['invited_user'], data['room']): send({'msg': "User does not exist!"}) raise ApplicationError("User doesn't exist", 404)
def find_by_name(name): result = None mapped_names = {} mapped_images = {} with SQLite() as db: result = db.execute("SELECT * FROM VAs WHERE name = ?", name) va = result.fetchone() if va is None: raise ApplicationError("No character found", 404) with SQLite() as db: characters = db.execute( "SELECT characters.name, characters.image FROM VAs JOIN characters ON VAs.name = characters.VA WHERE VAs.name = ?", name).fetchall() anime = db.execute( "SELECT anime.title, anime.image FROM VAs JOIN characters ON VAs.name = characters.VA JOIN anime ON anime.title = characters.anime WHERE VAs.name = ?", name).fetchall() f = 0 for i, j in zip(characters, anime): for i1, j1 in zip(i, j): if f == 1: mapped_images[i1] = j1 break mapped_names[i1] = j1 f = 1 filename = ''.join(name) path = "./images/" + filename + ".jpg" return VA(*va, mapped_names, mapped_images, path)
def update_choice(self, choice): result = None with SQLite() as db: result = db.execute("UPDATE user SET choice = ? WHERE id = ?", (choice, self.id)) if result.rowcount == 0: raise ApplicationError("No user present", 404)
def update_rating_by_name(rating, name): result = None with SQLite() as db: result = db.execute("UPDATE user SET rating = ? WHERE name = ?", (rating, name)) if result.rowcount == 0: raise ApplicationError("No user present", 404)
def find_by_title(title): result = None mapped_names = {} mapped_images = {} with SQLite() as db: result = db.execute("SELECT * FROM anime WHERE title = ?", title) anime = result.fetchone() if anime is None: raise ApplicationError("Anime not found", 404) with SQLite() as db: characters = db.execute( "SELECT characters.name, characters.image FROM anime JOIN characters ON anime.title = characters.anime WHERE title = ?", title).fetchall() # characters = db.execute("SELECT characters.name, characters.image FROM characters WHERE anime = ?", title).fetchall() VAs = db.execute( "SELECT VAs.name, VAs.image FROM anime JOIN characters ON anime.title = characters.anime JOIN VAs ON VAs.name = characters.VA WHERE title = ?", title).fetchall() f = 0 for i, j in zip(characters, VAs): for i1, j1 in zip(i, j): if f == 1: mapped_images[i1] = j1 break mapped_names[i1] = j1 f = 1 return Anime(*anime, mapped_names, mapped_images)
def delete(question_tag_id): result = None with SQLite() as db: result = db.execute("DELETE FROM question_tag WHERE id = ?", (question_tag_id, )) if result.rowcount == 0: raise ApplicationError("No value present", 404)
def create_user(user, password, email, address, phone_number): result = None with SQLite() as db: result = db.execute("INSERT INTO user (username, password, email, address, phone_number) VALUES (?, ?, ?, ?, ?)", (user, password, email, address, phone_number,)) if result.rowcount == 0: raise ApplicationError("No value present", 404)
def update_match(match, name): result = None with SQLite() as db: result = db.execute("UPDATE user SET match = ? WHERE name = ?", (match, name)) if result.rowcount == 0: raise ApplicationError("No user present", 404)
def update_rating(self, rating): result = None with SQLite() as db: result = db.execute("UPDATE user SET rating = ? WHERE id = ?", (rating, self.id)) if result.rowcount == 0: raise ApplicationError("No user present", 404)
def update_answer_by_content(answer, content): result = None with SQLite() as db: result = db.execute( "UPDATE question SET answer = ? WHERE content = ?", (answer, content)) if result.rowcount == 0: raise ApplicationError("No question present", 404)
def find_by_anime(anime): result = None with SQLite() as db: result = db.execute("SELECT * FROM characters WHERE anime = ?", anime) characters = result.fetchall() if characters is None: raise ApplicationError("No characters found", 404) return [Character(*row) for row in characters]
def find_by_name(name): result = None with SQLite() as db: result = db.execute("SELECT * FROM characters WHERE name = ?", name) character = result.fetchone() if character is None: raise ApplicationError("No character found", 404) return Character(*character)
def find_by_email(email): result = None with SQLite() as db: result = db.execute("SELECT * FROM user WHERE email = ?", (email, )) user = result.fetchone() if user is None: raise ApplicationError( "User with email {} not found".format(email), 404) return User(*user)
def find_by_studio(studio): result = None with SQLite() as db: result = db.execute("SELECT * FROM anime WHERE studio = ?", (studio, )) anime = result.fetchall() if anime is None: raise ApplicationError("Anime not found", 404) return anime
def find_by_id(id): result = None with SQLite() as db: result = db.execute( "SELECT user_id, title, description, price, date, isActive, buyer FROM ads WHERE id = ?", (id, )) ad = result.fetchone() if ad is None: raise ApplicationError("Ad with id {} not found".format(ad), 404) return Ad(*ad)
def find_by_username(username): result = None with SQLite() as db: result = db.execute( "SELECT id, email, password, username, address, phone_number FROM user WHERE username = ?", (username,)) user = result.fetchone() if user is None: raise ApplicationError( "Post with name {} not found".format(username), 404) return User(*user)
def find_by_name(name): result = None with SQLite() as db: result = db.execute( "SELECT is_private, name, id FROM rooms WHERE name = ?", (name,)) room = result.fetchone() if room is None: raise ApplicationError( "Room with name {} not found".format(name), 404) return Room(*room)
def find(question_id): result = None with SQLite() as db: result = db.execute( "SELECT content, answer, user, category, id FROM question WHERE id = ?", (question_id, )) question = result.fetchone() if question is None: raise ApplicationError( "Question with id {} not found".format(question_id), 404) return Question(*question)
def find(user_id): result = None with SQLite() as db: result = db.execute( "SELECT email, password, name, adress, mobile_number, id FROM user WHERE id = ?", (user_id, )) user = result.fetchone() if user is None: raise ApplicationError("User with id {} not found".format(user_id), 404) return User(*user)
def find_by_room(room_name): result = None with SQLite() as db: result = db.execute( "SELECT room_name, username, id FROM invites WHERE room_name = ?", (room_name, )) invite = result.fetchone() if invite is None: raise ApplicationError( "Invite for room {} not found".format(room_name), 404) return Invite(*invite)
def find_by_name(name): result = None with SQLite() as db: result = db.execute( "SELECT name, password, room, description, picture_location, id FROM user WHERE name = ?", (name, )) user = result.fetchone() if user is None: raise ApplicationError("User with name {} not found".format(name), 404) return User(*user)
def find(post_id): result = None with SQLite() as db: result = db.execute( "SELECT title, content, id FROM post WHERE id = ?", (post_id, )) post = result.fetchone() if post is None: raise ApplicationError("Post with id {} not found".format(post_id), 404) return Post(*post)
def find_by_email(email): result = None with SQLite() as db: result = db.execute( "SELECT username, password, email, address, phone_number, user_id FROM user WHERE email = ?", (email,)) user = result.fetchone() if user is None: raise ApplicationError( "User with name {} not found".format(username), 404) return User(*user)
def find(question_tag_id): result = None with SQLite() as db: result = db.execute( "SELECT question_id, tag_id, id FROM question_tag WHERE id = ?", (question_tag_id, )) tag = result.fetchone() if tag is None: raise ApplicationError( "Tag with id {} not found".format(question_tag_id), 404) return Question_tag(*tag)
def find(ad_id): result = None with SQLite() as db: result = db.execute( "SELECT title, content, price, release_date, is_active, buyer_id, creator_id, id FROM ad WHERE id = ?", (ad_id, )) ad = result.fetchone() if ad is None: raise ApplicationError("Ad with id {} not found".format(ad_id), 404) return Ad(*ad)
def find_by_id(id): result = None with SQLite() as db: result = db.execute( "SELECT id, email, username, password, adress or phone FROM user WHERE id = ?", (id,)) user = result.fetchone() if user is None: raise ApplicationError( "Post with name {} not found".format(username), 404) return User(*user)
def find(user_id): result = None with SQLite() as db: result = db.execute( "SELECT username, password, id FROM user WHERE id = ?", (user_id,)) user = result.fetchone() if user is None: raise ApplicationError( "Post with id {} not found".format(user_id), 404) return User(*user)
def find_by_id(ad_id): result = None with SQLite() as db: result = db.execute( "SELECT creator_id, title, desc, price, date, buyer, is_available, ad_id FROM ad WHERE ad_id = ?", (ad_id, )) ad = result.fetchone() if ad is None: raise ApplicationError("Ad with id {} not found".format(ad_id), 404) return Ad(*ad)
def find_all_purchased(creator_id): result = None with SQLite() as db: result = db.execute( "SELECT ad_id, title, desc, price, date, buyer FROM ad WHERE (creator_id = ? AND is_available = ?)", (creator_id, 0)) ad = result.fetchall() if ad is None: raise ApplicationError( "User with id {} has no ads".format(creator_id), 404) return ad
def edit(user_id, part_to_edit, value): if part_to_edit=="email" or part_to_edit=="password": raise ApplicationError("You can't change your email or password",404) elif part_to_edit=="username": with SQLite() as db: result = db.execute( "UPDATE user SET username = ? WHERE id = ?;", (value, user_id,)) elif part_to_edit=="address": with SQLite() as db: result = db.execute( "UPDATE user SET address = ? WHERE id = ?;", (value, user_id,)) elif part_to_edit=="phone_number": with SQLite() as db: result = db.execute( "UPDATE user SET phone_number = ? WHERE id = ?;", (value, user_id,)) else: raise ApplicationError("{} doesnt exist".format(part_to_edit),404)