예제 #1
0
def create_days(start_date, end_date, weight, body_fat):
    """Create day objects from measurements."""

    import day

    current_date = start_date
    step = datetime.timedelta(days=1)

    date_range = []

    # create a list of dates within the range
    while current_date >= end_date:
        date_range.append(current_date)
        current_date -= step

    days = []

    # loop over each day in the range
    for date in date_range:
        # retrieve the values for the current day object
        current_date = date
        current_weight = weight.get(current_date, None)
        current_body_fat = body_fat.get(current_date, None)

        # create the day object
        current_day = day.Day(current_date, current_weight, current_body_fat)

        # add the current day to the list of days
        days.append(current_day)

    return days
예제 #2
0
파일: FtreeAux.py 프로젝트: BIGtigr/xgcode
def equal_daylight_layout(T, B, iteration_count):
    """
    @param T: topology
    @param B: branch lengths
    """
    R = Ftree.T_to_R_canonical(T)
    r = Ftree.R_to_root(R)
    # create the initial equal arc layout
    v_to_location = equal_arc_layout(T, B)
    # use sax-like events to create a parallel tree in the C extension
    v_to_sinks = Ftree.R_to_v_to_sinks(R)
    v_to_dtree_id = {}
    dtree = day.Day()
    count = _build_dtree(
            dtree, r, v_to_sinks, v_to_location, v_to_dtree_id, 0)
    # repeatedly reroot and equalize
    v_to_neighbors = Ftree.T_to_v_to_neighbors(T)
    for i in range(iteration_count):
        for v in Ftree.T_to_inside_out(T):
            neighbor_count = len(v_to_neighbors[v])
            if neighbor_count > 2:
                dtree.select_node(v_to_dtree_id[v])
                dtree.reroot()
                dtree.equalize()
    # extract the x and y coordinates from the dtree
    v_to_location = {}
    for v, dtree_id in v_to_dtree_id.items():
        dtree.select_node(dtree_id)
        x = dtree.get_x()
        y = dtree.get_y()
        v_to_location[v] = (x, y)
    return v_to_location
예제 #3
0
 def do_layout(self, tree):
     """
     Interleave the processes of breaking the tree and daylight equalization.
     @param tree: something like a SpatialTree
     """
     # reroot to a node with more than two neighbors
     if get_neighbor_count(tree.root) < 3:
         suitable_roots = [
             x for x in tree.preorder() if get_neighbor_count(x) > 2
         ]
         if suitable_roots:
             tree.reroot(suitable_roots[0])
     # create the initial layout
     EqualArcLayout.do_layout(tree)
     # determine the maximum allowed branch length
     total_branch_length = tree.get_total_length()
     max_branch_length = total_branch_length / float(self.min_segment_count)
     # any branch longer than the max branch length will be broken in half
     iteration = 0
     while True:
         print 'progressive iteration', iteration + 1
         # write the extension tree
         dtree = day.Day()
         _build_dtree(dtree, tree.root, 0)
         # equalize the layout
         for node in tree.breadth_first():
             if get_neighbor_count(node) > 1:
                 dtree.select_node(node.dtree_id)
                 dtree.reroot()
                 try:
                     dtree.equalize()
                 except RuntimeError as e:
                     raise LayoutError(e)
         # read the extension tree
         for node in tree.preorder():
             dtree.select_node(node.dtree_id)
             x = dtree.get_x()
             y = dtree.get_y()
             node.location = (x, y)
         # break the branches
         old_nodes = list(tree.preorder())
         for node in old_nodes:
             if node is tree.root:
                 if node.blen is not None:
                     raise HandlingError(
                         'the root node should not have a branch length')
             elif node.blen is None:
                 raise HandlingError(
                     'each non-root node should have a branch length')
             elif node.blen > max_branch_length:
                 # create a new node and set its attributes
                 new = self.node_factory()
                 new.name = node.name
                 # insert the new node
                 tree.insert_node(new, node.parent, node, .5)
         # if no node was added then break out of the loop
         if len(old_nodes) == len(list(tree.preorder())):
             break
         else:
             iteration += 1
예제 #4
0
 def do_layout(self, tree):
     """
     @param tree: something like a SpatialTree
     """
     # create the initial layout
     EqualArcLayout.do_layout(tree)
     # use sax-like events to create a parallel tree in the C extension
     dtree = day.Day()
     count = _build_dtree(dtree, tree.root, 0)
     # repeatedly reroot and equalize
     for iteration in range(self.iteration_count):
         for node in tree.breadth_first():
             neighbor_count = len(node.children)
             if node.parent:
                 neighbor_count += 1
             if neighbor_count > 2:
                 dtree.select_node(node.dtree_id)
                 dtree.reroot()
                 try:
                     dtree.equalize()
                 except RuntimeError as e:
                     raise LayoutError(e)
     # extract the x and y coordinates from the parallel tree
     for node in tree.preorder():
         dtree.select_node(node.dtree_id)
         x = dtree.get_x()
         y = dtree.get_y()
         node.location = (x, y)
     # take off the silly dtree_id members
     for node in tree.preorder():
         del node.dtree_id
def process_metie(data):
    """ Process met.ie forecasts """

    use_icons = common.get_string("use_icons", "0")
    metric = common.get_string("metric", "1")

    days = ""

    desc = common.get_string('metierev', '')
    for jobj in json.loads(data):
        myday = day.Day()
        tmp_day = jobj["date"] + "T" + jobj["time"]
        myday.timestamp = time.mktime(time.strptime(tmp_day, '%Y-%m-%dT%H:%M'))
        myday.day = datetime.datetime.fromtimestamp(myday.timestamp).strftime("%A")
        myday.max = str(jobj["temperature"])
        myday.icon = jobj["weatherNumber"]
        myday.text = jobj["weatherDescription"]

        if use_icons != "1":
            myday.icon = "wi wi-met-ie-" + myday.icon
        else:
            myday.icon = "y" + myday.icon + ".png"

        if metric == "1":
            myday.max += "&deg;C"
        else:
            myday.max = str(round(float(myday.max) * 9.0 / 5.0 + 32.0)) + "&deg;F"

        days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    return [True, days, desc]
