def _habit_status(self): habits = Habit.All(self.user) today = self.user.local_time().date() habitday_keys = [ ndb.Key('HabitDay', HabitDay.ID(h, today), parent=self.user.key) for h in habits ] habitdays = ndb.get_multi(habitday_keys) n_habits_done = 0 habits_committed_undone = [] habits_done = [] for hd in habitdays: if hd: habit = hd.habit.get() if hd.committed and not hd.done: if habit: habits_committed_undone.append(habit.name) if hd.done: habits_done.append(habit.name) n_habits_done += 1 if habits: if n_habits_done: text = "Good work on doing %d %s (%s)!" % ( n_habits_done, tools.pluralize('habit', n_habits_done), tools.english_list(habits_done)) else: text = "No habits done yet." if habits_committed_undone: text += " Don't forget you've committed to %s." % tools.english_list( habits_committed_undone) else: text = "You haven't added any habits yet. Try saying 'add habit run'" return text
def testEnglishList(self): volley = [(["one", "two", "three"], "'one', 'two' and 'three'"), (["cat", "dog"], "'cat' and 'dog'"), ([], "--")] for v in volley: arr, expected = v res = tools.english_list(arr, quote="'") self.assertEqual(res, expected)
def testEnglishList(self): volley = [ (["one", "two", "three"], "'one', 'two' and 'three'"), (["cat", "dog"], "'cat' and 'dog'"), ([], "--") ] for v in volley: arr, expected = v res = tools.english_list(arr, quote="'") self.assertEqual(res, expected)
def salmon_weapons_get(request): current_salmon_stages = splatoon.get_salmon_schedule() current = splatoon.SalmonScheduleItem(current_salmon_stages['details'][0]) weapon_string = tools.english_list(map(str, current.weapons)) time_string = None if datetime.datetime.now() < current.end: time_string = current.end.strftime('until %B %-d at %-I:%M%p') else: time_string = current.end.strftime('starting on %B %-d at %-I:%M%p') result = f'You can use the {weapon_string}, {time_string}.' return responses.GoogleAssistantResponse(result)
def _tasks_request(self): tasks = Task.Recent(self.user) tasks_undone = [] n_done = Task.CountCompletedSince(self.user, datetime.combine(datetime.today(), time(0,0))) for task in tasks: if not task.is_done(): tasks_undone.append(task.title) if n_done: text = "You've completed %d %s for today." % (n_done, tools.pluralize('task', n_done)) else: text = "You haven't completed any tasks yet." if tasks_undone: text += " You still need to do %s." % tools.english_list(tasks_undone) if not n_done and not tasks_undone: text += " Try adding tasks by saying 'add task Q2 planning'" return text
def __str__(self): time_range = self.time_range() weapon_string = tools.english_list(map(str, self.weapons)) return f'Salmon Run on {self.stage} with the {weapon_string} at {time_range}'