def image(name): hostnames = ["192.168.43.237", "192.168.43.238"] i = 0 images = [] for ip in hostnames: if ip != "192.168.43.238": print(ip) command = "send" dict = {'name': name, "command": "send", 'ip': "192.168.43.238"} reliable_send(ip, dict) conn, addr = server() data = reliable_recv(conn) data['image'] img = arr2img(data['image'], data['width'], data['height'], data['color'], data['image_name']) images.append(img) images.append(img) img.show() else: print("local!") image = Image_Base.query.filter_by(image_name=name).first() img = arr2img(image.image, image.width, image.height, image.color, image.image_name) images.append(img) images.append(img) img.show() i += 1 final_image = join_image(images, 1600, 1024) final_image.show() return render_template('next.html')
def upload(): upload = Upload() hostnames = ["192.168.43.237", "192.168.43.238"] if upload.validate_on_submit(): if upload.file.data: if upload.file.data.filename.split('.')[-1] != 'mp3': peer_images = crop_image(upload.file.data) i = 0 for ip in hostnames: if ip != "192.168.43.238": print(ip) image_data = peer_images[i] shape = image_data.shape command = "scjhhsacjbds" dict = { 'name': upload.name.data, "command": command, "image": image_data, "shape": shape } reliable_send(ip, dict) else: image_data = peer_images[i] shape = image_data.shape image = Image_Base(name=upload.name.data, username="******", image=image_data, w=shape[0], h=shape[1], c=shape[2]) db.session.add(image) db.session.commit() i += 1 return redirect(url_for('users.shower')) else: return "ERROR!" # else: # peer_audio = audio_split(upload.image.data) # for ip in hostnames: # if ip != socket.gethostname(): # image_data = img2arr(peer_images[i]) # shape = image_data.shape # client(ip,command,shape,image_data) # else: # image_data = img2arr(peer_images[:-1]) # shape = image_data.shape # image = Image_Base(name=upload.name.data,username="******",image=image_data.tostring(),w=shape[0],h=shape[1],c=shape[2]) # db.session.add(image) # db.session.commit() # return redirect(url_for('users.next')) return render_template('image_upload.html', form=upload)
def index(): conn, addr = server() data = reliable_recv(conn) # print(data['name']) if data['name'].split('.')[-1] != 'mp3': if data['command'] != "send": shape = data["shape"] image = Image_Base(username="******", name=data["name"], image=data["image"], w=shape[0], h=shape[1], c=shape[2]) db.session.add(image) db.session.commit() return redirect(url_for('users.uploaded')) else: image = Image_Base.query.filter_by(image_name=data['name']) dict = {"image": image} reliable_send(data['ip'], dict) return redirect(url_for('users.init')) else: if data['command'] != "send": rand = ''.join( [random.choice(string.ascii_letters) for i in range(32)]) filename = rand + '.mp3' filepath = os.path.join(current_app.root_path, 'static/music', filename) data['image'].export(filepath, format="mp3") audio = Audio_Base(username="******", name=data["name"], uname=filepath) db.session.add(audio) db.session.commit() return redirect(url_for('users.uploaded')) else: audio = Audio_Base.query.filter_by(uname=data['name']) sound = AudioSegment.from_mp3(audio.uname) dict = {"audio": sound} reliable_send(data['ip'], dict) return redirect(url_for('users.init')) return render_template('welcome.html')
def index(): conn, addr = server() data = reliable_recv(conn) print(data['name']) if len(data) > 0: if data['command'] != "send": shape = data["shape"] image = Image_Base(username="******", name=data["name"], image=data["image"], w=shape[0], h=shape[1], c=shape[2]) db.session.add(image) db.session.commit() return redirect(url_for('users.uploaded')) else: image = Image_Base.query.filter_by(image_name=data['name']) dict = {"image": image} reliable_send(data['ip'], dict) return redirect(url_for('users.init')) return render_template('index.html')
def image(name): hostnames = ["5000", "5001", "5002", "5003"] i = 0 images = [] width = 0 height = 0 for ip in hostnames: if ip != "5000": print(ip) command = "send" dict = {'name': name, "command": "send", 'ip': "192.168.43.114"} reliable_send(ip, dict) conn, addr = server() data = reliable_recv(conn) data['image'] img = arr2img(data['image'], data['width'], data['height'], data['color'], data['image_name']) width += data['width'] height = data['height'] images.append(img) img.show() else: image = Image_Base.query.filter_by(image_name=name).first() img = arr2img(image.image, image.width, image.height, image.color, image.image_name) width += image.width height = image.height images.append(img) img.show() width -= int(data['width']) * 2 height -= int(data['height']) * 2 i += 1 final_image = join_image(images, 1920, 1080) final_image.show() return render_template('next.html')
def image(name): hostnames = [ "192.168.43.238", "192.168.43.237", "192.168.43.114", "192.168.43.185" ] i = 0 images = [] width = 0 height = 0 for ip in hostnames: if ip != "192.168.43.238": print(ip) command = "send" dict = {'name': name, "command": "send", 'ip': "192.168.43.238"} reliable_send(ip, dict) conn, addr = server() data = reliable_recv(conn) data['image'] img = arr2img(data['image'], data['width'], data['height'], data['color'], data['image_name']) width += data['width'] height = data['height'] images.append(img) img.show() else: image = Image_Base.query.filter_by(image_name=name).first() img = arr2img(image.image, image.width, image.height, image.color, image.image_name) width += image.width height = image.height images.append(img) img.show() i += 1 final_image = join_image(images, 1920, 1080) final_image.show() return redirect(url_for('users.files'))
def upload(): upload = Upload() hostnames = ["5000"] if upload.validate_on_submit(): if upload.file.data: if upload.file.data.filename.split('.')[-1] != 'mp3': peer_images = crop_image(upload.file.data) i = 0 for ip in hostnames: if ip != "5000": print(ip) image_data = peer_images[i] shape = image_data.shape command = "scjhhsacjbds" dict = { 'name': upload.name.data, "command": command, "image": image_data, "shape": shape } reliable_send(ip, dict) else: image_data = peer_images[i] shape = image_data.shape image = Image_Base(name=upload.name.data, username="******", image=image_data, w=shape[0], h=shape[1], c=shape[2]) db.session.add(image) db.session.commit() i += 1 return redirect(url_for('users.shower')) else: peer_audio = split_audio(upload.file.data) i = 0 for ip in hostnames: if ip != "5000": #image_data = img2arr(peer_images[i]) command = "scjhhsacjbds" dict = { 'name': upload.name.data, "command": command, "image": peer_audio[i], "shape": shape } shape = (1, 2, 3) reliable_send(ip, dict) else: rand = ''.join([ random.choice(string.ascii_letters) for i in range(32) ]) filename = rand + '.mp3' filepath = os.path.join(current_app.root_path, 'static/music', filename) peer_audio[i].export(filepath, format="mp3") image = Audio_Base(username="******", name=upload.name.data, uname=filepath) db.session.add(image) db.session.commit() i += 1 return redirect(url_for('users.shower')) return render_template('image_upload.html', upload=upload)