예제 #6
0
 def test_selection(self):
     """
     Test selection of a node by its id.
     """
     # first create a tree
     tree = day.Day()
     tree.begin_node(1)
     tree.set_x(1001)
     tree.begin_node(11)
     tree.set_x(1011)
     tree.end_node()
     tree.begin_node(12)
     tree.set_x(1012)
     tree.end_node()
     tree.begin_node(13)
     tree.end_node()
     tree.end_node()
     # test some stuff without moving the cursor
     self.assertRaises(TypeError, tree.select_node)
     self.assertRaises(TypeError, tree.select_node, 1, 1)
     self.assertRaises(ValueError, tree.select_node, 43)
     # select the root and verify the x value
     tree.select_node(1)
     self.assertEquals(tree.get_x(), 1001)
     # change the selection and verify the x value
     tree.select_node(12)
     self.assertEquals(tree.get_x(), 1012)
예제 #7
0
 def test_pre_creation(self):
     """
     We cannot set or get items until the tree has been created.
     """
     tree = day.Day()
     self.assertRaises(TypeError, tree.get_x, 3)
     self.assertRaises(TypeError, tree.set_x)
     self.assertRaises(RuntimeError, tree.get_x)
     self.assertRaises(RuntimeError, tree.set_x, 3)
예제 #8
0
def process_mf(data):
    """ Process meteofrance.com Forecasts """

    use_icons = main.get_string("use_icons", "0")
    metric = main.get_string("metric", "1")

    days = ""

    desc = data.split("<h1>", 1)[1].split("</h1>", 1)[0].strip()
    data = data.split("<!-- LISTE JOURS -->",
                      1)[1].split("<!-- LISTE JOURS/ -->", 1)[0].strip()

    bits = data.split('title="')
    del bits[0]
    print("")

    for bit in bits:
        myday = day.Day()
        myday.day = bit.split("<a>", 1)[1].split("</a>", 1)[0].strip()
        myday.min = bit.split('class="min-temp">',
                              1)[1].split('°C Minimale', 1)[0].strip()
        myday.max = bit.split('class="max-temp">',
                              1)[1].split('°C Maximale', 1)[0].strip()
        myday.icon = bit.split('<dd class="pic40 ', 1)[1].split('">',
                                                                1)[0].strip()

        if metric == "1":
            myday.max = myday.max + "&deg;C"
            myday.min = myday.min + "&deg;C"
        else:
            myday.max = str(round(int(myday.max) * 9 / 5 + 32)) + "&deg;F"
            myday.min = str(round(int(myday.max) * 9 / 5 + 32)) + "&deg;F"

        icon = TABLE.get(myday.icon)
        if icon is None:
            # TODO: report/log missing CSS name
            myday.icon = None
        else:
            if use_icons != "1":
                if icon.replace("_", "-") != 'j-w1-8-n"':
                    myday.icon = "wi wi-meteofrance-" + icon.replace('_', '-')
                else:
                    myday.icon = "flaticon-thermometer"
            else:
                myday.icon = "mf_" + icon + ".png"

        days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    print(days)

    return [True, days, desc]
예제 #9
0
 def __buildRoster(self, arr):
     roster = {}
     for n in range(1, len(arr)):  #Skip the headers
         try:
             date = self.__convertDate(arr[n][0])
             shifts = self.__appendShiftsToStaff(arr[n], self.__headers)
             roster[date.strftime('%d/%m/%Y')] = day.Day(date, shifts)
         except Exception as e:
             #print("Failed to parse date '%s'" % arr[n][0])
             #print(str(e))
             continue
     return roster
예제 #10
0
def process_metservice(data):
    """ Process metservice forecasts """

    use_icons = common.get_string("use_icons", "0")
    metric = common.get_string("metric", "1")

    days = ""

    jobj = json.loads(data)
    loop = jobj['days']
    # ftime = loop[0]["issuedAtISO"]
    desc = jobj["locationECWasp"] + ", New Zealand"

    for jtmp in loop:
        myday = day.Day()
        jtmp['dateISO'] = jtmp['dateISO'][:-6]
        myday.timestamp = time.mktime(time.strptime(jtmp['dateISO'], "%Y-%m-%dT%H:%M:%S"))
        myday.day = jtmp["dow"]
        myday.text = jtmp["forecast"]
        myday.max = jtmp["max"]
        myday.min = jtmp["min"]

        if "partDayData" in jtmp:
            myday.icon = jtmp["partDayData"]["afternoon"]["forecastWord"]
        else:
            myday.icon = jtmp["forecastWord"]

        myday.icon = myday.icon.lower().replace(" ", "-").strip()

        if use_icons != "1":
            if myday.icon != "frost":
                myday.icon = "wi wi-metservice-" + myday.icon
            else:
                myday.icon = "flaticon-thermometer"
        else:
            myday.icon = myday.icon.replace("-", "_")
            myday.icon = "ms_" + myday.icon + ".png"

        if metric:
            myday.max += "&deg;C"
            myday.min += "&deg;C"
        else:
            myday.max = str(round(float(myday.max) * 9.0 / 5.0 + 32.0)) + "&deg;F"
            myday.min = str(round(float(myday.min) * 9.0 / 5.0 + 32.0)) + "&deg;F"

        days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    return [True, days, desc]
예제 #11
0
 def test_simple_creation(self):
     """
     Test creation of a simple tree.
     """
     tree = day.Day()
     self.assertRaises(TypeError, tree.end_node, 3)
     self.assertRaises(TypeError, tree.begin_node)
     self.assertRaises(RuntimeError, tree.end_node)
     tree.begin_node(3)
     tree.end_node()
     self.assertRaises(RuntimeError, tree.end_node)
     self.assertRaises(TypeError, tree.get_node_count, 1)
     self.assertEquals(tree.get_node_count(), 1)
예제 #12
0
def process_wmo(data):
    """ Process WMO forecast """

    metric = common.get_string("metric", "1")

    days = ""

    jobj = json.loads(data)

    desc = jobj['city']['cityName'] + ", " + jobj['city']['member']['memName']
    # tmp = jobj['city']['forecast']['issueDate']

    # "yyyy-MM-dd HH:mm:ss"
    # timestamp = time.mktime(time.strptime(tmp, '%Y-%m-%d %H:%M:%S'))

    jarr = jobj['city']['forecast']['forecastDay']
    for j in jarr:
        myday = day.Day()
        myday.timestamp = time.mktime(time.strptime(j['forecastDate'], '%Y-%m-%d'))
        myday.day = datetime.datetime.fromtimestamp(myday.timestamp).strftime("%A")

        myday.text = j['weather']
        myday.max = j['maxTemp'] + "&deg;C"
        myday.min = j['minTemp'] + "&deg;C"
        if metric != "1":
            myday.max = j['maxTempF'] + "&deg;F"
            myday.min = j['minTempF'] + "&deg;F"

        code = str(j['weatherIcon'])[:-2]

        if code == "28":
            myday.icon = "flaticon-cactus"
        elif code == "29" or code == "30":
            myday.icon = "flaticon-thermometer"
        elif code == "32":
            myday.icon = "flaticon-cold"
        elif code == "33":
            myday.icon = "flaticon-warm"
        elif code == "34":
            myday.icon = "flaticon-cool"
        else:
            myday.icon = "wi wi-wmo-" + code

        days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    return [True, days, desc]
