def get_schedule_list(self): start_index = 0 stop_index = self.redisClient.llen(self.list_key) schedule_list = self.redisClient.lrange(self.list_key, start_index, stop_index) model_list = [TextSchedule.from_json(json.loads(schedule_json)) for schedule_json in schedule_list] return model_list
def send_next_chunks_for_all_schedules(self): number_of_schedules = self.redisClient.llen(self.list_key) for i in range(number_of_schedules): schedule_json = self.redisClient.lindex(self.list_key, i) schedule = TextSchedule.from_json(json.loads(schedule_json)) self.send_next_chunk_for_schedule(schedule) updated_json = schedule.to_json() self.redisClient.lset(self.list_key, i, updated_json)
def cleanup_finished_schedules(self): number_of_schedules = self.redisClient.llen(self.list_key) schedule_list = self.redisClient.lrange(self.list_key, 0, number_of_schedules) finished_items = [] for schedule_json in schedule_list: schedule = TextSchedule.from_json(json.loads(schedule_json)) if schedule.is_finished(): finished_items.append(schedule_json) for finished in finished_items: self.redisClient.lrem(self.list_key, 0, finished)
def post_new_book_schedule(): """ Post to this endpoint to add a new reader. Post data should be json with the following mandatory keys: 'email': the email address to send daily reading chunks to 'gutenberg_id': The ID for a given Project Gutenberg text Post data *can* include the following optional keys: 'days_to_read': Number of days the reader would like to read text in; defualts to 30 """ data = request.body.readline() if not data: abort(400, 'No data received') schedule_json = json.loads(data) validate_schedule_json(schedule_json) text_schedule = TextSchedule.from_json(schedule_json) handle_new_schedule(text_schedule) return u''