Example #1
0
def analysis_lowest(dep_code, arr_code):
    result_map = ResultMap()
    db = DB('atp', 'atp', 'atp')
    conn = db.getConn()
    cursor = conn.cursor()
    cursor.execute("select * from FLIGHT_LOWEST_PRICE_INFO where dep_code='%s' and arr_code='%s'" % (dep_code, arr_code))
    # print cursor.rowcount
    while True:
        result = cursor.fetchone()
        # print result
        if not result:
            break

        query_date = result[1]
        dep_date = result[5]
        price = result[11]
        result_map.add((dep_date - query_date).days, price)

    print 'FROM:%s    TO:%s' % (dep_code, arr_code)
    result_map.analysis()
Example #2
0
def analysis_lowest(dep_code, arr_code):
    result_map = ResultMap()
    db = DB('atp', 'atp', 'atp')
    conn = db.getConn()
    cursor = conn.cursor()
    cursor.execute(
        "select * from FLIGHT_LOWEST_PRICE_INFO where dep_code='%s' and arr_code='%s'"
        % (dep_code, arr_code))
    # print cursor.rowcount
    while True:
        result = cursor.fetchone()
        # print result
        if not result:
            break

        query_date = result[1]
        dep_date = result[5]
        price = result[11]
        result_map.add((dep_date - query_date).days, price)

    print 'FROM:%s    TO:%s' % (dep_code, arr_code)
    result_map.analysis()
Example #3
0
def workQunarLowest():
    db = DB('atp', 'atp', 'atp')
    q = QunarLowest(db.getConn(), getAllAirport(), RECENT_DAY_RANGE)
    q.crawlAllAirlinesWithRetry(RETRY_TIMES)
Example #4
0
        L.info("{} -> {}", depInfo[0], arrInfo[0])
        bs = BeautifulSoup(r.text, 'lxml-xml')
        resultData = bs.find('ResultData')
        for airline in resultData.children:
            if airline.name == 'lowestPrice':
                d = airline.attrs
                allAttrs = ('date', 'code', 'depTime', 'arrTime', 'carrier',
                            'vendorName', 'price')
                attrOK = True
                for attr in allAttrs:
                    if attr not in d:
                        attrOK = False
                        break
                if not attrOK:
                    continue

                info = FlightLowestPriceInfo(queryDate, queryTime, depInfo[0],
                                             arrInfo[0],
                                             [d[x] for x in allAttrs])
                #                 print info.asRec()
                self.dbHandle.insertOneRec(info)

        return ER_SUCC


if __name__ == '__main__':
    db = DB('atp', 'atp', 'atp')
    q = QunarLowest(db.getConn(), getAllAirport(), 60)
    q.crawlAllAirlinesWithRetry(5)
Example #5
0
from atp import qunar
import time
from atp.dbc import DB
from atp.flight_info import FlightInfoHandler, FlightInfo
from atp.logger import L
from atp.errcode import ER_CONN_DB_FAILED, ER_SUCC

g_db = DB('atp', 'atp', 'atp')

def processDataByFile(fileName, depDate, depCode, arrCode):
    curDateTime = time.localtime(time.time())
    
    queryDate = time.strftime('%Y-%m-%d', curDateTime)
    queryTime = time.strftime('%H:%M:%S', curDateTime)
    
    retList = qunar.analysis(fileName)
    if not retList:
        L.error("Not found airline")

    global g_db
    conn = g_db.getConn()
    if not conn:
        L.error("connect db failed.")
        return ER_CONN_DB_FAILED
    
    handler = FlightInfoHandler(conn)
    
    for rec in retList:
        flightInfo = FlightInfo(queryDate, queryTime, depDate, depCode, arrCode, rec)
        handler.insertOneRec(flightInfo)
        
Example #6
0
def workQunarLowest():
    db = DB("atp", "atp", "atp")
    q = QunarLowest(db.getConn(), getAllAirport(), RECENT_DAY_RANGE)
    q.crawlAllAirlinesWithRetry(RETRY_TIMES)
Example #7
0
            
        if r.status_code != 200:
            L.error("{} -> {} failed, url={}", depInfo[0], arrInfo[0], url)
            return ER_RESPONSE_FAIL
        
        L.info("{} -> {}", depInfo[0], arrInfo[0])
        bs = BeautifulSoup(r.text, 'lxml-xml')
        resultData = bs.find('ResultData')
        for airline in resultData.children:
            if airline.name == 'lowestPrice':
                d = airline.attrs
                allAttrs = ('date', 'code', 'depTime', 'arrTime', 'carrier', 'vendorName', 'price')
                attrOK = True
                for attr in allAttrs:
                    if attr not in d:
                        attrOK = False
                        break
                if not attrOK:
                    continue        
                    
                info = FlightLowestPriceInfo(queryDate, queryTime, depInfo[0], arrInfo[0], [d[x] for x in allAttrs])
#                 print info.asRec()
                self.dbHandle.insertOneRec(info)
                
        return ER_SUCC
                
if __name__ == '__main__':
    db = DB('atp', 'atp', 'atp')
    q = QunarLowest(db.getConn(), getAllAirport(), 60)
    q.crawlAllAirlinesWithRetry(5)