def index(instance_id): start_at = request.query.start_at end_at = request.query.end_at try: db = Database('aws') Schedule.add(instance_id, start_at, end_at) response.set_header('Content-Type', 'application/vnd.api+json') return json.dumps({'res': 'success'}) except Exception as ex: abort(500, str(ex))
def save(update, context): """Return to top level conversation.""" ud = context.user_data schedule = {"time": ud[NEW_TIME][TIME], "duration": ud[NEW_TIME][DURATION]} Schedule.create(schedule) context.user_data[START_OVER] = True start(update, context) return END
def __updated(self): schedule.clear() schedules = Schedule.find_all() for sched in schedules: schedule.every().days.at(sched[1]).do(self.turn_on, sched[2]) logger.info("Schedules updated")
def index(instance_id): try: db = Database('aws') item = Schedule.remove(instance_id) response.set_header('Content-Type', 'application/vnd.api+json') return json.dumps({'res': 'success'}) except Exception as ex: abort(500, str(ex))
def get_schedule(): _schedules = [] schedules = Schedule.find_all() for schedule in schedules: _schedules.append({ ID: schedule[0], TIME: schedule[1], DURATION: schedule[2] }) return _schedules
def index(): db = Database('aws') response.set_header('Content-Type', 'application/vnd.api+json') data = [] for item in Schedule.select(): data.append({ 'id': item.instance_id, 'start at': str(item.start_at), 'stop at': str(item.stop_at) }) return json.dumps(data)
async def enter_schedule_day_of_week(msg: types.Message, state: FSMContext): async with state.proxy() as data: if msg.text not in week_days: return await msg.answer("Выберите день недели с клавиатуры!", reply_markup=week_days_kb) data["schedule_day_of_week"] = week_days.index(msg.text) schedule = Schedule(data["schedule_name"], data["schedule_group_id"], data["schedule_day_of_week"], bool(data["schedule_numerator"]), data["schedule_cabinet"], data["schedule_time"], data["schedule_start_date"], data["schedule_end_date"]) insert_schedule(schedule) await state.finish() await msg.answer("Ура! Расписание успешно добавлено!", reply_markup=admin_panel_kb)
def remove_schedule(update, context): msg_id = int(update.callback_query.data.split('_')[1]) Schedule.delete_one(msg_id) return show_remove_schedule(update, context)