Exemple #1
0
def QtDownMulti(codes):
    qcode = ''
    for i in range(0, len(codes)):
        qcode += sat_util.codeAddPrefix(codes[i]) + ','
    durl = qurl + 'r=' + str(random.random()) + '&q=' + qcode
    if (debug): print(durl)
    s = sat_down.GetMultiRtPriceByURL(durl)
    if (debug): print(s, len(s))
    return QtParseMulti(s)
Exemple #2
0
def YahooDownHistory(code, dtEnd, dtStart, f):
    code = sat_util.codeAddSuffix(code)
    qcode = code[0:6] + '.' + code[6:]
    insCode = qcode[:6]

    yEnd = int(dtEnd.year)
    mEnd = int(dtEnd.month)
    dEnd = int(dtEnd.day)
    yStart = int(dtStart.year)
    mStart = int(dtStart.month)
    dStart = int(dtStart.day)

    qyEnd = ''
    qmEnd = ''
    qdEnd = ''
    qyStart = ''
    qmStart = ''
    qdStart = ''

    #倒序查询
    for i in range(yEnd, yStart - 1, -1):
        if i == yEnd and i == yStart:
            qmEnd = mEndPre + str(mEnd - 1)
            qdEnd = dEndPre + str(dEnd)
            qmStart = mStartPre + str(mStart - 1)
            qdStart = dStartPre + str(dStart)
        elif i == yEnd and i > yStart:
            qmEnd = mEndPre + str(mEnd - 1)
            qdEnd = dEndPre + str(dEnd)
            qmStart = mStartPre + '0'
            qdStart = dStartPre + '1'
        elif i < yEnd and i > yStart:
            qmEnd = mEndPre + '11'
            qdEnd = dEndPre + '31'
            qmStart = mStartPre + '0'
            qdStart = dStartPre + '1'

        elif i < yEnd and i == yStart:
            qmEnd = mEndPre + '11'
            qdEnd = dEndPre + '31'
            qmStart = mStartPre + str(mStart - 1)
            qdStart = dStartPre + str(dStart)
        else:
            print("date error, give up this query")
            break

        qyEnd = yEndPre + str(i)
        qyStart = yStartPre + str(i)
        qDate = qyEnd + qmEnd + qdEnd + qyStart + qmStart + qdStart
        durl = qurlHis + qcodePre + qcode + qDate
        if (debug): print(durl)
        s = sat_down.GetMultiRtPriceByURL(durl)
        if s == None or s == '':
            print("yahoo open url failed ", durl)
            continue
        wStr = ''
        for i in range(1, len(s)):
            strUTF8 = sat_util.ToUTF8(s[i])
            slist = insCode + ',' + strUTF8
            wStr += slist
        f.writelines(wStr)
Exemple #3
0
def SinaDownHistory(code, dtEnd, dtStart, f):
    qcode=sat_util.codeAddPrefix(code)
    insCode=qcode[2:]
   
    yEnd = int(dtEnd.year)
    mEnd = int(dtEnd.month)
    dEnd = int(dtEnd.day)
    yStart=int(dtStart.year)
    mStart = int(dtStart.month)
    dStart = int(dtStart.day) 

    qyEnd = ''
    qmEnd = ''
    qdEnd = ''
    qyStart = ''
    qmStart = ''
    qdStart = ''
    
    for i in range(yStart, yEnd+1):
        if i == yEnd and i == yStart:
            qmEnd = str(mEnd)
            qdEnd = str(dEnd)
            qmStart = str(mStart)
            qdStart = str(dStart)
        elif i == yEnd and i > yStart:
            qmEnd = str(mEnd)
            qdEnd = str(dEnd)
            qmStart = '01'
            qdStart = '01'              
        elif i < yEnd and i > yStart:
            qmEnd = '12'
            qdEnd = '31'
            qmStart = '01'
            qdStart = '01'       

        elif i < yEnd and i == yStart:
            qmEnd = '12'
            qdEnd = '31'
            qmStart = str(mStart)
            qdStart = str(dStart)
        else:
            print("date error, give up this query")
            break
        
        qyEnd = str(i)
        qyStart = qyEnd
        if len(qmEnd) < 2:
            qmEnd = '0'+qmEnd
        if len(qdEnd) < 2:
            qdEnd = '0' + qdEnd
        if len(qmStart) < 2:
            qmStart = '0'+qmStart
        if len(qdStart) < 2:
            qdStart = '0' + qdStart
        
        qDate = qdtEndPre+qyEnd+qmEnd+qdEnd+qdtStartPre+qyStart+qmStart+qdStart
        durl=qurlHis+qrandomPre+str(random.randint(0,10000))+qcodePre+qcode+qDate+qtype
        if (debug): print(durl)
        s = sat_down.GetMultiRtPriceByURL(durl)
        if s == None or s == '':
            #print("sn_down open url failed ", durl)
            continue
        wStr=''
        for i in range(0, len(s)):
            strUTF8=sat_util.ToUTF8(s[i])
            slist=insCode+','+strUTF8
            wStr += slist
        if wStr != '':
            f.writelines(wStr)