Ejemplo n.º 1
0
def index(logis_id):
    """
    圆通
    var reg = /^[A-Za-z0-9]{10,12}$/;
          var reg1 = /^88[A-Za-z0-9]{16}$/;
    """
    
    if not (re.match(r'^[A-Za-z0-9]{10,12}$', logis_id) or re.match(r'^88[A-Za-z0-9]{16}$', logis_id)):
        return jsonify(msg="logis id invalid")
    #firefox_profile = webdriver.FirefoxProfile()
    #firefox_profile.set_preference('permissions.default.stylesheet', 2)
    #firefox_profile.set_preference('permissions.default.image', 2)
    #firefox_profile.set_preference("javascript.enabled", False)
    #driver = webdriver.Firefox(firefox_profile=firefox_profile)
    #driver = webdriver.Firefox()
    #dirver = webdriver.Chrome()
    # TODO 
    if platform.system() == 'Darwin':
        driver = webdriver.PhantomJS('./vendor/phantomjs-macosx/bin/phantomjs')
    elif platform.system() == 'Linux':
        driver = webdriver.PhantomJS('./vendor/phantomjs-linux-x86_64/bin/phantomjs')
    else:
        driver = webdriver.PhantomJS('./vendor/phantomjs-linux-x86_64/bin/phantomjs')
            
    driver.get("http://www.yto.net.cn/gw/index/index.html")
    driver.find_element_by_id('textarea_track').send_keys(logis_id)
    driver.find_element_by_css_selector('a.a-btn').click()
    windows = driver.window_handles
    driver.switch_to_window(windows[1])
    result_dom = driver.page_source
    driver.close()
    driver.switch_to_window(windows[0])
    driver.close()
    
    soup = BeautifulSoup(result_dom, 'lxml')
    status_dom = soup.find("div", class_="trace-ico")
    if not status_dom:
        return info_not_found()
    
    #route_dom = soup.find("div", class_"trace-table").find
    route_dom = soup.select('.trace-table table tr')
    status = status_dom.span.extract().get_text()
    
    routes = []
    
    for item in route_dom:
        routes.append({
            "scanTime": item.find("td", class_="time" ).get_text(strip=True),
            "remark": item.find("td", class_="data" ).get_text(strip=True)
        })
        
    routes = utils.fixYTORoute(routes)
            
    return jsonify(status=status, routes=routes, id=logis_id)
Ejemplo n.º 2
0
def index(logis_id):
    """
    中通
    """
    html_doc = requests.get("http://www.zto.com/GuestService/Bill?model.TxtBill=" + logis_id)
    soup = BeautifulSoup(html_doc.text, 'lxml')
    status_dom = soup.find(id="Status")
    
    if not status_dom:
        return info_not_found()
    else:
        status = status_dom.get("value")
        duration = soup.find("div", class_="text3").get_text()
        routes = []
        for li in soup.find_all('li', class_="pr"):
            routes.append({
                'remark': li.find("div").get_text(),
                'scanTime': utils.convert_time(li.find("div", class_="time").get_text(strip=True))
            })
        
        return jsonify(status=status, duration=duration, routes=routes, id=logis_id)
Ejemplo n.º 3
0
def index(logis_id):
    """
    申通
    """
    html_doc = requests.get("http://q1.sto.cn/chaxun/result?express_no=" + logis_id)
    soup = BeautifulSoup(html_doc.text, 'lxml')
    
    status = soup.find("ul", class_="info-list").find(class_="tip_info_bg").get_text()
    route_dom = soup.find("ul", class_="result-list-info")
    
    if not route_dom:
        return info_not_found()
        
    routes = []
    for item in route_dom.children:
        routes.append({
            "scanTime": utils.convert_time(item.find("div", class_="fl-left").get_text(strip=True)),
            "remark": item.find("div", class_="fl-right").get_text(strip=True)
        })
        
    return jsonify(status=status, routes=routes, id=logis_id)
Ejemplo n.º 4
0
def index(logis_id):
    """
    returns "[]" if results was null
    """
    r = requests.get('http://www.sf-express.com/sf-service-web/service/bills/' + logis_id + '/routes?app=bill&lang=sc&region=cn&translate=')
    resp_text = re.sub(r'<.+?>', '', r.text)
    if resp_text == "[]":
        return info_not_found()
    
    resp = r.json()[0]
    
    routes = []
    ## filter unnecessary content
    for rou in resp['routes']:
        tmp = {}
        if 'remark' in rou:
            tmp['remark'] = re.sub(r'<.+?>', '', rou['remark'])
        if 'scanDateTime' in rou:
            tmp['scanTime'] = utils.convert_time(rou['scanDateTime']) 
        routes.append(tmp)
            
    return jsonify(status=resp['expressState'], routes=routes, id=resp['id'])