예제 #13
0
    def update_cal(self, transactions_list):
        # Need to account for when only 1 transaction is passed
        if type(transactions_list) is not list:
            transactions_list = [transactions_list]

        for transaction in transactions_list:

            if str(transaction.date) not in self.days:
                self.days[str(transaction.date)] = day.Day(transaction.date)

            self.days[str(transaction.date)].add_transaction(transaction)

        self.update_running_bal()
        self.config.write_config()
예제 #14
0
def process_metoffice(data):
    """ Process MET Office forecasts """

    use_icons = common.get_string("use_icons", "0")
    metric = common.get_string("metric", "1")

    days = ""

    desc = data.split('<title>', 1)[1].split(' weather - Met Office</title>', 1)[0].strip()
    forecasts = data.split('<ul id="dayNav"', 2)[1].split('</ul>', 2)[0].split('<li')
    del forecasts[0]
    for line in forecasts:
        myday = day.Day()
        myday.day = line.split('data-tab-id="', 1)[1].split('"')[0].strip()
        myday.timestamp = time.mktime(time.strptime(myday.day, '%Y-%m-%d'))
        myday.day = datetime.datetime.fromtimestamp(myday.timestamp).strftime("%A")

        myday.icon = "https://beta.metoffice.gov.uk" + line.split('<img class="icon"')[1]
        myday.icon = myday.icon.split('src="')[1].split('">')[0].strip()

        myday.icon = os.path.basename(myday.icon).replace(".svg", ".png").strip()
        myday.min = line.split('<span class="tab-temp-low"', 1)[1].split('">')[1]
        myday.min = myday.min.split("</span>", 1)[0].strip()
        myday.max = line.split('<span class="tab-temp-high"', 1)[1].split('">')[1]
        myday.max = myday.max.split("</span>")[0].strip()
        myday.text = line.split('<div class="summary-text', 1)[1].split('">', 3)[2]
        myday.text = myday.text.split("</div>", 1)[0]
        myday.text = myday.text.replace('</span>', '').replace('<span>', '').strip()

        if metric == "1":
            myday.min += "C"
            myday.max += "C"
        else:
            myday.min = str(round(float(myday.min) * 9.0 / 5.0 + 32.0)) + "&deg;F"
            myday.max = str(round(float(myday.max) * 9.0 / 5.0 + 32.0)) + "&deg;F"

        if use_icons == "1":
            myday.icon = "met" + myday.icon
        else:
            myday.icon = "wi wi-metoffice-" + myday.icon[:-4]

        days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    return [True, days, desc]
예제 #15
0
def process_wcom(data):
    """ Process weather.com forecasts """

    use_icons = common.get_string("use_icons", "0")
    metric = common.get_string("metric", "1")

    days = ""

    jobj = json.loads(data)
    desc = jobj["id"]

    valid_date = jobj["vt1dailyForecast"]["validDate"]
    icons = jobj["vt1dailyForecast"]["day"]["icon"]
    phrase = jobj["vt1dailyForecast"]["day"]["phrase"]
    day_temp = jobj["vt1dailyForecast"]["day"]["temperature"]
    night_temp = jobj["vt1dailyForecast"]["night"]["temperature"]

    rng = range(len(valid_date))
    for i in rng:
        myday = day.Day()
        myday.timestamp = time.mktime(time.strptime(valid_date[i], '%Y-%m-%dT%H:%M:%S%z'))
        myday.day = datetime.datetime.fromtimestamp(myday.timestamp).strftime("%A")
        myday.text = phrase[i]
        myday.icon = icons[i]
        myday.max = str(day_temp[i])
        myday.min = str(night_temp[i])

        if use_icons != "1":
            myday.icon = "wi wi-yahoo-" + myday.icon
        else:
            myday.icon = "yahoo" + str(myday.icon) + ".gif"

        if metric == "1":
            myday.max += "&deg;C"
            myday.min += "&deg;C"
        else:
            myday.max += "&deg;F"
            myday.min += "&deg;F"

        days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    return [True, days, desc]
예제 #16
0
def process_day(tmpstr, startid, metric):
    """ Extract data based on the id number """

    last_ts = int(time.time())

    if startid == 196:
        endid = startid + 24
    else:
        endid = startid + 19

    tmpstr = tmpstr.split('<span data-reactid="' + str(startid) + '">', 1)[1]
    tmpstr, rest = tmpstr.split('data-reactid="' + str(endid) + '">', 1)
    dow = tmpstr.split('</span>', 1)[0].strip()
    last_ts = timestamp = forecasts.convert_day_to_ts(dow, last_ts)
    text = tmpstr.split('<img alt="', 1)[1].split('"', 1)[0].strip()
    icon = tmpstr.split('<img alt="', 1)[1].split('"', 1)[1]
    icon = icon.split('src="', 1)[1].split('"', 1)[0].strip()
    # pop = tmpstr.split('Precipitation: ', 1)[1].split('"', 1)[0].strip()
    maxtemp = tmpstr.split('data-reactid="' + str(startid + 10) + '">', 1)[1]
    maxtemp = maxtemp.split('</span>', 1)[0]
    mintemp = tmpstr.split('data-reactid="' + str(startid + 13) + '">', 1)[1]
    mintemp = mintemp.split('</span>', 1)[0]

    soup = BeautifulSoup(maxtemp, "html.parser")
    maxtemp = soup.text[:-1]
    soup = BeautifulSoup(mintemp, "html.parser")
    mintemp = soup.text[:-1]

    if metric == "1":
        maxtemp = str(round((int(maxtemp) - 32) * 5 / 9)) + "&deg;C"
        mintemp = str(round((int(mintemp) - 32) * 5 / 9)) + "&deg;C"
    else:
        maxtemp += "&deg;F"
        mintemp += "&deg;F"

    myday = day.Day()

    myday.day = dow
    myday.timestamp = timestamp
    myday.text = text
    myday.icon = icon
    myday.min = mintemp
    myday.max = maxtemp

    return myday, rest
