def test_forecasts(self):
     url = xmlparsing.location_url(redis=redis.db, locName='Victoria')
     xml = xmlparsing.xml_from_url(url)
     date, forecasts = accuracy.forecasts(xml, 7)
     assert date is not None and forecasts is not None
     # maximum allowed is 5 days
     assert len(forecasts) == 5
def main():
    """Used to get the latest data for the database. Can be run as a cron
       job.
    """
    usage = 'usage: python %s LIVE|devel' % (sys.argv[0])
    usage += "\n> note: python must be run with the '-O' switch to use the "
    usage += 'live database'

    if len(sys.argv) < 2:
        print usage
        exit()

    db = sys.argv[1]

    if (db == 'LIVE' and not __debug__) or (db == 'devel' and __debug__):
        r=redis.db
    else:
        print usage
        exit()

    for loc in ACCURACY_TEST_LOCATIONS:
        url = xp.location_url(redis=r, locName=loc)
        xml = xp.xml_from_url(url)

        date, fcast = forecasts(xml, 5)

        if date is None or fcast is None:
            continue

        key = 'forecast:' + loc
        val = (date, fcast)

        lastRecord = r.lrange(key, 0, 0)

        if (lastRecord is not None and len(lastRecord) == 1 
                and lastRecord[0][0] == date):
            continue

        r.lpush(key, val)
 def test_location_url(self):
     xmlparsing.location_url(redis.db, locName='Squamish')