def create_one_coin_history(name, symbol):
    start_date = '20110101'
    end_date = datetime.datetime.now().strftime('%Y%m%d')

    cursor = History.find({
        "symbol": symbol
    }).sort([("date", pymongo.DESCENDING)])
    try:
        recent_history = cursor.next()
    except StopIteration:
        recent_history = None

    if recent_history:
        date_now = datetime.datetime.now()
        recent_history_date = recent_history.date
        latest_history_date = (date_now - datetime.timedelta(days=1)).replace(
            hour=0, minute=0, second=0, microsecond=0)
        if recent_history_date < latest_history_date:
            start_date = recent_history_date + datetime.timedelta(days=1)
            start_date = start_date.strftime('%Y%m%d')
        else:
            return
    else:
        pass

    html = None
    # try:
    #     html = download_data(name, start_date, end_date)
    # except:
    #     html = download_data(name_back, start_date, end_date)
    # html = try_coin_history_by_name(name, start_date, end_date)
    # try_count = 0
    # while try_count < 3:
    #     try:
    #         html = download_data(name, start_date, end_date)
    #     except requests.exceptions.ProxyError:
    #         print('try request fail, count %s' % try_count)
    #         try_count = try_count + 1
    #         time.sleep(5)

    html = download_data(name, start_date, end_date)
    header, rows = extract_data(html)
    store_db(symbol, rows)
Beispiel #2
0
def count_history_symbol():
    from app.models import History
    tmp = len(History.find({}).distinct('symbol'))
    print(tmp)