예제 #17
0
def process_yrno(data):
    """ Process yr.no forecast """

    use_icons = common.get_string("use_icons", "0")

    jobj = xmltodict.parse(data)
    jobj = jobj['weatherdata']
    location = jobj['location']
    desc = location['name'] + ", " + location['country']

    days = ""
    jarr = jobj['forecast']['tabular']['time']

    for line in jarr:
        myday = day.Day()
        from_time = line['@from']
        to_time = line['@to']
        code = line['symbol']['@var']
        myday.min = line['precipitation']['@value'] + "mm"
        myday.max = line['temperature']['@value'] + "&deg;C"

        myday.text = line['windSpeed']['@name'] + ", " + line['windSpeed']['@mps'] + "m/s from the "
        myday.text += line['windDirection']['@name']

        date1 = time.mktime(time.strptime(from_time, '%Y-%m-%dT%H:%M:%S'))
        date2 = time.mktime(time.strptime(to_time, '%Y-%m-%dT%H:%M:%S'))

        myday.timestamp = date1
        from_time = datetime.datetime.fromtimestamp(date1).strftime("%H:%M")
        to_time = datetime.datetime.fromtimestamp(date2).strftime("%H:%M")
        date = datetime.datetime.fromtimestamp(date1).strftime("%A")
        myday.day = date + ": " + from_time + "-" + to_time

        if use_icons != "1":
            myday.icon = "wi wi-yrno-" + code
        else:
            myday.icon = "yrno" + code + ".png"

        days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    return [True, days, desc]
예제 #18
0
 def test_complex_creation(self):
     """
     Test creation of a more complex tree.
     """
     tree = day.Day()
     tree.begin_node(1)
     tree.set_x(42)
     tree.begin_node(10)
     tree.end_node()
     tree.begin_node(20)
     tree.begin_node(21)
     tree.end_node()
     tree.begin_node(22)
     tree.end_node()
     tree.begin_node(23)
     tree.end_node()
     tree.end_node()
     self.assertEquals(tree.get_x(), 42)
     tree.end_node()
예제 #19
0
 def test_rooting(self):
     # first create a tree
     # 1
     #   11
     #   12
     #     121
     #     122
     #   13
     tree = day.Day()
     tree.begin_node(1)
     tree.set_x(1001)
     tree.begin_node(11)
     tree.set_x(1011)
     tree.end_node()
     tree.begin_node(12)
     tree.set_x(1012)
     tree.begin_node(121)
     tree.end_node()
     tree.begin_node(122)
     tree.end_node()
     tree.end_node()
     tree.begin_node(13)
     tree.end_node()
     tree.end_node()
     # do a sanity check on the created tree
     self.assertEquals(tree.get_node_count(), 6)
     self.assertEquals(tree.get_root_id(), 1)
     # no node should be selected
     self.assertEquals(tree.get_subtree_count(), 0)
     # assert subtree counts of various nodes
     tree.select_node(1)
     self.assertEquals(tree.get_subtree_count(), 3)
     tree.select_node(12)
     self.assertEquals(tree.get_subtree_count(), 2)
     tree.select_node(11)
     self.assertEquals(tree.get_subtree_count(), 0)
     # reroot at a node and make some assertions
     tree.select_node(12)
     tree.reroot()
     self.assertEquals(tree.get_node_count(), 6)
     self.assertEquals(tree.get_subtree_count(), 3)
     self.assertEquals(tree.get_root_id(), 12)
예제 #20
0
def process_apixu(data):
    """ Process apixu.com forecasts """

    use_icons = common.get_string("use_icons", "0")
    metric = common.get_string("metric", "1")

    days = ""

    jobj = json.loads(data)
    desc = jobj["location"]["name"] + ", " + jobj["location"]["country"]
    for j in jobj["forecast"]["forecastday"]:
        myday = day.Day()
        myday.timestamp = j['date_epoch']
        myday.day = datetime.datetime.fromtimestamp(myday.timestamp).strftime("%A")
        this_day = j["day"]

        if metric == "1":
            myday.min = str(this_day['mintemp_c']) + "&deg;C"
            myday.max = str(this_day['maxtemp_c']) + "&deg;C"
        else:
            myday.min = str(this_day['mintemp_f']) + "&deg;F"
            myday.max = str(this_day['maxtemp_f']) + "&deg;F"

        for cond in common.CONDITIONS:
            if cond["code"] == this_day["condition"]["code"]:
                myday.icon = str(cond["icon"])
                myday.text = cond["day"]
                break

        if use_icons != "1":
            myday.icon = "wi wi-apixu-" + myday.icon
        else:
            myday.icon = "apixu_" + myday.icon + ".png"

        days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    return [True, days, desc]
예제 #21
0
def process_owm(data):
    """ Process OpenWeatherMap.org forecasts """

    metric = common.get_string("metric", "1")

    days = ""

    jobj = json.loads(data)

    desc = jobj["city"]["name"] + ", " + jobj["city"]["country"]

    for j in jobj['list']:
        myday = day.Day()
        myday.timestamp = j['dt']
        myday.day = datetime.datetime.fromtimestamp(myday.timestamp).strftime("%A")
        myday.max = str(round(float(j['temp']['max'])))
        myday.min = str(round(float(j['temp']['min'])))
        weather = j['weather'][0]

        myday.text = weather['description']
        myday.icon = weather['icon']
        if not myday.icon.endswith('n'):
            myday.icon = "wi wi-owm-day-" + str(weather['id'])
        else:
            myday.icon = "wi wi-owm-night-" + str(weather['id'])

        if metric == "1":
            myday.max += "&deg;C"
            myday.min += "&deg;C"
        else:
            myday.max += "&deg;F"
            myday.min += "&deg;F"

        days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    return [True, days, desc]
