def upload(): if request.method =="POST": file = request.files['file'] #if file and allowed_file(file.filename): if file and allowed_file(file.filename): filename = secure_filename(file.filename) print filename file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) file_path=os.path.join(app.config['UPLOAD_FOLDER'], filename) print file_path x= '../'+file_path print x #calculate the hash value of the pic hash_val = image.cal_hash_val(file_path) if not image.pic_exist(hash_val[2]): image.insert_image(hash_val[0],hash_val[1],hash_val[2],x) return render_template('upload.html',filename = x,phash = hash_val[2]) tag = request.form['tag_name'] print tag if tag : tag=tag.split(',') for item in tag: print item if not image.tag_exist(item,request.form['phash']): image.insert_tags(item,request.form['phash']) return render_template('upload.html',success=True) else: return render_template('upload.html')
def received_data(data): # Parse line and detect data # Position (.*)\>APECAN(.*?):\/([0-9]{6}h)(.{13})(.*?)\|(.*)\| # Image (.*)\>APECAN(.*?):\/([0-9]{6}h)(.{13})I(.*) # Log (.*)\>APECAN(.*?):\/([0-9]{6}h)(.{13})L(.*) all = re.search("(.*)\>APECAN(.*?):", data) pos = re.search("(.*)\>APECAN(.*?):\!(.{13})(.*?)\|(.*)\|", data) dat = re.search("(.*)\>APECAN(.*?):\{\{(I|L)(.*)", data) if pos or dat: # Debug if args.verbose: print('=' * 100) print(data.strip()) print('-' * 100) call = all.group(1).split(' ')[-1] rxer = all.group(2).split(',')[-1] if not len(rxer): rxer = args.call if pos: # Position packet (with comment and telementry) comm = pos.group(4) position.insert_position(sqlite, call, comm, 'pos') elif dat: # Data packet typ = dat.group(3) data = dat.group(4) if typ is 'I': # Image packet image.insert_image(sqlite, rxer, call, data) elif typ is 'L': # Log packet position.insert_position(sqlite, call, data, 'log')
def upload(): if request.method == "POST": file = request.files['file'] #if file and allowed_file(file.filename): if file and allowed_file(file.filename): filename = secure_filename(file.filename) print filename file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) print file_path x = '../' + file_path print x #calculate the hash value of the pic hash_val = image.cal_hash_val(file_path) if not image.pic_exist(hash_val[2]): image.insert_image(hash_val[0], hash_val[1], hash_val[2], x) return render_template('upload.html', filename=x, phash=hash_val[2]) tag = request.form['tag_name'] print tag if tag: tag = tag.split(',') for item in tag: print item if not image.tag_exist(item, request.form['phash']): image.insert_tags(item, request.form['phash']) return render_template('upload.html', success=True) else: return render_template('upload.html')
def upload_file(): if request.method == 'POST': username = request.cookies.get('username') myimage = request.files['file'] # if myimage and allowed_file(myimage.filename): # filename = secure_filename(myimage.filename) # myimage.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) # return redirect(url_for('uploaded_file', # filename=filename)) print 'received file with name:', myimage.filename data = myimage.read() image.insert_image(myimage.filename, username, data) return redirect('./')
def content(): if request.method == 'POST': file = request.files['file'] if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) file_path=os.path.join(app.config['UPLOAD_FOLDER'], filename) ##calculate the hash value of the pic hash_val = image.cal_hash_val(file_path) #insert into the database if not image.pic_exist(hash_val[2]): image.insert_image(hash_val[0],hash_val[1],hash_val[2],file_path) x = image.get_format(image.hamming(hash_val[0],hash_val[2])) print x return render_template('retrieval.html',filename=x) else: return render_template('retrieval.html')
def content(): if request.method == 'POST': file = request.files['file'] if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) ##calculate the hash value of the pic hash_val = image.cal_hash_val(file_path) #insert into the database if not image.pic_exist(hash_val[2]): image.insert_image(hash_val[0], hash_val[1], hash_val[2], file_path) x = image.get_format(image.hamming(hash_val[0], hash_val[2])) print x return render_template('retrieval.html', filename=x) else: return render_template('retrieval.html')
def received_data(data): data = data.strip() # Parse line and detect data callreg = "([A-Z]{2}[0-9][A-Z]{1,3}(?:-[0-9]{1,2})?)" # Callregex to filter bad igated packets all = re.search("^" + callreg + "\>APECAN(.*?):", data) pos = re.search("^" + callreg + "\>APECAN(.*?):[\=|!](.{13})(.*?)\|(.*)\|", data) dat = re.search("^" + callreg + "\>APECAN(.*?):\{\{(I|L)(.*)", data) dir = re.search("^" + callreg + "\>APECAN(.*?)::(.{9}):Directs=(.*)", data) if pos or dat or dir: # Debug if args.verbose: print('=' * 100) print(data) print('-' * 100) call = all.group(1).split(' ')[-1] rxer = all.group(2).split(',')[-1] if not len(rxer): rxer = args.call if pos: # Position packet (with comment and telementry) comm = pos.group(4) position.insert_position(db, call, comm, 'pos') elif dat: # Data packet (Image or Logging) typ = dat.group(3) data = dat.group(4) if typ is 'I': # Image packet image.insert_image(db, rxer, call, data) elif typ is 'L': # Log packet position.insert_position(db, call, data, 'log') elif dir: # Directs packet position.insert_directs(db, call, dir.group(4))
def received_data(data): # Parse line and detect data # Position (.*)\>APECAN(.*?):\/([0-9]{6}h)(.{13})(.*?)\|(.*)\| # Image (.*)\>APECAN(.*?):\/([0-9]{6}h)(.{13})I(.*) # Log (.*)\>APECAN(.*?):\/([0-9]{6}h)(.{13})L(.*) all = re.search("(.*)\>APECAN(.*?):\/([0-9]{6}h)(.{13})", data) pos = re.search("(.*)\>APECAN(.*?):\/([0-9]{6}h)(.{13})(.*?)\|(.*)\|", data) dat = re.search("(.*)\>APECAN(.*?):\/([0-9]{6}h)(.{13})(I|J|L)(.*)", data) if all: # Debug print('='*100) print(data) print('-'*100) call = all.group(1).split(' ')[-1] rxer = all.group(2).split(',')[-1] if not len(rxer): rxer = args.call tim = all.group(3) posi = all.group(4) if pos: # Position packet (with comment and telementry) comm = pos.group(5) tel = pos.group(6) position.insert_position(sqlite, call, tim, posi, comm, tel) elif dat: # Data packet typ = dat.group(5) data_b91 = dat.group(6) data = base91.decode(data_b91) # Decode Base91 if typ is 'I' or typ is 'J': # Image packet image.insert_image(sqlite, rxer, call, tim, posi, data, typ, args.server, args.grouping) elif typ is 'L': # Log packet position.insert_log(sqlite, call, data)