def audio_message(update, context): from app import create_app app = create_app(config_class=Config) app.app_context().push() audio = update.message.voice.get_file() audio = audio.download_as_bytearray() rand = str(random.randint(100000,1000000)) filename = rand+"note.ogg" with open(os.path.join(Config.UPLOAD_FOLDER, filename), 'wb') as f: f.write(audio) subprocess.run(['ffmpeg', '-i', os.path.join(Config.UPLOAD_FOLDER, filename), os.path.join(Config.UPLOAD_FOLDER, filename.replace('ogg', 'wav'))]) with sr.AudioFile(os.path.join(Config.UPLOAD_FOLDER, filename.replace('ogg', 'wav'))) as s: r = sr.Recognizer() txt = r.listen(s) text = r.recognize_google(txt, language = 'ru-RU') note = Note() note.text = text note.sound_file = filename note.creator = User.query.filter_by(tg_id=update.message.chat_id).first().id db.session.add(note) db.session.commit() bot.send_message( chat_id=update.message.chat_id, text=f"Заметка сохранена" )
def save_day(): req = request.get_json() title = req.get('title') data = req.get('data', '') if not title: abort(400) username = get_jwt_identity() if not username: abort(401) user = User.query.filter_by(username=username.lower()).first() if not user: abort(400) enc_date = aes_encrypt(title) note = user.notes.filter_by(title=enc_date).first() if not Note: # Check old encryption enc_date = aes_encrypt_old(title) note = user.notes.filter_by(title=enc_date).first() if not note: note = Note(user_id=user.uuid, name=title, text=data, is_date=True) else: note.text = data db.session.add(note) db.session.flush() db.session.commit() return jsonify(note=note.serialize), 200
def ticket_detail(ticket_id): ticket = Ticket.query.filter_by(id=ticket_id).first_or_404() if g.user.admin or g.user.id == ticket.user.id: form = forms.TicketUpdateForm() if form.validate_on_submit(): ticket.status = form.status.data ticket.priority = int(form.priority.data) if form.text.data != '': note = Note() note.text = form.text.data ticket.conversation.append(note) flash('New Content posted to ticket %s' % ticket.id, 'success') db.session.merge(ticket) db.session.commit() flash('Ticket Status Updated', 'success') else: form.status.data = ticket.status form.priority.data = str(ticket.priority) for error in form.errors: flash('%s: %s' % (error, form.errors[error]), 'danger') return render_template('ticket_detail.html', ticket=ticket, form=form, title='Ticket: %s' % ticket.id)
def index(): title = 'Главная' # Я поставил orders_iam_creator = current_user.get_orders_iam_creator() # Мне поставили orders_iam_executor = current_user.get_orders_iam_executor() create_order_form = CreateOrder() for order_type in OrderTypes.query.all(): create_order_form.type.choices.append( (str(order_type.id), order_type.title)) create_order_form.executors.choices.append(('0', 'не выбрано')) for tag in Tag.query.all(): create_order_form.executors.choices.append((str(tag.id), tag.name)) create_note_form = CreateNote() if create_order_form.validate_on_submit(): all_fields = request.form custom_fields = {} personal_executors = [] for field in all_fields: if 'field' in field.split('-'): custom_fields[field.split('-')[0]] = all_fields[field] if 'executor' in field.split('-'): personal_executors.append(User.query.get(field.split('-')[-1])) order = Order() order.creator = current_user.id order.base_order = create_order_form.baseorder.data order.title = create_order_form.title.data order.description = create_order_form.description.data order.description_sound = create_order_form.file.data order.priority = create_order_form.priority.data order.type = create_order_form.type.data order.interval = create_order_form.interval.data order.deadline = create_order_form.deadline.data for field in all_fields: if 'file_id' in field: order.description_sound = f'{all_fields["file_id"]}sound.ogg' # print(os.path.join(Config.UPLOAD_FOLDER, f'{all_fields["file_id"]}sound.wav')) order.status = 1 if create_order_form.executors.data != '0': tag = Tag.query.filter( Tag.id == create_order_form.executors.data).first() for user in tag.users: order.executors.append(user) if personal_executors: for user in personal_executors: order.executors.append(user) order.reactions = json.dumps(custom_fields) db.session.add(order) db.session.commit() return redirect(request.referrer) if create_note_form.validate_on_submit(): note = Note() note.creator = current_user.id note.text = create_note_form.text.data all_fields = request.form for field in all_fields: if 'file_id' in field: note.sound_file = os.path.join( Config.UPLOAD_FOLDER, f'{all_fields["file_id"]}sound.wav') db.session.add(note) db.session.commit() return redirect(request.referrer) return render_template('main/index.html', title=title, create_order_form=create_order_form, create_note_form=create_note_form, orders_iam_creator=orders_iam_creator, orders_iam_executor=orders_iam_executor, custom_inputs=CustomInputs.query.all(), list=list, reversed=reversed)