예제 #22
0
def process_darksky(data):
    """ Process darksky forecasts """

    metric = common.get_string("metric", "1")

    days = ""

    jobj = json.loads(data)
    desc = str(jobj["latitude"]) + ", " + str(jobj["longitude"])
    daily = jobj["daily"]

    for jarr in daily["data"]:
        myday = day.Day()
        myday.icon = jarr["icon"]
        myday.timestamp = jarr['time']
        myday.day = datetime.datetime.fromtimestamp(myday.timestamp).strftime("%A")
        myday.max = str(round(float(jarr['temperatureHigh'])))
        myday.min = str(round(float(jarr['temperatureLow'])))

        if metric == "1":
            myday.max += "&deg;C"
            myday.min += "&deg;C"
        else:
            myday.max += "&deg;F"
            myday.min += "&deg;F"

        myday.icon = "wi wi-forecast-io-" + myday.icon
        myday.text = jarr["summary"]

        days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    print(days)

    return [True, days, desc]
예제 #23
0
def process_wgov(data):
    """ Process the data from weather.gov """

    metric = main.get_string("metric", "1")

    days = ""

    jobj = json.loads(data)

    desc = jobj['currentobservation']['name']
    # tmp = jobj['creationDate']
    # date = tmp[:-3] + tmp[-2:]
    # print(date)

    # timestamp = time.mktime(time.strptime(date, '%Y-%m-%dT%H:%M:%S%z'))

    period_name = jobj['time']['startPeriodName']
    valid_time = jobj['time']['startValidTime']
    weather = jobj['data']['weather']
    icon_link = jobj['data']['iconLink']
    temperature = jobj['data']['temperature']

    rng = range(0, len(period_name))

    for i in rng:
        myday = day.Day()
        # https://forecast.weather.gov/newimages/medium/bkn.png
        # DualImage.php?i=bkn&j=scttsra&jp=30
        # https://forecast.weather.gov/DualImage.php?i=bkn&j=scttsra&jp=30
        icon_link[i] = icon_link[i].replace("http://", "https://").replace(
            ".png", ".jpg").strip()

        file_name = "wgov" + os.path.basename(icon_link[i])
        if file_name.startswith("wgovDualImage.php"):
            tmp = icon_link[i].split("?", 1)[1].strip()
            fimg = simg = ""
            fper = sper = ""
            lines = tmp.split("&")
            for line in lines:
                line = line.strip()
                bits = line.split("=", 1)
                if bits[0].strip() == "i":
                    fimg = "wgov" + bits[1].strip() + ".jpg"
                if bits[0].strip() == "j":
                    simg = "wgov" + bits[1].strip() + ".jpg"
                if bits[0].strip() == "ip":
                    fper = bits[1].strip()
                if bits[0].strip() == "jp":
                    sper = bits[1].strip()

            bmp1 = Image.open(main.CACHEBASE + "/" + fimg).convert("RGBA")

            if fimg != simg:
                bmp2 = Image.open(main.CACHEBASE + "/" + simg).convert("RGBA")
                icon_link[i] = combine_images(bmp1, bmp2, fimg[4:-4],
                                              simg[4:-4], fper + "%",
                                              sper + "%")
            else:
                icon_link[i] = combine_image(bmp1, fper + "%", sper + "%")
        else:
            match = re.search(r"\d{2,3}", file_name)
            if match is not None:
                file_name = re.sub(r'\d{2,3}\.jpg$', ".jpg", file_name)
                bmp1 = Image.open(main.CACHEBASE + "/" +
                                  file_name).convert("RGBA")
                icon_link[i] = combine_image(bmp1, match.group(0) + "%", "%")
            else:
                icon_link[i] = file_name

        tmp = valid_time[i]
        date = tmp[:-3] + tmp[-2:]

        myday.timestamp = time.mktime(
            time.strptime(date, '%Y-%m-%dT%H:%M:%S%z'))
        myday.day = period_name[i]

        myday.max = temperature[i] + "&deg;F"
        if metric == "1":
            myday.max = str(round(
                (float(temperature[i]) - 32) * 5 / 9)) + "&deg;C"

        myday.text = weather[i]
        myday.icon = icon_link[i]

        days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    return [True, days, desc]
예제 #24
0
def process_aemet(data):
    """ Process AEMET forecasts """

    use_icons = common.get_string("use_icons", "0")
    metric = common.get_string("metric", "1")

    jobj = xmltodict.parse(data)

    jobj = jobj["root"]
    desc = jobj["nombre"] + ", " + jobj["provincia"]
    # print(desc)

    # elaborado = jobj["elaborado"]
    # yyyy-MM-dd'T'HH:mm:ss
    # timestamp = time.mktime(time.strptime(elaborado, "%Y-%m-%dT%H:%M:%S"))
    # dayname = datetime.datetime.fromtimestamp(timestamp).strftime("%A -- %H:%M")
    # print(dayname)

    days = ""

    dates = jobj['prediccion']['dia']
    for date in dates:
        myday = day.Day()
        myday.day = date['@fecha']
        myday.timestamp = time.mktime(time.strptime(myday.day, "%Y-%m-%d"))
        myday.day = datetime.datetime.fromtimestamp(myday.timestamp).strftime("%A")

        myday.max = date['temperatura']['maxima']
        myday.min = date['temperatura']['minima']

        if isinstance(date['estado_cielo'], collections.OrderedDict):
            myday.text = date['estado_cielo']['@descripcion']
            myday.icon = date['estado_cielo']['#text']
        elif isinstance(date['estado_cielo'], list):
            for i in date['estado_cielo']:
                try:
                    if isinstance(i, collections.OrderedDict) and i['#text'] != "":
                        myday.text = i['@descripcion']
                        myday.icon = i['#text']
                        # print(myday)
                        break
                except KeyError:
                    pass

        if use_icons != "1":
            if myday.icon != "7":
                myday.icon = "wi wi-aemet-" + myday.icon
            else:
                myday.icon = "flaticon-thermometer"
        else:
            myday.icon = "aemet_" + myday.icon + "_g.png"

        if metric == "1":
            myday.max += "&deg;C"
            myday.min += "&deg;C"
        else:
            if myday.min != "":
                myday.min = str(round(float(myday.min) * 9.0 / 5.0 + 32.0)) + "&deg;F"

            if myday.max != "":
                myday.max = str(round(float(myday.max) * 9.0 / 5.0 + 32.0)) + "&deg;F"

        if myday.min.startswith("&deg;"):
            myday.min = ""

        if myday.max == "" or myday.max.startswith("&deg;"):
            myday.max = "N/A"

        days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    return [True, days, desc]
