本文整理汇总了Python中twitter.Twitter.get_tweet_text方法的典型用法代码示例。如果您正苦于以下问题:Python Twitter.get_tweet_text方法的具体用法?Python Twitter.get_tweet_text怎么用?Python Twitter.get_tweet_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twitter.Twitter
的用法示例。
在下文中一共展示了Twitter.get_tweet_text方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Analysis
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import get_tweet_text [as 别名]
if __name__ == "__main__":
analysis = Analysis(logs_to_cloud=False)
trading = Trading(logs_to_cloud=False)
twitter = Twitter(logs_to_cloud=False)
# Look up the metadata for the tweets.
tweets = twitter.get_tweets(SINCE_TWEET_ID)
events = []
for tweet in tqdm(tweets):
event = {}
timestamp_str = tweet["created_at"]
timestamp = trading.utc_to_market_time(datetime.strptime(
timestamp_str, "%a %b %d %H:%M:%S +0000 %Y"))
text = twitter.get_tweet_text(tweet)
event["timestamp"] = timestamp
event["text"] = text
event["link"] = twitter.get_tweet_link(tweet)
# Extract the companies.
companies = analysis.find_companies(tweet)
strategies = []
for company in companies:
# What would have been the strategy?
market_status = get_market_status(timestamp)
strategy = trading.get_strategy(company, market_status)
# What was the price at tweet and at EOD?
示例2: __init__
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import get_tweet_text [as 别名]
#.........这里部分代码省略.........
(name, mid))
continue
self.logs.debug("Found company data: %s" % company_data)
for company in company_data:
# Extract and add a sentiment score.
sentiment = self.get_sentiment(text)
self.logs.debug("Using sentiment for company: %s %s" %
(sentiment, company))
company["sentiment"] = sentiment
# Add the company to the list unless we already have the same
# ticker.
tickers = [existing["ticker"] for existing in companies]
if not company["ticker"] in tickers:
companies.append(company)
else:
self.logs.warn(
"Skipping company with duplicate ticker: %s" % company)
return companies
def get_expanded_text(self, tweet):
"""Retrieves the text from a tweet with any @mentions expanded to
their full names.
"""
if not tweet:
self.logs.warn("No tweet to expand text.")
return None
try:
text = self.twitter.get_tweet_text(tweet)
mentions = tweet["entities"]["user_mentions"]
except KeyError:
self.logs.error("Malformed tweet: %s" % tweet)
return None
if not text:
self.logs.warn("Empty text.")
return None
if not mentions:
self.logs.debug("No mentions.")
return text
self.logs.debug("Using mentions: %s" % mentions)
for mention in mentions:
try:
screen_name = "@%s" % mention["screen_name"]
name = mention["name"]
except KeyError:
self.logs.warn("Malformed mention: %s" % mention)
continue
self.logs.debug("Expanding mention: %s %s" % (screen_name, name))
pattern = compile(screen_name, IGNORECASE)
text = pattern.sub(name, text)
return text
def make_wikidata_request(self, query):
"""Makes a request to the Wikidata SPARQL API."""
query_url = WIKIDATA_QUERY_URL % quote_plus(query)