Beispiel #1
0
def stocks_v2_detail(stock_code):
    code = stock_code.upper()
    stock = stocks_hits_collection.find_one(
        {'_highlightResult.tickerSymbolPrefix.value': code})
    if not stock:
        return abort(404)
    return jsonify(convert_id(stock))
Beispiel #2
0
def stocks_sheet_detail(stock_code):
    code = stock_code.upper()
    if request.method == 'POST':
        SHEET_SPIDER.get_stock_data(save=True, as_dict=True, force_update=True)
    stock = stocks_sheet_collection.find_one({'codigo': code},
                                             sort=[('data', pymongo.DESCENDING)
                                                   ])
    if not stock:
        return abort(404)
    return jsonify(convert_decimal_for_response(convert_id(stock)))
Beispiel #3
0
def stocks_list():
    if request.method != 'POST':
        stocks = [stock for stock in stocks_collection.find()]
    else:
        if not CRAWLER_EMAIL or not CRAWLER_PASSWORD:
            return jsonify({
                'error': True,
                'message': 'Credentials not set',
            })
        stocks = SPIDER.parse_stocks(save=True)
    return jsonify([add_url(convert_id(stock)) for stock in stocks])
Beispiel #4
0
def stocks_google_search_detail(stock_code):
    try:
        GoogleSearchCrawler(symbol=stock_code, db=db).get_stock_data()
    except Exception as e:
        logging.exception(e)
        return jsonify(
            dict(error=True,
                 message='Please check the code or try again later.')), 400
    return jsonify([
        convert_decimal_for_response(convert_id(stock)) for stock in
        google_search_collection.find({'symbol': stock_code.upper()})
    ])
Beispiel #5
0
def analysis_detail(stock_code):
    code = stock_code.upper()
    analysis = stocks_analysis_collection.find_one({
        'code': code,
    })
    if not analysis:
        stock = stocks_collection.find_one({'code': code})
        if not stock:
            return abort(404)
    if request.method == 'POST' or not analysis:
        if analysis:
            stocks_analysis_collection.delete_one(analysis)
        analysis = SPIDER.extract_all_fundamentalist_data(code, save=True)
    return jsonify(convert_id(analysis))
Beispiel #6
0
def stocks_sheet_list():
    if not SHEET_SPIDER.authenticated:
        return jsonify({
            'error': True,
            'message': 'Could not authenticate to Sheet Spider',
        })
    if request.method != 'POST':
        stocks = SHEET_SPIDER.get_stock_data(save=False, as_dict=True)
    else:
        logging.info('Fetching data from Google Sheet')
        stocks = SHEET_SPIDER.get_stock_data(save=True,
                                             as_dict=True,
                                             force_update=True)
    return jsonify(
        [convert_decimal_for_response(convert_id(stock)) for stock in stocks])
Beispiel #7
0
def tweet_list():
    return jsonify(
        [convert_id(tweet) for tweet in TWITTER_CRAWLER.get_all_tweets()])
Beispiel #8
0
def stocks_detail(stock_code):
    code = stock_code.upper()
    stock = stocks_collection.find_one({'code': code})
    if not stock:
        return abort(404)
    return jsonify(convert_id(stock))
Beispiel #9
0
def analysis_list():
    return jsonify([convert_id(a) for a in stocks_analysis_collection.find()])