예제 #25
0
def process_wz(data):
    """ Process Weather Zone forecast """

    jobj = xmltodict.parse(data)
    jobj = jobj['rss']['channel']

    pub_date = jobj["pubDate"]
    desc = jobj["title"]
    # Sun, 12 May 2019 08:56:04 +1000
    # EEE, dd MMM yyyy HH:mm:ss Z
    last_ts = time.mktime(time.strptime(pub_date, '%a, %d %b %Y %H:%M:%S %z'))

    mydesc = jobj['item'][0]["description"].split("<b>")

    days = ""

    use_icons = common.get_string("use_icons", "0")
    metric = common.get_string("metric", "1")

    for line in mydesc:
        line = line.strip()
        if line == "":
            continue

        tmp = line.split("</b>", 1)
        myday = day.Day()
        myday.timestamp = convert_day_to_ts(tmp[0].strip(), last_ts)
        if myday.timestamp != 0:
            myday.day = datetime.datetime.fromtimestamp(myday.timestamp).strftime("%A")
        else:
            myday.day = tmp[0].strip()

        if len(tmp) <= 1:
            continue

        mybits = tmp[1].strip().split("<br />")
        mybits[1] = mybits[1].strip()

        tmpstr = '<img src="http://www.weatherzone.com.au/images/icons/fcast_30/'
        myimg = mybits[1].replace(tmpstr, "")
        myimg = myimg.replace("\">", "").replace(".gif", "").replace("_", "-").strip()

        myday.text = mybits[2].strip()
        myrange = mybits[3].split(" - ", 1)

        if use_icons != "1":
            if myimg != "frost-then-sunny":
                myday.icon = "wi wi-weatherzone-" + myimg
            else:
                myday.icon = "flaticon-thermometer"
        else:
            myday.icon = "wz" + myimg.replace("-", "_") + ".png"

        myday.max = myrange[1].strip()
        myday.min = myrange[0].strip()

        if metric != "1":
            myday.max = str(round(float(myrange[1][:-7]) * 9.0 / 5.0 + 32.0, 0)) + "&deg;F"
            myday.min = str(round(float(myrange[0][:-7]) * 9.0 / 5.0 + 32.0, 0)) + "&deg;F"

        days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    return [True, days, desc]
예제 #26
0
def process_bom2(data):
    """ Process BoM forecasts method 2 """

    use_icons = common.get_string("use_icons", "0")
    metric = common.get_string("metric", "1")

    desc = data.split('<title>', 1)[1].split(' Weather - Bureau of Meteorology</title>', 1)[0]
    desc = desc + ", Australia"

    data = data.split('<div class="forecasts">', 1)[1]
    days = ""

    bits = data.split('<dl class="forecast-summary">')
    del bits[0]
    bit = bits[0]

    myday = day.Day()
    myday.day = bit.split('<a href="', 1)[1].split('">', 1)[0].split("/forecast/detailed/#d", 1)[1]
    myday.timestamp = time.mktime(time.strptime(myday.day, '%Y-%m-%d'))
    myday.day = datetime.datetime.fromtimestamp(myday.timestamp).strftime("%A")

    myday.icon = bit.split("<img src=\"", 1)[1].split("\" alt=\"", 1)[0]
    myday.icon = myday.icon.strip()

    if '<dd class="max">' in bit:
        myday.max = bit.split('<dd class="max">', 1)[1].split('</dd>', 1)[0].strip()

    if '<dd class="min">' in bit:
        myday.min = bit.split("<dd class=\"min\">")[1].split("</dd>")[0].strip()

    myday.text = bit.split('<dd class="summary">', 1)[1].split('</dd>', 1)[0].strip()

    file_name = os.path.basename(myday.icon)[:-4]
    if use_icons != "1":
        if file_name != "frost":
            myday.icon = "wi wi-bom-" + file_name
        else:
            myday.icon = "flaticon-thermometer"
    else:
        myday.icon = "bom2" + file_name.replace('-', '_') + ".png"

    myday.max = myday.max.replace("°C", "").replace("&deg;C", "").strip()
    myday.min = myday.min.replace("°C", "").replace("&deg;C", "").strip()

    if metric == "1":
        myday.max += "&deg;C"
        myday.min += "&deg;C"
    else:
        if myday.min != "":
            myday.min = str(round(float(myday.min) * 9.0 / 5.0 + 32.0)) + "&deg;F"

        if myday.max != "":
            myday.max = str(round(float(myday.max) * 9.0 / 5.0 + 32.0)) + "&deg;F"

    if myday.min.startswith("&deg;"):
        myday.min = ""

    if myday.max == "" or myday.max.startswith("&deg;"):
        myday.max = "N/A"

    days += str(myday) + ","

    del bits[0]

    for bit in bits:
        if '</div>' in bit:
            bit = bit.split('</div>', 1)[0].strip()

        myday = day.Day()
        myday.day = bit.split('<a href="', 1)[1].split('">', 1)[0]
        myday.day = myday.day.split("/forecast/detailed/#d", 1)[1].strip()
        myday.timestamp = time.mktime(time.strptime(myday.day, '%Y-%m-%d'))
        myday.day = datetime.datetime.fromtimestamp(myday.timestamp).strftime("%A")

        myday.icon = bit.split('<img src="', 1)[1].split('" alt="', 1)[0].strip()
        myday.max = bit.split('<dd class="max">')[1].split('</dd>')[0].strip()
        myday.min = bit.split('<dd class="min">')[1].split('</dd>')[0].strip()
        myday.text = bit.split('<dd class="summary">', 1)[1].split('</dd>', 1)[0].strip()

        file_name = os.path.basename(myday.icon)[:-4]
        if use_icons != "1":
            if file_name != "frost":
                myday.icon = "wi wi-bom-" + file_name
            else:
                myday.icon = "flaticon-thermometer"
        else:
            myday.icon = "bom2" + file_name.replace('-', '_') + ".png"

        myday.max = myday.max.replace("°C", "").replace("&deg;C", "").strip()
        myday.min = myday.min.replace("°C", "").replace("&deg;C", "").strip()

        if metric == "1":
            myday.max += "&deg;C"
            myday.min += "&deg;C"
        else:
            if myday.min != "":
                myday.min = str(round(float(myday.min) * 9.0 / 5.0 + 32.0)) + "&deg;F"

            if myday.max != "":
                myday.max = str(round(float(myday.max) * 9.0 / 5.0 + 32.0)) + "&deg;F"

        if myday.min.startswith("&deg;"):
            myday.min = ""

        if myday.max == "" or myday.max.startswith("&deg;"):
            myday.max = "N/A"

        days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    return [True, days, desc]
