当前位置: 首页>>代码示例>>Python>>正文


Python Loader.load_meals方法代码示例

本文整理汇总了Python中loader.Loader.load_meals方法的典型用法代码示例。如果您正苦于以下问题:Python Loader.load_meals方法的具体用法?Python Loader.load_meals怎么用?Python Loader.load_meals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在loader.Loader的用法示例。


在下文中一共展示了Loader.load_meals方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from loader import Loader [as 别名]
# 或者: from loader.Loader import load_meals [as 别名]
class App:

    """The main application class takes user input and manages the applicatino
    loop.
    """

    def __init__(self):
        os.system('clear')
        print('Initializing...')
        self.loader          = Loader()
        self.available_meals = self.loader.load_meals()
        self.active          = True
        print('Initialization complete')

        self.days = [
            'Monday',
            'Tuesday',
            'Wednesday',
            'Thursday',
            'Friday',
            'Saturday',
            'Sunday',
        ]

    def start(self):
        while self.active:
            self.loop()

    def loop(self):
        print('\nWhat would you like to do?')
        print('1) Load this week\'s meals')
        print('2) Generate new meals')
        print('3) Hold specific meals')
        print('4) Save current meals')
        if hasattr(self, 'meals'):
            print('5) Email shopping list for current meals')

        choice = input().replace(' ', '')

        if not choice.isnumeric():
            os.system('clear')
            print('please enter a number between 1 and 4')
            return
        else:
            choice = int(choice)

        if choice == 1:
            # @TODO: load saved meals
            os.system('clear')
            print('loading current meals...')
            self.meals = []
            self.print_meals()
        elif choice == 2:
            os.system('clear')
            print('generating meals...\n')
            self.meals = self.get_random_meals([])
            self.print_meals()
        elif choice == 3:
            print('make selections:')
            choices = self.get_choices()
            self.meals = self.get_random_meals(choices)
            os.system('clear')
            print('generating meals...\n')
            self.print_meals()
        elif choice == 4:
            os.system('clear')
            print('saving meals...')
            # @TODO: save meals
        elif choice == 5:
            os.system('clear')
            print('emailing shopping list...')
            emailer = Emailer(self.meals)
            emailer.send_list()

    def print_meals(self):
        for i, meal in enumerate(self.meals):
            day_spaces  = self.max_day_len() - len(self.days[i])
            meal_spaces = self.max_meal_len() - len(meal.name)

            output = ''
            output = output + self.days[i] + ': ' + (' ' * day_spaces)
            output = output + meal.name + ' ' + ('.' * (meal_spaces + 2))
            output = output + ' (' + str(i + 1) + ')'
            print(output)

    def max_day_len(self):
        return max([len(day) for day in self.days])

    def max_meal_len(self):
        return max([len(meal.name) for meal in self.meals])

    def get_random_meals(self, choices):
        meals = []

        # Make sure the choices are in order.
        choices = list(set(choices))
        choices.sort()

        # Get list of available meals.
        available_meals = list(self.available_meals)
#.........这里部分代码省略.........
开发者ID:Kimbsy,项目名称:feed-me,代码行数:103,代码来源:app.py


注:本文中的loader.Loader.load_meals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。