示例#1
0
def test_metar_age3():
    class Taf():pass
    t=Taf()
    t.text="250000Z akdsjfal dfkj"
    age=get_data_age(t,lambda:datetime(2013,7,10,00,00))
    #print age
    assert age==-timedelta(15,0)
示例#2
0
def test_metar_age():
    class Taf():pass
    t=Taf()
    t.text="312020Z akdsjfal dfkj"
    age=get_data_age(t,lambda:datetime(2013,1,1,0,20))
    #print age
    assert age==timedelta(0,3600*4)
示例#3
0
def test_metar_age2():
    class Taf():pass
    t=Taf()
    t.text="010020Z akdsjfal dfkj"
    age=get_data_age(t,lambda:datetime(2013,12,31,23,59))
    #print age
    assert age==-timedelta(0,60*21)
示例#4
0
def test_metar_age3():
    class Taf():
        pass

    t = Taf()
    t.text = "250000Z akdsjfal dfkj"
    age = get_data_age(t, lambda: datetime(2013, 7, 10, 00, 00))
    #print age
    assert age == -timedelta(15, 0)
示例#5
0
def test_metar_age2():
    class Taf():
        pass

    t = Taf()
    t.text = "010020Z akdsjfal dfkj"
    age = get_data_age(t, lambda: datetime(2013, 12, 31, 23, 59))
    #print age
    assert age == -timedelta(0, 60 * 21)
示例#6
0
def test_metar_age():
    class Taf():
        pass

    t = Taf()
    t.text = "312020Z akdsjfal dfkj"
    age = get_data_age(t, lambda: datetime(2013, 1, 1, 0, 20))
    #print age
    assert age == timedelta(0, 3600 * 4)
示例#7
0
def getpage(what, area):

    data, last_sync = fetchdata.getdata(geturl(what, area),
                                        country="raw",
                                        maxcacheage=timeout / 2,
                                        no_dev_comp_exception=True)
    #print "Fetched data, last sync",last_sync
    parser = lxml.html.HTMLParser()
    parser.feed(data)
    tree = parser.close()
    out = []
    for cand in tree.xpath(".//div"):
        elems = []
        for elem in cand.xpath(".//span"):
            if elem.text and elem.text.strip():
                elems.append(elem.text.strip())
        if len(elems) < 2: continue
        icao = elems[0].strip()
        if not re.match(r"[A-Z]{4}", icao):
            continue
        metar = " ".join(elems[1:]).strip()

        if what == 'TAF':
            out.append(Taf(icao, last_sync, metar))
        else:
            out.append(Metar(icao, last_sync, metar))
    #print "Parsed out:",out
    return out
示例#8
0
def get_taf(icao):
    try:
        return get_some("TAF", icao)
    except Exception:
        return Taf(icao, datetime.utcnow(), "")