예제 #27
0
def process_dwd(data):
    """ Process DWD.de forecasts """

    use_icons = common.get_string("use_icons", "0")
    metric = common.get_string("metric", "1")

    days = ""

    bits = data.split("<title>", 1)[1]
    desc = bits.split("</title>", 1)[0]
    desc = desc.split(' - ', 2)[2].strip()

    ftime = data.split('<tr class="headRow">', 1)[1].split('</tr>', 1)[0].strip()
    date = ftime.split('<td width="30%" class="stattime">', 1)[1].split('</td>', 1)[0].strip()
    ftime = date + " " + ftime.split('<td width="40%" class="stattime">', 2)[1]
    ftime = ftime.split(' Uhr</td>', 1)[0].strip()
    # dd.MM.yyyy HH
    last_ts = time.mktime(time.strptime(ftime, "%d.%m.%Y %H"))
    # dayname = datetime.datetime.fromtimestamp(timestamp).strftime("%A -- %Y-%m-%d %H")
    # print(dayname)

    data = data.split('<td width="40%" class="statwert">Vorhersage</td>', 1)[1]
    data = data.split('</table>', 1)[0].strip()
    lines = data.split('<tr')
    del lines[0]
    for line in lines:
        myday = day.Day()

        if len(line.split('<td ><b>')) > 1:
            myday.day = line.split('<td ><b>', 1)[1].split('</b></td>', 1)[0].strip()
        else:
            myday.day = line.split('<td><b>', 1)[1].split('</b></td>', 1)[0].strip()

        myday.timestamp = convert_day_to_ts(myday.day, last_ts, "de_DE")

        if len(line.split('<td ><img name="piktogramm" src="', 2)) > 1:
            myday.icon = line.split('<td ><img name="piktogramm" src="', 1)[1]
            myday.icon = myday.icon.split('" width="50" alt="', 1)[0].strip()
        else:
            myday.icon = line.split('<td><img name="piktogramm" src="', 1)[1]
            myday.icon = myday.icon.split('" width="50" alt="', 1)[0].strip()

        for i in line.split('<td'):
            if 'Grad' in i:
                myday.max = i
                myday.max = myday.max.split('Grad', 1)[0].strip()[1:]
                break

        myday.icon = myday.icon.replace('/DE/wetter/_functions/piktos/vhs_', '')
        myday.icon = myday.icon.replace('?__blob=normal', '').strip()
        myday.icon = "dwd_" + myday.icon.replace('-', '_')

        if use_icons != "1":
            myday.icon = myday.icon[4:-4]
            if myday.icon != "pic-48" and myday.icon != "pic-66" and myday.icon != "pic67":
                myday.icon = "wi wi-dwd-" + myday.icon
            else:
                myday.icon = "flaticon-thermometer"

        if metric == "1":
            myday.max += "&deg;C"
        else:
            if myday.max != "":
                myday.max = str(round(float(myday.max) * 9.0 / 5.0 + 32.0)) + "&deg;F"

        if not myday.max.startswith('&deg;'):
            days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    return [True, days, desc]
