Example #1
0
def GetIndex(id, year_from, year_to):
    indexs=[]
    for year in range(year_from, year_to + 1):
        for season in range(1, 5):
            content = URL.request(__index_url_date.format(str(id),str(year),str(season)))
            search_begin = content.find('<table class=')
            if search_begin == -1 :
                continue
            search_begin = content.find('<tr class=\'\'>', search_begin)
            search_end = content.find('</table>', search_begin)
            content = content[search_begin:search_end]
            search_end = 0
            index = 0
            while True :
                search_begin = content.find('<tr class=', search_end)
                if search_begin == -1 :
                    break
                record=[]
                for i in range(1, 10):
                    search_begin = content.find('<td>', search_end)
                    search_end = content.find('</td>', search_begin + 4)
                    value = content[search_begin + 4:search_end]
                    value = value.replace(',', '')
                    record.append(value)
                indexs.append(record)
    indexs.sort(key = lambda x:x[0])
                                       
    return indexs
Example #2
0
def UpdateCodes():
    db = SQL.sql(__index_db)
    db.set("CREATE TABLE IF NOT EXISTS {}(code char(6) unique, name char(36))".format(__index_table))
    for index in range(__begin_index, __end_index):
        index_str='{:0>6}'.format(index)
        content = URL.request(__index_url.format(index_str))
        index_begin = content.find('var STOCKSYMBOL = \'')
        if index_begin == -1:
            continue
        index_end = content.find('\'', index_begin + 19)
        index_code = content[index_begin + 19:index_end]
        index_begin = content.find('var STOCKNAME = \'')
        if index_begin == -1:
            continue
        index_end = content.find('\'', index_begin + 17)
        index_name = content[index_begin + 17:index_end]
        LOG.info ('%s %s' %(index_code, index_name))
        __indexs.append([index_code, index_name])
        db.set("REPLACE INTO {} VALUES(\'{}\',\'{}\')".format(__index_table, index_code, index_name))
    db.close()