Example #1
0
def week_forecast(weat_db, width):
    color_flag = True   # this will eventually get set in a config file
    #  color_flag = False   # this will eventually get set in a config file
    COLORS = utils.get_colors(color_flag=color_flag)
    #  width = utils.get_terminal_width()
    height = utils.get_terminal_height()
    #  there has to be a more elegant way to do the following:
    format_tups = temp_return_format()
    format_list = list(x[0] for x in format_tups['body'])
    labels = []
    #  labels = list(x[1] for x in format_tups['body'])
    for lab in format_tups['body']:
        if lab[2] == 1:
            labels.append(lab[1])
        elif lab[2] > 1:
            temp = []
            temp.append(lab[1])
            for i in range(lab[2] - 1):
                temp.append('')
            labels.extend(temp)
        else:
            raise ValueError("formatter returned negative value")
    box_width = get_box_width(width - utils.max_len(labels))
    #  box_height = get_box_height(format_list, height)
    box_height = get_box_height(format_tups['body'], height)
    formatted_days = format_day_list(weat_db, box_width,
                                     box_height, format_list,
                                     COLORS)
    formatted_header = format_header(None, utils.max_len(labels), box_width,
                                     COLORS)
    results = join_days(formatted_days, formatted_header, labels, width,
                        box_width, box_height, COLORS)
    return results
Example #2
0
def join_days(formatted_days, formatted_header, labels, width, box_width,
              box_height, COLORS):
    res = []
    label_width = utils.max_len(labels)
    total_width = label_width + (7 * box_width)
    #  assert width > total_width
    for lin in formatted_header:
        res.append("{:^{wid}}{}".format('', lin,
                                        wid=int(0.5 * (width - total_width))))
    while formatted_days:
        for index in range(box_height):
            temp = ''.join(d[index] for d in formatted_days[0:7])
            temp = "{:>{wid}}{}".format(labels[index], temp, wid=label_width)
            temp = "{:>{wid}}{}".format('', temp,
                                        wid=int(0.5 * (width - total_width)))
            res.append(temp)
        formatted_days = formatted_days[7:]
    return res