예제 #28
0
def process_bom1(data):
    """ Process BoM FTP forecast """

    use_icons = common.get_string("use_icons", "0")
    metric = common.get_string("metric", "1")
    bomtown = common.get_string("bomtown", "")

    if bomtown == "":
        return [False, "Town or suburb not set, update settings.txt"]

    jobj = xmltodict.parse(data)['product']
    # content = jobj["amoc"]["issue-time-local"]['#text']

    days = ""
    loc_content = None

    for area in jobj["forecast"]["area"]:
        if bomtown == area['@description']:
            loc_content = area
            break

    if loc_content is None:
        return[False, "Unable to match '" + bomtown + "'", ""]

    jobj = loc_content
    desc = jobj["@description"] + ", Australia"

    for forecast in jobj['forecast-period']:
        myday = day.Day()
        start_time = forecast['@start-time-local'][:-6]
        myday.timestamp = time.mktime(time.strptime(start_time, '%Y-%m-%dT%H:%M:%S'))
        myday.day = datetime.datetime.fromtimestamp(myday.timestamp).strftime("%A")

        if forecast['@index'] != "0":
            for i in range(len(forecast['element'])):
                if forecast['element'][i]['@type'] == "forecast_icon_code":
                    myday.icon = forecast['element'][i]['#text']
                if forecast['element'][i]['@type'] == "air_temperature_minimum":
                    myday.min = forecast['element'][i]['#text']
                if forecast['element'][i]['@type'] == "air_temperature_maximum":
                    myday.max = forecast['element'][i]['#text']
        else:
            try:
                myday.icon = forecast['element']['#text']
            except Exception:
                for i in range(len(forecast['element'])):
                    if forecast['element'][i]['@type'] == "forecast_icon_code":
                        myday.icon = forecast['element'][i]['#text']

        for i in range(len(forecast['text'])):
            if forecast['text'][i]['@type'] == "precis":
                myday.text = forecast['text'][i]['#text']

        if use_icons != "1":
            if myday.icon != "14":
                myday.icon = "wi wi-bom-ftp-" + myday.icon
            else:
                myday.icon = "flaticon-thermometer"
        else:
            myday.icon = "bom" + myday.icon + ".png"

        if metric == "1":
            myday.max += "&deg;C"
            myday.min += "&deg;C"
        else:
            myday.min = str(round(float(myday.min) * 9.0 / 5.0 + 32.0)) + "&deg;F"
            myday.max = str(round(float(myday.max) * 9.0 / 5.0 + 32.0)) + "&deg;F"

        if myday.max == "&deg;C" or myday.max == "&deg;F" or myday.max == "":
            myday.max = "N/A"

        if myday.min == "&deg;C" or myday.min == "&deg;F":
            myday.min = ""

        days += str(myday) + ","

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    return [True, days, desc]
예제 #29
0
def process_wca(data):
    """ Process forecast for weather.gc.ca """

    metric = main.get_string("metric", "1")
    use_icons = main.get_string("use_icons", "0")

    days = ""
    last_ts = 0

    obs = data.split("Forecast issued: ", 1)[1].strip()
    obs = obs.split("</span>", 1)[0].strip()

    i = 0
    j = obs.index(":")
    hour = obs[i:j]
    i = j + 1
    j = obs.index(" ", i)
    minute = obs[i:j]
    i = j + 1
    j = obs.index(" ", i)
    # ampm = obs[i:j]
    i = j + 1
    j = obs.index(" ", i)
    # TZ = obs[i:j]
    i = j + 1
    j = obs.index(" ", i)
    # DOW = obs[i:j]
    i = j + 1
    j = obs.index(" ", i)
    date = obs[i:j]
    i = j + 1
    j = obs.index(" ", i)
    month = obs[i:j]
    i = j + 1
    j = len(obs)
    year = obs[i:j]

    # obs = hour + ":" + minute + " " + ampm + " " + date + " " + month + " " + year
    obs = year + "-" + month + "-" + date + " " + hour + ":" + minute  # + " " + ampm
    # "h:mm aa d MMMM yyyy"
    # last_ts = timestamp = time.mktime(time.strptime(obs, '%Y-%B-%d %I:%M %p'))
    last_ts = timestamp = time.mktime(time.strptime(obs, '%Y-%B-%d %I:%M'))
    date = datetime.datetime.fromtimestamp(timestamp).strftime(
        "%Y-%m-%d %H:%M")
    year = datetime.datetime.fromtimestamp(last_ts).strftime("%Y")

    desc = data.split('<dt>Observed at:</dt>', 1)[1]
    desc = desc.split('<dd class="mrgn-bttm-0">', 1)[1].split("</dd>",
                                                              1)[0].strip()

    data = data.split('<div class="div-table">', 1)[1].strip()
    data = data.split(
        '<section><details open="open" class="wxo-detailedfore">',
        1)[0].strip()
    data = data[:-7].strip()

    doc = BeautifulSoup(data, "html.parser")
    div = doc.find_all("div", class_="div-column")

    j = 0
    while j < len(div):
        myday1 = day.Day()
        myday2 = day.Day()

        head1 = head2 = ""
        content1 = content2 = ""
        img1 = img2 = ""
        maxtemp = mintemp = ""
        pop1 = "0%"
        pop2 = "0%"

        if '<div class="div-row div-row1 div-row-head greybkgrd">' not in str(
                div[j]):
            head1 = str(div[j]).split(
                '<div class="div-row div-row1 div-row-head">', 1)[1]
            head1 = head1.split("</div>", 1)[0].strip()
            tmpday = head1.split("<br/>", 1)[1]
            month = tmpday.split('title="', 1)[1].split('"', 1)[0].strip()
            tmpday = tmpday.split("\xa0", 1)[0].strip()
            date = tmpday + " " + month + " " + year
            timestamp1 = time.mktime(time.strptime(date, '%d %B %Y'))

            maxtemp = str(div[j]).split('title="max">',
                                        1)[1].split("°", 1)[0].strip()
            if metric == "1":
                maxtemp += "&deg;C"
            else:
                maxtemp = str(round(int(maxtemp) * 9 / 5 + 32)) + "&deg;F"

            mystr = str(div[j]).split(
                '<div class="div-row div-row2 div-row-data">', 1)[1]
            mystr = mystr.split('</div>', 1)[0].strip()

            if '<p class="mrgn-bttm-0 pop text-center" title="' in mystr:
                pop1 = mystr.split('<small>', 1)[1].split('</small>',
                                                          1)[0].strip()

        if '<div class="div-row div-row3 div-row-head greybkgrd">' not in str(
                div[j]):
            if '<div class="div-row div-row3 div-row-head" ' in str(div[j]):
                head2 = str(div[j])
                head2 = head2.split(
                    '<div class="div-row div-row3 div-row-head" title="', 1)[1]
                head2 = head2.split("</div>", 1)[0].split('">', 1)[0].strip()
                bits = head2.split("\xa0")
                tmpday = bits[1]
                month = bits[2]
                date = tmpday + " " + month + " " + year
                timestamp2 = time.mktime(time.strptime(date, '%d %B %Y'))
            else:
                head2 = str(div[j]).split(
                    '<div class="div-row div-row3 div-row-head">', 1)[1]
                head2 = head2.split("</div>", 1)[0].strip()
                timestamp2 = last_ts

            mintemp = str(div[j]).split('title="min">',
                                        1)[1].split("°", 1)[0].strip()
            if metric == "1":
                mintemp += "&deg;C"
            else:
                mintemp = str(round(int(mintemp) * 9 / 5 + 32)) + "&deg;F"

            mystr = str(div[j]).split(
                '<div class="div-row div-row4 div-row-data">', 1)[1]
            mystr = mystr.split('</div>', 1)[0].strip()

            if '<p class="mrgn-bttm-0 pop text-center" title="' in mystr:
                pop2 = mystr.split('<small>', 1)[1].split('</small>',
                                                          1)[0].strip()

        srcs = [img['src'] for img in div[j].find_all('img')]
        alts = [alt['alt'] for alt in div[j].find_all('img')]

        if head1 != "":
            count = len(srcs)
            if count > 0:
                img1 = srcs[0]
                content1 = alts[0]

            if head2 != "":
                if count > 1:
                    img2 = srcs[1]
                    content2 = alts[1]
        else:
            count = len(srcs)
            if count > 0:
                img2 = srcs[0]
                content2 = alts[0]

        if head1 != "":
            img1 = img1[14:-4]
            if use_icons == "1":
                img1 = "wca" + img1 + ".png"
            else:
                if img1 == "26":
                    img1 = "flaticon-thermometer"
                else:
                    img1 = "wi wi-weather-gc-ca-" + img1

            myday1.text = content1
            myday1.icon = img1
            myday1.max = maxtemp
            last_ts = myday1.timestamp = timestamp1
            myday1.day = datetime.datetime.fromtimestamp(
                myday1.timestamp).strftime("%A")
            myday1.min = pop1

            days += str(myday1) + ","

        if head2 != "":
            img2 = img2[14:-4]
            if use_icons == "1":
                img2 = "wca" + img2 + ".png"
            else:
                if img2 == "26":
                    img2 = "flaticon-thermometer"
                else:
                    img2 = "wi wi-weather-gc-ca-" + img2

            myday2.text = content2
            myday2.icon = img2
            myday2.max = mintemp
            last_ts = myday2.timestamp = timestamp2
            myday2.day = datetime.datetime.fromtimestamp(
                myday2.timestamp).strftime("%A")
            myday2.day += " Night"
            myday2.min = pop2

            days += str(myday2) + ","

        j += 1

    if days[-1:] == ",":
        days = days[:-1]
    days = "[" + days + "]"

    return [True, days, desc]