当前位置: 首页>>代码示例>>Python>>正文


Python Twitter.update方法代码示例

本文整理汇总了Python中pattern.web.Twitter.update方法的典型用法代码示例。如果您正苦于以下问题:Python Twitter.update方法的具体用法?Python Twitter.update怎么用?Python Twitter.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pattern.web.Twitter的用法示例。


在下文中一共展示了Twitter.update方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TwitterStream

# 需要导入模块: from pattern.web import Twitter [as 别名]
# 或者: from pattern.web.Twitter import update [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
开发者ID:MartinLidy,项目名称:LSTM-GA-StockTrader,代码行数:57,代码来源:05-twitter-stream.py

示例2: Pattern_Module_Twitter_Stream

# 需要导入模块: from pattern.web import Twitter [as 别名]
# 或者: from pattern.web.Twitter import update [as 别名]
def Pattern_Module_Twitter_Stream():

     # Start Stop Watch
    t1 = time.time()

    # Create a list to Store the Data
    List = Twitter().stream('#Fail')

    # For 10 Instances
    for second in range(10):
        # Get Stream Data
        value = List.update(bytes=1024)
        # Add Value to List if not Empty
        if len(value) == 0:
            # Pass
            continue
        else:
            # Storing Results
            List.append()
            # Print Tweet
            print('Tweet: %s') % (value.text)
            # Get Sentiment
            print('Sentiment Analysis of Tweet: %s') % (TextBlob(str(value.text),
                                                                 analyzer=NaiveBayesAnalyzer()).sentiment[0].upper())
        # Wait 3 Seconds between queries - Do not want to get blocked
        time.sleep(3)

    return time.time() - t1
开发者ID:AkiraKane,项目名称:CityUniversity2014,代码行数:30,代码来源:Sentiment_Harry_Potter_Review.py

示例3: create_stream

# 需要导入模块: from pattern.web import Twitter [as 别名]
# 或者: from pattern.web.Twitter import update [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
开发者ID:jdwittenauer,项目名称:twitter-viz-demo,代码行数:24,代码来源:app.py

示例4: Twitter

# 需要导入模块: from pattern.web import Twitter [as 别名]
# 或者: from pattern.web.Twitter import update [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)
开发者ID:clips,项目名称:pattern,代码行数:32,代码来源:05-twitter-stream.py

示例5: Twitter

# 需要导入模块: from pattern.web import Twitter [as 别名]
# 或者: from pattern.web.Twitter import update [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()
开发者ID:pagemedinaj,项目名称:vcu,代码行数:11,代码来源:HW1_twitter_stream.py


注:本文中的pattern.web.Twitter.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。