def low_temp(day, curr_day, box_width): temp = utils.eat_keys(day, ('low', 'fahrenheit')) base = utils.eat_keys(curr_day, ('low', 'fahrenheit')) return "{}{:^{wid}}{}".format(cf.bar_temp_color(temp, base, COLOR), "{} {}".format(temp, "F"), COLOR.clear, wid=box_width)
def precip(day, curr_day, box_width): qpf = utils.eat_keys(day, ('qpf_allday', 'in')) snow = utils.eat_keys(day, ('snow_allday', 'in')) return "{}{:^{wid}}{}".format(cf.inch_precip_color((qpf + snow), None, COLOR), "{:.3} {}".format(qpf+snow, "in"), COLOR.clear, wid=box_width)
def date(day, _, box_width): temp = dt.datetime.fromtimestamp(int(utils.eat_keys(day, ('date', 'epoch')))) working = temp.strftime('%B %e') if len(working) * 1.5 > box_width: working = temp.strftime('%b %e') return "{:^{wid}}".format(working[:box_width], wid=box_width)
def weekday(day, _, box_width): temp = dt.datetime.fromtimestamp(int(utils.eat_keys(day, ('date', 'epoch')))) working = temp.weekday() if len(working) > box_width: working = working[:3] return "{:^{wid}}".format(working[:box_width], wid=box_width)
def wind_speed_dir(day, curr_day, box_width): speed = utils.eat_keys(day, ('maxwind', 'mph')) direction = utils.eat_keys(day, ('maxwind', 'dir')) curr_speed = utils.eat_keys(curr_day, ('maxwind', 'mph')) if direction is not None: return "{}{:^{wid}}{}".format(cf.bar_temp_color(speed, curr_speed, COLOR), "{} {}".format(speed, direction), COLOR.clear, wid=box_width) else: return "{}{:^{wid}}{}".format(cf.bar_temp_color(speed, curr_speed, COLOR), speed, COLOR.clear, wid=box_width)
def time_format_generator(hourly_wdb, header, head_width, col_width, color_func=lambda x: "", CLEAR="", *args): """ generates a sequence of formated times from a list of times """ ind = -1 import utils.utilities as utils while ind < len(hourly_wdb): if ind < 0: temp = "{:>{wid}}: ".format(header, wid=head_width) else: hr = utils.eat_keys(hourly_wdb[ind], ('FCTTIME', 'hour')) mn = utils.eat_keys(hourly_wdb[ind], ('FCTTIME', 'min')) _tim = "{:>{wid}}".format("{}:{}".format(hr, mn), wid=col_width) temp = "" for zind in range(col_width): temp_mins = int(60 * (zind / col_width)) # temp_color = color_func((hr, temp_mins), *args) temp_color = color_func((hr, temp_mins), *args) temp = "{}{}{}{}".format(temp, temp_color, _tim[zind], CLEAR) yield temp ind += 1
def format_day_list(lis, box_width, box_height, format_list, COLOR): """ takes a list of formatted lines, arranges them according to weekday """ import datetime working = [] # here we'll have: assert isinstance(lis, list) assert isinstance(lis[0], dict) format_func = make_formatter(format_list, COLOR) start = int(datetime.datetime.fromtimestamp( int(utils.eat_keys(lis[0], ('date', 'epoch')))).weekday()) if start > 0: tmp = [] for j in range(box_height): tmp.append(' ' * box_width) for i in range(start): working.append(tmp) for day in lis: working.append(format_single_day(day, lis[0], format_func, box_width)) return working
def conditions(day, curr_day, box_width): conds = utils.eat_keys(day, ('conditions',)) if len(conds) < box_width: first = "{}{:^{wid}}{}".format(COLOR.cond, conds, COLOR.clear, wid=box_width) second = ' ' * box_width # return [first, second] else: tmp = conds.split(' ') first, second = '', '' while len(first) + len(tmp[0]) < box_width: first = first + ' ' + tmp[0] tmp = tmp[1:] first = "{}{:^{wid}}{}".format(COLOR.cond, first.lstrip(), COLOR.clear, wid=box_width) second = "{}{:^{wid}}{}".format(COLOR.cond, ' '.join(tmp)[:box_width], COLOR.clear, wid=box_width) return [first, second]
def new_sunrise_line(hourly_wdb, sun_wdb, COLORS, col_width, head): # kill the following... import utils.utilities as utils import printers.colorfuncs as cf _hour_lis = list(utils.eat_keys(hour, ('FCTTIME', 'hour')) for hour in hourly_wdb) temp = "{:>{wid}}: ".format("Sunrise/set", wid=head) sunrise_hour = sun_wdb['sunrise']['hour'] sunrise_min = sun_wdb['sunrise']['minute'] if sunrise_hour in _hour_lis: sunrise_index = ((_hour_lis.index(sunrise_hour) * col_width) + int(sunrise_min) // 10) else: sunrise_index = -1 sunset_hour = sun_wdb['sunset']['hour'] sunset_min = sun_wdb['sunset']['minute'] if sunset_hour in _hour_lis: sunset_index = ((_hour_lis.index(sunset_hour) * col_width) + int(sunset_min) // 10) else: sunset_index = -1 sunrise_str = "{}:{}".format(sunrise_hour, sunrise_min) sunset_str = "{}:{}".format(sunset_hour, sunset_min) index = 0 tar_length = col_width * len(hourly_wdb) # color_func = cf.sunrise_sunset_color color_func = cf.new_sunrise_sunset_color while index < tar_length: curr_hour = _hour_lis[index // col_width] curr_min = (index % col_width) * 10 if index == sunrise_index: temp = "{}{}{}".format(temp, color_func((curr_hour, curr_min), (sunrise_hour, sunrise_min), (sunset_hour, sunset_min), COLORS), sunrise_str[0]) sunrise_str = sunrise_str[1:] index += 1 if len(sunrise_str) > 0: sunrise_index += 1 elif index == sunset_index: temp = "{}{}{}".format(temp, color_func((curr_hour, curr_min), (sunrise_hour, sunrise_min), (sunset_hour, sunset_min), COLORS), sunset_str[0]) sunset_str = sunset_str[1:] index += 1 if len(sunset_str) > 0: sunset_index += 1 else: temp = "{}{}{}".format(temp, color_func((curr_hour, curr_min), (sunrise_hour, sunrise_min), (sunset_hour, sunset_min), COLORS), " ") index += 1 temp += COLORS.clear return temp