コード例 #1
0
def analyze_text_sentiment(tweet, company):

    # Instantiates a client
    client = language.LanguageServiceClient()

    document = types.Document(content=tweet.full_text,
                              type=enums.Document.Type.PLAIN_TEXT)

    # Detects the sentiment of the text and sends to stock price function
    sentiment = client.analyze_sentiment(document=document).document_sentiment
    if sentiment.score > .85 or sentiment.score < -.25:
        print('Text: {}'.format(tweet.full_text))
        print('Sentiment: {}, {}'.format(sentiment.score, sentiment.magnitude))
        print("Tweet Date: ", tweet.created_at)
        stock.export_tweet_stock_correlations(tweet.created_at, company)
コード例 #2
0
def test_stock_data1(capfd):
    date = datetime(2020, 10, 12, 2, 5, 46)
    response = "                  Open        High  ...  Dividends  Stock Splits\nDate                                ...                         \n2020-10-12  442.000000  445.850006  ...          0             0\n2020-10-12  441.385590  443.499786  ...          0             0\n2020-10-12  440.630005  443.700012  ...          0             0\n2020-10-12  443.290009  444.890015  ...          0             0\n2020-10-12  443.558807  448.440002  ...          0             0\n2020-10-12  448.140015  448.739990  ...          0             0\n2020-10-12  444.640015  444.700012  ...          0             0\n\n[7 rows x 7 columns]\n"
    stock.export_tweet_stock_correlations(date, 'TSLA')
    out, err = capfd.readouterr()
    assert out == response