Beispiel #1
0
def print_all(food_menu):
    '''
    Print everything from every selected restaurant from every day
    '''
    week_dates = [date.strftime('%d.%m') for date in get_current_weekdates()]

    for corp, restaurant in sorted(food_menu.items()):
        for name, week_menu in sorted(restaurant.items()):
            print(ansify('%s (%s)' % (name.capitalize(), corp.capitalize()), 'green'))

            if not week_menu:
                print(ansify(' Nothing for the whole week!', 'magenta'))

                if config.LANG.lower() == 'en':
                    print("  Maybe %s is being lazy with their english menu again?" % corp.capitalize())
                    # This shit happens way too often

            for day, day_menu in sorted(week_menu.items()):
                day = int(day)
                if not day_menu:
                    print(ansify(' Nothing found for %s (%s)' % (WEEK[day], week_dates[day]), 'magenta'))

                else:
                    if datetime.weekday(datetime.now()) == day:
                        print(ansify(' %s (%s)' % (WEEK[day], 'today'), 'red'))
                    else:
                        print(ansify(' %s (%s)' % (WEEK[day], week_dates[day]), 'magenta'))

                    for food in day_menu:
                        print("  %s" % format_food(food))

            print()  # Newline after every restaurant!
Beispiel #2
0
def get_sodexo_json():
    '''
    Form the proper URLs from SODEXO_DEFAULTS and return all wanted JSON data
    '''
    sodexo_base = 'http://www.sodexo.fi/ruokalistat/output/daily_json/'

    week_dates = get_current_weekdates()
    sodexo_data = dict()

    try:
        for restaurant in config.SODEXO_DEFAULTS:
            verbose_print('Fetching Sodexo: %s...' % restaurant)

            sodexo_data[restaurant] = list()
            for date in week_dates:
                sodexo_url = '%s%s/%s/%s/%s/fi' % (
                    sodexo_base, config.SODEXO_ALL[restaurant], date.year,
                    date.month, date.day)
                sodexo_data[restaurant].append(
                    str(web.urlopen(sodexo_url).read().decode('utf8')))
    except KeyError:
        print('ERROR: Invalid Sodexo restaurant specified.')
        print('Use -r flag to find out all the restaurants')
        sys.exit(1)

    return sodexo_data
Beispiel #3
0
def get_sodexo_json():
    '''
    Form the proper URLs from SODEXO_DEFAULTS and return all wanted JSON data
    '''
    sodexo_base = 'http://www.sodexo.fi/ruokalistat/output/daily_json/'

    week_dates = get_current_weekdates()
    sodexo_data = dict()

    try:
        for restaurant in config.SODEXO_DEFAULTS:
            verbose_print('Fetching Sodexo: %s...' % restaurant)

            sodexo_data[restaurant] = list()
            for date in week_dates:
                sodexo_url = '%s%s/%s/%s/%s/fi' % (
                    sodexo_base, config.SODEXO_ALL[restaurant],
                    date.year, date.month, date.day
                )
                sodexo_data[restaurant].append(str(web.urlopen(sodexo_url).read().decode('utf8')))
    except KeyError:
        print('ERROR: Invalid Sodexo restaurant specified.')
        print('Use -r flag to find out all the restaurants')
        sys.exit(1)

    return sodexo_data
Beispiel #4
0
def is_cache_uptodate():
    '''
    Check if cache exists and compare CACHE_FILE modify date to current weekdates
    '''
    try:
        mtime = os.path.getmtime(config.CACHE_FILE)

    except FileNotFoundError:
        verbose_print('No cache found!')
        return False

    mdate = datetime.fromtimestamp(mtime)
    for week_date in get_current_weekdates():
        if mdate.day == week_date.day:
            verbose_print('Cache is from this week')
            return True

    verbose_print('Cache is not up to date')
    return False
Beispiel #5
0
def is_cache_uptodate():
    '''
    Check if cache exists and compare CACHE_FILE modify date to current weekdates
    '''
    try:
        mtime = os.path.getmtime(config.CACHE_FILE)

    except FileNotFoundError:
        verbose_print('No cache found!')
        return False

    mdate = datetime.fromtimestamp(mtime)
    for week_date in get_current_weekdates():
        if mdate.day == week_date.day:
            verbose_print('Cache is from this week')
            return True

    verbose_print('Cache is not up to date')
    return False