def atualizar_imagem(cls): while True: path = input( f'Insira o caminho da sua IMAGEM de perfil. (ou Aperte ENTER para cancelar)' ) if not len(path): return else: try: Image.open(path) except: option = input( 'Não foi possível carregar a IMAGEM. Deseja utilizar a imagem padrão? [s/N]' ) if option.lower() == 's': img_blob = imagem_blob(State.imagem_usuario_padrao) DB.cursor.execute( "UPDATE tUser SET image=%s WHERE id_user=%s", (img_blob, cls.owner_user['id_user'])) DB.connection.commit() return else: img_blob = imagem_blob(path) DB.cursor.execute( "UPDATE tUser SET image=%s WHERE id_user=%s", (img_blob, cls.owner_user['id_user'])) DB.connection.commit() return
def new_group(cls, name, description, img_path, creator_user, visibility=1): if not os.path.isfile(img_path): img_path = 'groups/group0.jpg' img_blob = imagem_blob(img_path) id_wall = cls.new_wall() DB.cursor.execute( 'INSERT INTO tGroup (name, description, id_wall, visibility, image) VALUES (%s, %s, %s, %s, %s)', (name, description, id_wall, visibility, img_blob)) DB.connection.commit() # Retornar id do grupo criado DB.cursor.execute('SELECT id_group FROM tGroup') ids = DB.cursor.fetchall() id_grupo = ids[-1]['id_group'] id_creator = creator_user['id_user'] if type( creator_user) == dict else int(creator_user) DB.cursor.execute( 'INSERT INTO rUser_Group (id_user, id_group, status) VALUES (%s, %s, %s)', (id_creator, id_grupo, 2)) DB.connection.commit() return id_grupo
def new_post_group(id_user, id_group, text, image_path='no image'): DB.cursor.execute(f''' SELECT id_wall FROM tGroup WHERE id_group={id_group} ''') id_wall = DB.cursor.fetchone()['id_wall'] if not os.path.isfile(image_path): image_path = f'posts/post0.jpg' img_blob = imagem_blob(image_path) DB.cursor.execute( f''' INSERT INTO tPost(id_user, id_wall, text, image) VALUES (%s, %s, %s, %s) ''', (id_user, id_wall, text, img_blob)) DB.connection.commit()
def new_user(cls, name, city, img_path, visibility=3): if not os.path.isfile(img_path): img_path = 'users/user0.jpg' img_blob = imagem_blob(img_path) id_wall = cls.new_wall() DB.cursor.execute( 'INSERT INTO tUser (name, city, id_wall, visibility, image) VALUES (%s, %s, %s, %s, %s)', (name, city, id_wall, visibility, img_blob)) DB.connection.commit()
def new_group(name, description, visibility=1, image='null'): global id_wall global group_num filepath = f'{group_pic_path}group{group_num}.jpg' if not os.path.isfile(filepath): filepath = f'{group_pic_path}group0.jpg' img_blob = imagem_blob(filepath) new_wall() DB.cursor.execute( 'INSERT INTO tGroup (name, description, id_wall, visibility, image) VALUES (%s, %s, %s, %s, %s)', (name, description, id_wall, visibility, img_blob)) DB.connection.commit() id_wall += 1
def new_user(name, city, visibility=3, image='null'): global id_wall global user_num filepath = f'{user_pic_path}user{user_num}.jpg' if not os.path.isfile(filepath): filepath = f'{user_pic_path}user0.jpg' img_blob = imagem_blob(filepath) new_wall() DB.cursor.execute( 'INSERT INTO tUser (name, city, id_wall, visibility, image) VALUES (%s, %s, %s, %s, %s)', (name, city, id_wall, visibility, img_blob)) DB.connection.commit() id_wall += 1