本文整理汇总了Python中pattern.web.Twitter.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Twitter.clear方法的具体用法?Python Twitter.clear怎么用?Python Twitter.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pattern.web.Twitter
的用法示例。
在下文中一共展示了Twitter.clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TwitterStream
# 需要导入模块: from pattern.web import Twitter [as 别名]
# 或者: from pattern.web.Twitter import clear [as 别名]
def TwitterStream():
# Another way to mine Twitter is to set up a stream.
# A Twitter stream maintains an open connection to Twitter,
# and waits for data to pour in.
# Twitter.search() allows us to look at older tweets,
# Twitter.stream() gives us the most recent tweets.
for trend in Twitter().trends(cached=False):
print trend
# It might take a few seconds to set up the stream.
stream = Twitter().stream("i love", timeout=30)
pos_count=0
neg_count=0
#while True:
for i in range(50):
if(neg_count):
ratio = pos_count / neg_count
else:
ratio = 0
print str(pos_count) + " " + str(neg_count) + " " + str(ratio)+"%"
#print i
#print "+ " + str(pos_count)
#print "- " + str(neg_count)
#print "- - -"
# Poll Twitter to see if there are new tweets.
stream.update()
# The stream is a list of buffered tweets so far,
# with the latest tweet at the end of the list.
for tweet in reversed(stream):
print tweet.text
print tweet.language
sent = pol(tweet.text)
if(sent>0):
pos_count+=1
else:
neg_count+=1
# Clear the buffer every so often.
stream.clear()
# Wait awhile between polls.
time.sleep(1)
print "Final Twitter"
print pos_count
print neg_count
示例2: create_stream
# 需要导入模块: from pattern.web import Twitter [as 别名]
# 或者: from pattern.web.Twitter import clear [as 别名]
def create_stream(phrase, queue):
"""
Celery task that connects to the twitter stream and runs a loop, periodically
emitting tweet information to all connected clients.
"""
local = SocketIO(message_queue=queue)
stream = Twitter().stream(phrase, timeout=30)
for i in range(60):
stream.update()
for tweet in reversed(stream):
sentiment = classify_tweet(tweet)
x, y = vectorize_tweet(tweet)
local.emit('tweet', {'id': str(i),
'text': str(tweet.text.encode('ascii', 'ignore')),
'sentiment': sentiment,
'x': x,
'y': y})
stream.clear()
time.sleep(1)
return queue
示例3: Twitter
# 需要导入模块: from pattern.web import Twitter [as 别名]
# 或者: from pattern.web.Twitter import clear [as 别名]
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
import time
from pattern.web import Twitter
# Another way to mine Twitter is to set up a stream.
# A Twitter stream maintains an open connection to Twitter,
# and waits for data to pour in.
# Twitter.search() allows us to look at older tweets,
# Twitter.stream() gives us the most recent tweets.
# It might take a few seconds to set up the stream.
stream = Twitter().stream("I hate", timeout=30)
#while True:
for i in range(10):
print(i)
# Poll Twitter to see if there are new tweets.
stream.update()
# The stream is a list of buffered tweets so far,
# with the latest tweet at the end of the list.
for tweet in reversed(stream):
print(tweet.text)
print(tweet.language)
# Clear the buffer every so often.
stream.clear()
# Wait awhile between polls.
time.sleep(1)
示例4: Twitter
# 需要导入模块: from pattern.web import Twitter [as 别名]
# 或者: from pattern.web.Twitter import clear [as 别名]
from pattern.web import Twitter
import time
s = Twitter().stream('#snowday')
for i in range(25):
time.sleep(1)
s.update(bytes=1024)
print s[-1].text if s else ''
s.clear()