Esempio n. 1
0
def fetch_events(id):
    object = session.query(Object).filter_by(oid=id).first()
    if object:
        page = urllib2.urlopen("http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI="+id)
        items = correio.parse(page.read())

        if len(items) == len(object.events): return
        
        if len(object.events) != 0:
            items = items[len(object.events):]
            
        for item in items:
            event = Event()
            event.datetime = parser.parse(item["datetime"])
            event.local = item["local"]
            event.activity = item["activity"]
            event.oid = object.oid
            session.add(event)
            if item["activity"] == "Entrega Efetuada": object.delivered = True
    session.commit()
    return items
Esempio n. 2
0
def track(id):
    page = urllib2.urlopen("http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI="+id)
    events = correio.parse(page.read())
    return render_template('track.html', events=events)