async def get_comment(message: types.Message, state: FSMContext): """ Part of file upload process. Downloads file, saves it in a tmp dir, uploads to gdrive and saves info to google spreadsheet """ try: async with state.proxy() as data: data["comment"] = message.text await message.reply("Сохраняю файл") row_id = gsheet.get_next_free_row_id() file_id = generate_id(row_id - 2) file_json = json.loads(data["file"]) logger.info( "User {user} for file with file_id: {file_id} added comment {comment}", user=get_user_name(message.from_user), file_id=file_json["file_id"], comment=message.text, ) with tempfile.TemporaryDirectory() as tmpdirname: tmp_file = Path(tmpdirname) / file_json["file_name"] await bot.download_file_by_id(file_json["file_id"], tmp_file) logger.info("Saved file {} to {}", file_json["file_id"], tmp_file) file = gdrive.upload_file(tmp_file, file_id) logger.info("Uploaded file {} to gdrive", file_json["file_id"]) data = GSheetRow( file_id=file_id, tool=data["tool"], protocol=data["protocol"], organism=data["organism"], experiment_date=str(data["date"]), date=str(message.date), user=get_user_name(message.from_user), file_link=file.link, comment=data["comment"], ) gsheet.add_row(data) logger.info("Saved data {} to gsheets", data) await message.reply("Файл сохранен!\n" + str(data), disable_web_page_preview=True) finally: await state.finish()
def test_id_10(): assert generate_id(10) == "000010"
def test_id_1(): assert generate_id(1) == "000001"
def test_id_999999(): assert generate_id(999999) == "999999"