Пример #1
0
    def get_stream(self):
        queue_module = self.get_config_default('tweets-client', 'track-module',
                                               'tweetsclient.config_track')
        queue_class = self.get_config_default('tweets-client', 'track-class',
                                              'ConfigTrackPlugin')
        log.debug("Loading track plugin: {module} - {klass}",
                  module=queue_module,
                  klass=queue_class)

        pluginClass = self.load_plugin(queue_module, queue_class)
        self.track = pluginClass()
        #self.track = tweetsclient.MySQLTrackPlugin({'verbose': self.verbose})
        # self.track = tweetsclient.ConfigTrackPlugin({'verbose': self.verbose})
        stream_type = self.track.get_type()
        log.debug("Initializing a {0} stream of tweets.", stream_type)
        track_items = self.track.get_items()
        log.debug(str(track_items))
        stream = None
        if stream_type == 'users':
            stream = tweetstream.FilterStream(self.user, self.passwd,
                                              track_items)
        elif stream_type == 'words':
            stream = tweetstream.TrackStream(self.user, self.passwd,
                                             track_items)
        else:
            stream = tweetstream.TweetStream(self.user, self.passwd)
        return stream
Пример #2
0
    def start(self):
        with tweetstream.FilterStream(self.username,
                                      self.password,
                                      track=self.hashtags,
                                      follow=self.users_to_follow) as stream:
            self.start_time = localtime()  #TODO Note the start time.
            restart_asap = False
            for tweet in stream:
                if tweet and tweet.get("text", False):
                    #print tweet["text"]
                    #send tweets to modules.
                    for module in self.my_modules:
                        module_return = module.use_tweet(tweet)
                        #print module.name() + " using " + tweet["text"]

                        if "users" in module_return:
                            self.users_to_follow.extend(module_return["users"])
                        restart_asap = module_return.get("restart", False)
                    if (mktime(gmtime()) % 300
                            == 0) and self.time != mktime(gmtime(
                            )):  #every five minutes, get a new trending topics
                        self.time = mktime(gmtime())
                        self.getHTML()
                    else:
                        #print "Received tweet: " + tweet["text"]
                        pass
                    if restart_asap:
                        break  #TODO: (check if this really just boosts us out to a new tweetstream.Filterstream thing.
                        self.start(
                        )  #will it work for restarting the loop (with new users to track or whatever) to just do this?
Пример #3
0
    def run(self):
        config = {
            'user': '******',
            'passwd': 'RDKC1VlNyLSg',
            'host': '127.7.115.1',
            'db': 'sentistock'
        }
        self.cnx = MySQLdb.connect(**config)

        if (self.Company == "$BAC"):
            self.usr = "******"
            self.pss = "blublu"
            self.tbl = "bac"
        elif (self.Company == "$AAPL"):
            self.usr = "******"
            self.pss = "rohit123rv"
            self.tbl = "aapl"
        elif (self.Company == "$GOOG"):
            self.usr = "******"
            self.pss = "rohit123rv"
            self.tbl = "goog"
        while True:
            try:
                Retweet = ['RT']
                if (self.cnx == None):
                    logging.info("Trying to connect")
                    self.cnx = MySQLdb.connect(**config)
                cur = self.cnx.cursor()
                add_tweet = "INSERT ignore INTO tweets_%s (tweet,time)VALUES (%s,%s)"
                with tweetstream.FilterStream(self.usr,
                                              self.pss,
                                              track=self.words) as stream:
                    logging.info(
                        "Connected To Twitter Stream For %s Successfully." %
                        self.Company)
                    for tweet in stream:
                        if 'text' not in tweet: continue
                        tweet_data = re.sub(r"'|\"", "",
                                            tweet['text'].encode('UTF-8'))
                        if any(word in tweet_data for word in Retweet):
                            continue
                        new_tweet_data = re.sub(r"'|\"", "", tweet_data)
                        d = datetime.datetime.today()
                        america = timezone('America/New_York')
                        india = timezone('Asia/Kolkata')
                        dd = america.localize(d)
                        dd = dd.astimezone(india)
                        print tweet_data
                        cur.execute(add_tweet %
                                    (self.tbl,
                                     ("'" + new_tweet_data + "'"), "'" +
                                     dd.strftime('%Y-%m-%d %H:%M:%S') + "'"))
                        logging.info("Tweet Added For %s." % self.Company)
                        self.cnx.commit()
            except Exception as e:
                logging.info(
                    "Connection To Twitter For %s Has Encountered An Error, Reconnecting.."
                    % self.Company + " " + str(e))
                sleep(60)
def twitterStream(watchlist):
    """Watch Twitter RealTime Stream for WatchList Elements"""
    with tweetstream.FilterStream("Alien1Security",
                                  "Tang0!23123",
                                  track=watchlist) as stream:
        for tweet in stream:
            for element in tweet:
                print(element)
Пример #5
0
def twitterStream(follow_ids):
    """Watch Twitter RealTime Stream for WatchList Elements"""
    with tweetstream.FilterStream("conmon43wazoo", "ninja789", follow=follow_ids) as stream:
        for tweet in stream:
            try:
                src_lang = tweet['user']['lang']
                if src_lang != "en":
                    if 'web' in tweet['source']:
                        source_platform = tweet['source']
                    else:
                        source_platform = tweet['source'].split('"')[4].split('>')[1].split('<')[0]
                    translatedTweet = google_trans(tweet['text'], src_lang)
                    tweet_time = tweet['created_at']
                    pattern = '%a %b %d %H:%M:%S +0000 %Y'
                    creation_time = int(time.mktime(time.strptime(tweet_time, pattern))) * 1000
                    geo_location = tweet['geo']
                    coordinates = tweet['coordinates']
                    twitter_id = str(tweet['user']['id'])
                    twitter_screen_name = tweet['user']['screen_name']
                    twitter_proper_name = tweet['user']['name']
                    reply_to_id = tweet['in_reply_to_user_id_str']
                    reply_to_screen_name = tweet['in_reply_to_screen_name']
                    source_lang = tweet['user']['lang']
                    translated_tweet = translatedTweet['translations'][0]['translatedText']
                    keys = ["Ctime", "Geo", "Coordinates", "Platform", "TwitterID", "ScreenName", "ProperName",
                            "ReplyToID", "ReplyToScreenName", "SourceLang", "Tweet"]
                    values = [creation_time, geo_location, coordinates, source_platform, twitter_id, twitter_screen_name,
                              twitter_proper_name, reply_to_id, reply_to_screen_name,
                              source_lang, translated_tweet]
                    twit_dict = dict(zip(keys, values))
                    yield twit_dict
                else:
                    if 'web' in tweet['source']:
                        source_platform = tweet['source']
                    else:
                        source_platform = tweet['source'].split('"')[4].split('>')[1].split('<')[0]
                    tweet_time = tweet['created_at']
                    pattern = '%a %b %d %H:%M:%S +0000 %Y'
                    creation_time = int(time.mktime(time.strptime(tweet_time, pattern))) * 1000
                    geo_location = tweet['geo']
                    coordinates = tweet['coordinates']
                    twitter_id = str(tweet['user']['id'])
                    twitter_screen_name = tweet['user']['screen_name']
                    twitter_proper_name = tweet['user']['name']
                    reply_to_id = tweet['in_reply_to_user_id_str']
                    reply_to_screen_name = tweet['in_reply_to_screen_name']
                    source_lang = tweet['user']['lang']
                    tweet_en = tweet['text']
                    keys = ["Ctime", "Geo", "Coordinates", "Platform", "TwitterID", "ScreenName", "ProperName",
                        "ReplyToID", "ReplyToScreenName", "SourceLang", "Tweet"]
                    values = [creation_time, geo_location, coordinates, source_platform, twitter_id, twitter_screen_name,
                          twitter_proper_name, reply_to_id, reply_to_screen_name,
                          source_lang, tweet_en]
                    twit_dict = dict(zip(keys, values))
                    yield twit_dict
            except KeyError:
                yield KeyError
Пример #6
0
def twitterStream():
    """Watch Twitter RealTime Stream for WatchList Elements"""
    words = [
        "Top Secret", "Secret Service", "Classified", "Targeted",
        "Assassination", "Kill Program", "NSA", "wire", "CIA", "FBI", "DEA",
        "DOJ"
    ]
    with tweetstream.FilterStream(
            "JollyJimBob",
            "delta0!23123",
            track=words,
    ) as stream:
        try:
            for tweet in stream:
                if 'user' in tweet:
                    created_at = tweet['created_at']
                    mentions = tweet['entities']['user_mentions']
                    id_string = tweet['user']['id_str']
                    screen_name = tweet['user']['screen_name']
                    tweet_text = tweet['text']
                    try:
                        if len(mentions) > 0:
                            for record in mentions:
                                user_id = record['id_str']
                                user_name = record['screen_name']
                                user_mentions = "mentions"
                                keys = [
                                    'Date', 'ID', 'Name', 'Tweet', 'Mention',
                                    'mUserId', 'mUserName'
                                ]
                                values = [
                                    created_at, id_string, screen_name,
                                    tweet_text, user_mentions, user_id,
                                    user_name
                                ]
                                mentions_dict = dict(zip(keys, values))
                                ordered_mentions_dict = OrderedDict(
                                    sorted(mentions_dict.items(),
                                           key=lambda by_key: by_key[0]))
                                yield ordered_mentions_dict
                        else:
                            no_mentions = "no_mentions"
                            keys = ['Date', 'ID', 'Name', 'Tweet', 'Mention']
                            values = [
                                created_at, id_string, screen_name, tweet_text,
                                no_mentions
                            ]
                            no_mentions_dict = dict(zip(keys, values))
                            ordered_no_mentions_dict = OrderedDict(
                                sorted(no_mentions_dict.items(),
                                       key=lambda by_key: by_key[0]))
                            yield ordered_no_mentions_dict
                    except KeyError:
                        raise KeyError
        except ConnectionError:
            raise ConnectionError
Пример #7
0
def twitterStream(user_name):
    """Watch Twitter RealTime Stream for WatchList Elements"""
    follow_ids = list_following(user_name)
    with tweetstream.FilterStream("JollyJimBob", "delta0!23123", follow=follow_ids,) as stream:
        try:
            for tweet in stream:
                try:
                    if 'web' in tweet['source']:
                        source_platform = tweet['source']
                    else:
                        source_platform = tweet['source'].split('"')[4].split('>')[1].split('<')[0]
                except KeyError:
                    continue
                if tweet['coordinates'] is None:
                    coordinates = None
                else:
                    coordinates = tweet['coordinates']['coordinates']
                if 'user' in tweet:
                    created_at = tweet['created_at']
                    mentions = tweet['entities']['user_mentions']
                    id_string = tweet['user']['id_str']
                    screen_name = tweet['user']['screen_name']
                    tweet_text = tweet['text']
                    in_reply_to_id = tweet['in_reply_to_user_id_str']
                    in_reply_to_name = tweet['in_reply_to_screen_name']
                    re_tweet_count = tweet['retweet_count']
                    try:
                        if len(mentions) > 0:
                            for record in mentions:
                                user_id = record['id_str']
                                user_name = record['screen_name']
                                user_mentions = "mentions"
                                keys = ['Date', 'ID', 'Platform', 'Coord', 'Name', 'InReplyToId', 'InReplyToName',
                                        'ReTweetCount', 'Tweet', 'Mention', 'mUserId', 'mUserName']
                                values = [created_at, id_string, source_platform, coordinates,
                                          screen_name, in_reply_to_id, in_reply_to_name, re_tweet_count, tweet_text,
                                          user_mentions, user_id, user_name]
                                mentions_dict = dict(zip(keys, values))
                                ordered_mentions_dict = OrderedDict(sorted(mentions_dict.items(),
                                                                           key=lambda by_key: by_key[0]))
                                yield ordered_mentions_dict
                        else:
                            no_mentions = "no_mentions"
                            keys = ['Date', 'ID', 'Platform', 'Coord', 'Name', 'InReplyToId',
                                    'InReplyToName', 'ReTweetCount', 'Tweet', 'Mention']
                            values = [created_at, id_string, source_platform, coordinates,
                                      screen_name, in_reply_to_id, in_reply_to_name,
                                      re_tweet_count, tweet_text, no_mentions]
                            no_mentions_dict = dict(zip(keys, values))
                            ordered_no_mentions_dict = OrderedDict(sorted(no_mentions_dict.items(),
                                                                          key=lambda by_key: by_key[0]))
                            yield ordered_no_mentions_dict
                    except KeyError:
                        raise KeyError
        except ConnectionError:
            raise ConnectionError
 def run(self):
     with tweetstream.FilterStream(self.twitterUser,
                                   self.twitterPass,
                                   track=self.words) as stream:
         for tweet in stream:
             if tweet.get('text'):
                 if 'rt' in tweet.get('text').lower():
                     continue
                 #print tweet
                 self.queue.put(tweet)
                 self.count += 1
                 if (self.count >= self.limit):
                     break
Пример #9
0
def twitterStream():
    """Watch Twitter RealTime Stream for WatchList Elements"""
    words = ["AnonymousIRC", "hackers", "NullCrew", "firefox"]
    with tweetstream.FilterStream(
            "JollyJimBob",
            "ninja789",
            track=words,
    ) as stream:
        try:
            for tweet in stream:
                if 'user' in tweet:
                    created_at = tweet['created_at']
                    mentions = tweet['entities']['user_mentions']
                    id_string = tweet['user']['id_str']
                    screen_name = tweet['user']['screen_name']
                    tweet_text = tweet['text']
                    try:
                        if len(mentions) > 0:
                            for record in mentions:
                                user_id = record['id_str']
                                user_name = record['screen_name']
                                user_mentions = "no_mentions"
                                keys = [
                                    'Date', 'ID', 'Name', 'Tweet', 'Mention',
                                    'UserId', 'UserName'
                                ]
                                values = [
                                    created_at, id_string, screen_name,
                                    tweet_text, user_mentions, user_id,
                                    user_name
                                ]
                                mentions_dict = dict(zip(keys, values))
                                yield write_mongo(mentions_dict)
                        else:
                            no_mentions = "no_mentions"
                            keys = ['Data', 'ID', 'Name', 'Tweet', 'Mention']
                            values = [
                                created_at, id_string, screen_name, tweet_text,
                                no_mentions
                            ]
                            no_mentions_dict = dict(zip(keys, values))
                            print no_mentions_dict
                            yield write_mongo(no_mentions_dict)
                    except KeyError:
                        raise KeyError
        except OSError:
            pass
Пример #10
0
def main():
    ser = serial.Serial(SERIAL_PORT, SERIAL_SPEED)
    ser.write("2\n")  #move the servo two times

    while True:
        with tweetstream.FilterStream(USER, PASSWORD, track=WORDS) as stream:
            print "CONECTADO!"

            for tweet in stream:
                if ser.isOpen():
                    ser.write("1\n")
                #print tweet
                print ">>> %s: %s" % (tweet["user"]["screen_name"],
                                      tweet["text"])
                print ""
            print "\n\n\n"

        print "reconnecting..."
    print "END."
Пример #11
0
def do_stream():
    words = ['outsidelands', 'outside lands']
    with tweetstream.FilterStream(credentials['username'],
                                  credentials['password'],
                                  track=words) as stream:

        print "Done."
        counter = 0
        print "Starting loop-di-loop..."
        for tweet in stream:
            print "Got tweet..."
            if tweet.get('text'):
                print "It's an actual tweet: %s" % (tweet.get('text'))

                counter += 1

                user = tweet['user']
                u = Session.query(User).filter(User.id == user['id']).first()
                if not u:
                    u = User(id=user['id'],
                             screen_name=user['screen_name'],
                             followers_count=user['followers_count'])

                t = Tweet(id=tweet['id'],
                          text=tweet['text'],
                          user_id=u.id,
                          favorite_count=tweet['favorite_count'],
                          created_at=parser.parse(tweet['created_at']),
                          retweet_count=tweet['retweet_count'],
                          truncated=tweet['truncated'],
                          coordinates=json.dumps(tweet['coordinates']),
                          place=json.dumps(tweet['place']))

                Session.add(u)
                Session.add(t)

                # Commit every 20 tweets
                if counter >= 20:
                    Session.commit()
                    print "Commiting..."
                    counter = 0
Пример #12
0
def tweet_stream():
    # To track:
    words = [
        "olympic", "olympics", "olympian", "olympiad", "london2012",
        "bbcolympics", "openingceremony", "paralympic", "lo2012", "torch",
        "torchrelay", "olympictorch", "teamgb", "news", "#ces"
    ]
    # UK bounds:
    #locations = ["-10.0,50.0", "5.0,65.0"]
    try:
        #with tweetstream.SampleStream(, ) as stream:
        #with tweetstream.FilterStream(twitter_user, twitter_pw, track=words, locations=locations) as stream:
        with tweetstream.FilterStream(twitter_user, twitter_pw,
                                      track=words) as stream:
            for tweet in stream:
                logger.info(tweet)

    except tweetstream.ConnectionError as e:
        logger.error("ERROR: Disconnected from twitter. Reason: {}".format(
            e.reason))
        time.sleep(0.1)
Пример #13
0
def main(p, event, bbox=None, tag=None, people=None, mediaOnly=None):
    ''' Coordinates a new twitter stream connection'''

    if tag:
        tag = [tag]

    # Build an appropriate bounding box
    bbox = cf.buildBoundingBox(bbox)
    # track=tag, follow=people, 
    
    try:
        with tweetstream.FilterStream(p.sourceUser, p.sourcePassword, locations=bbox) as stream:
            for tweet in stream:
                
                # If we're only after those with media in
                if mediaOnly:
                    entities = tweet['entities']
                    
                    # If the tweet contains media
                    if entities.has_key('media'):
                        mediaOut = cf.processMedia(tweet)
                        mediaOut['objectId'] = event
                    else:
                        continue
                
                # Dump the tweet to a string for the jms
                try:
                    tweet = json.dumps(mediaOut, ensure_ascii=True)
                except Exception, e:
                    print 'FAILED to dump out'
                    print e
                    continue
            
                try:
                    success = cf.postTweet(tweet)
                except Exception, e:
                    print e
                    print success
Пример #14
0
    def handle(self, *args, **kwargs):
        self.screen_name = getattr(settings, 'TWITTER_USERNAME', None)
        self.password = getattr(settings, 'TWITTER_PASSWORD', None)

        tracking = ["@" + self.screen_name]
        retry_wait = 1

        while True:
            try:
                self.stdout.write("connecting at %s..." %
                                  (datetime.datetime.now(), ))
                self.stdout.flush()
                with tweetstream.FilterStream(self.screen_name,
                                              self.password,
                                              track=tracking) as stream:
                    self.stdout.write(" connected.\ntracking: %s\n" %
                                      (tracking, ))
                    for tweet in stream:
                        self._process_tweet(tweet)
            except tweetstream.ConnectionError as e:
                retry_wait *= 2
                self.stdout.write(" error '%s' retrying in %s...\n" %
                                  (e.reason, retry_wait))
                time.sleep(retry_wait)
Пример #15
0
import tweetstream
import sys
import json

words = ["beiber"]
stream = tweetstream.FilterStream("loverly", "oliver11", track=words)

for t in stream:
    tweet = json.dumps({
        "screen_name": t['user']['screen_name'],
        "created_at": t['created_at'],
        "id": t['id'],
        "text": t['text']
    })
    f = open('/Users/nickwynja/Sites/tweeter/tweets.txt', 'a')
    f.write("," + tweet)
    f.closed
Пример #16
0
    print_divider_line()


print "Authenticating"

api = twitter.Api(consumer_key=consumer_key,
                  consumer_secret=consumer_secret,
                  access_token_key=access_token_key,
                  access_token_secret=access_token_secret)

print "Logged user: @" + api.VerifyCredentials().screen_name

query = ['search']  # words to search
stream = tweetstream.FilterStream(twitter_account_username,
                                  twitter_account_password,
                                  track=query)

analized_tweets = 0
sent_tweets = 0
start_time = time.time()

for tweet in stream:
    try:
        analized_tweets += 1
        print ".",

        current_tpm = get_current_tpm(sent_tweets)

        if (should_reply_to_tweet(tweet)):
            if should_send_tweet_with_tpm(current_tpm):
Пример #17
0
    try:
        ofile.write(dumps(out) + '\n')
        #print dumps(out)
    except:
        print 'failed to dumps: ', tweet


if __name__ == '__main__':
    current = timechunk()
    fname = mkfname(current)
    outf = open(fname, 'w')

    while True:
        try:
            with tweetstream.FilterStream(uname, passwd,
                                          locations=locations) as stream:
                for tweet in stream:
                    if timechunk() != current:
                        current = timechunk()
                        new_fname = mkfname(current)
                        outf.close()
                        try:
                            rename(fname, fname + '.done')
                        except:
                            pass
                        fname = new_fname
                        outf = open(fname, 'w')
                        print 'opening ', fname
                    write_tweet(tweet, outf)
        except tweetstream.ConnectionError:
            delay = 2**backoff_power
Пример #18
0
"""
user
favorited => returns True/False
entities => Twitter Mentions Recorded Here
contributors  => mainly returns None
truncated => returns True/False
text => Tweet message
created_at => Date & Time Tweet Messages was created @
retweeted => returns True or False
in_reply_to_status_id_str => None or Something - Mainly returns None
coordinates => Returns None - or Geo Lat/Long Grid Coordinates
in_reply_to_user_id_str => integer twitter id
source => returns application platform utilized to tweet
in_reply_to_status_id => returns mainly None
in_reply_to_screen_name => twitter screen name
id_str => integer twitter id as a string
place => mainly returns None
filter_level => returns mainly "medium"
retweet_count => how many times the tweet has been re-tweeted
geo => mainly returns None
id => twitter id as integer
in_reply_to_user_id => twitter id as integer
"""

import tweetstream

words = ["FBI"]
with tweetstream.FilterStream("JollyJimBob", "delta0!23123", track=words,) as stream:
    for tweet in stream:
        print tweet['geo']
Пример #19
0
    if len(columns) != 5:
        print 'Error on line: %s' % line
        continue
    name = columns[0]
    latSW = float(columns[1])
    lonSW = float(columns[2])
    latNE = float(columns[3])
    lonNE = float(columns[4])
    name2a[name] = Area(name, latSW, lonSW, latNE, lonNE)
input.close()

locations = []
for area in name2a.values():
    print area
    locations.append('%f,%f' % (area.lonSW, area.latSW))
    locations.append('%f,%f' % (area.lonNE, area.latNE))   
print "Areas = %s" % locations

stream = tweetstream.FilterStream(username, password, follow=None, locations=locations, track=None, catchup=None, url=None)

while True:
    try:
        for tweet in stream:
            (id, rev) = db.save(tweet)
    except:
        time.sleep(60)
        stream = tweetstream.FilterStream(username, password, follow=None, locations=locations, track=None, catchup=None, url=None)
        pass
        
        
Пример #20
0
def main(p, mediaOnly=None):
    ''' Coordinates a new twitter stream connection'''

    # Logging config
    logFile = os.path.join(p.errorPath, p.connErrorFile)
    logging.basicConfig(filename=logFile,
                        format='%(levelname)s:: %(asctime)s %(message)s',
                        level=p.logLevel)

    # The mongo bits
    try:
        c, dbh = mdb.getHandle(host=p.dbHost,
                               port=p.dbPort,
                               db=p.db,
                               user=p.dbUser,
                               password=p.dbPassword)
        evCollHandle = dbh[p.eventsCollection]
    except:
        logging.critical('Failed to connect to db and authenticate.',
                         exc_info=True)
        sys.exit()

    # Here's the redis queue for managing the tweets as they come in
    try:
        q = RedisQueue(p.redisName,
                       host=p.redisHost,
                       password=p.redisPassword,
                       port=p.redisPort,
                       db=0)
    except:
        logging.critical("REDIS: Failed to connect in connectionClient.py. ",
                         exc_info=True)
        sys.exit()

    # Connection placeholder in case the exception catches the drop out
    connection = True

    while connection == True:

        # Get the existing tags and add the current
        try:
            tags = cf.getCurrentTags(evCollHandle)
        except:
            tags = None
            logging.error('Failed to get current tags from db.', exc_info=True)

        # Build the building boxes
        try:
            bboxes = cf.getCurrentBBoxes(evCollHandle)
        except:
            bboxes = None
            logging.error('Failed to get current BBOXes from db.',
                          exc_info=True)

        if not tags and not bboxes:
            logging.warning('Currently no tags or bboxes in the db.')
            sys.exit()

        try:
            print tags, bboxes
            with tweetstream.FilterStream(p.sourceUser,
                                          p.sourcePassword,
                                          track=tags,
                                          locations=bboxes) as stream:
                for tweet in stream:
                    if mediaOnly:
                        try:
                            q.put(json.dumps(tweet))
                        except:
                            logging.critical(
                                "Failed to put tweet on redis. This tweet: \n%s"
                                % (tweet),
                                exc_info=True)

        except tweetstream.ConnectionError:
            logging.critical("Disconnected from twitter", exc_info=True)
Пример #21
0
import tweetstream
import serial
import re
from pprint import pprint

ser = serial.Serial('/dev/ttyUSB0', 9600)
ser.write(" ")

regexTestString = "Hello @DigitalClacks !"
print re.sub(r'[^\w+]', ' ', re.sub(r'(@\S+)', '', regexTestString))

stream = tweetstream.FilterStream("DigitalClacks", "outofcheese", [982842908])
i = 0
for tweet in stream:
    ser.write("@")
    startingText = re.sub(r'[^\w+]', ' ', re.sub(r'(@\S+)', '', tweet["text"]))
    print startingText
    for c in startingText:
        ser.read()
        ser.write(c)
Пример #22
0
import tweetstream
import sys
import unidecode

words = ["opera", "firefox", "safari"]
people = [123, 124, 125]
locations = ["-122.75,36.8", "-121.75,37.8"]
with tweetstream.FilterStream("leopoldo3",
                              "twleopleop1978788888z",
                              track=words,
                              follow=people,
                              locations=locations) as stream:
    for tweet in stream:
        print("A")
Пример #23
0
    config = ConfigParser.ConfigParser()
    config.readfp(open(cfg_name))
    consumer_key = config.get("Oauth", "consumer_key")
    consumer_secret = config.get("Oauth", "consumer_secret")
    access_token = config.get("Oauth", "access_token")
    access_token_secret = config.get("Oauth", "access_token_secret")
    return (consumer_key, consumer_secret, access_token, access_token_secret)


if __name__ == "__main__":
    (consumer_key, consumer_secret, access_token,
     access_token_secret) = get_connection_secrets("oauth.cfg")
    words = [
        "sequester", "boehner", "sequestration", "obama", "fiscal cliff",
        "democrat", "republican", "compromise", "taxes", "deficit"
    ]

    # sw corner first
    #dc_bbox = ["-77.401428", "38.751941", "-76.728516", "39.123668"]

    #with tweetstream.FilterStream(consumer_key, consumer_secret, access_token,
    #                              access_token_secret, track=words,
    #                              locations=dc_bbox) as stream:
    with tweetstream.FilterStream(consumer_key,
                                  consumer_secret,
                                  access_token,
                                  access_token_secret,
                                  track=words) as stream:
        for tweet in stream:
            db.tweets.save(tweet)
Пример #24
0
import os
import types

print "start"

filecounter = 8
filename = "test_stream" + str(filecounter) + ".csv"
output = open(filename, "a")

#new york city
nyc = ["-74.5,40.5", "-73.2,41.3"]

words = ['dexter', 'bond']

#stream = tweetstream.SampleStream("601city", "chliklas")
stream = tweetstream.FilterStream("601city", "chliklas", locations=nyc)

counter = 878817

for tweet in stream:

    if tweet.get("delete"):
        print "delete"
        continue
    else:
        print counter

    # ----- write tweet infos ----- #

    # -- write count
    output.write(str(counter) + ", ")
Пример #25
0
import tweetstream
from utils import *
import networkx as net


words = ["#NSA"]
##people = [123,124,125]
#locations = ["-122.75,36.8", "-121.75,37.8"] #, follow=people, locations=locations


retweets=net.DiGraph()
hashtag_net=net.Graph()

with tweetstream.FilterStream("ElectionGauge", "cssgmu", track=words) as stream:
    for js in stream:

        ### process tweet to extract information
        try:
            author=js['user']['screen_name']
            entities=js['entities']
            mentions=entities['user_mentions']
            hashtags=entities['hashtags']

            for rt in mentions:
            	alter=rt['screen_name']
            	retweets.add_edge(author,alter)

            tags=[tag['text'].lower() for tag in hashtags]
            for t1 in tags: 
            	for t2 in tags:
            		if t1 is not t2:
Пример #26
0
import tweetstream
import pystache
import RPrinter.printer as rp
import time

printer = rp.RPrinter()

stream = tweetstream.FilterStream("login", "password", track=["columbo"])

template = """
**{{ timestamp }}**
**{{ screen_name }}**: {{ tweet }}
"""

for tweet in stream:
    if 'user' in tweet:

        # format date
        tweetDate = time.strptime(tweet['created_at'],
                                  "%a %b %d %H:%M:%S +0000 %Y")
        printDate = time.strftime("%b.%d %H:%M:%S", tweetDate)

        # setup context
        context = {
            'timestamp': printDate,
            'screen_name':
            tweet['user']['screen_name'].encode('ascii', 'ignore'),
            'tweet': tweet['text'].encode('ascii', 'ignore')
        }

        printer.printStr(pystache.render(template, context))
Пример #27
0
import tweetstream

#words = ['bugger','london']
user = '******'
password = '******'

locations = ["-122.75,36.8", "-121.75,37.8", "-0.15,51.50", "-0.10,51.55"]

stream = tweetstream.FilterStream(user, password, locations=locations)

for tweet in stream:
    print tweet
    print dir(tweet)
Пример #28
0
        "http://api.thingspeak.com/channels/1417/field/1/last.txt").read()
])

if (ENABLE_TWITTER_BOT):
    try:
        print '*** Authenticating Twitter bot...'
        auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
        auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
        api = tweepy.API(auth)
        print '*** Authorized!'
    except:
        print '*** Error authenticating Twitter bot. Check OAuth settings!'

try:
    print '*** Connecting to Twitter stream...'
    stream = tweetstream.FilterStream(TW_USERNAME, TW_PASSWORD, track=HASHTAGS)
    print '*** Connected!'
    print '*** Waiting for tweets matching hashtags...'
except:
    print '*** Twitter stream failed. :('

try:
    for tweet in stream:
        print "-----" * 4
        print datetime.datetime.now()
        print "New tweet from: " + tweet['user']['screen_name'] + "\n"
        print tweet['text']
        print "-----" * 4
        words = re.findall(r'\w+', tweet['text'].lower())
        cmds = [word for word in words if word in COLOR_SET]
        if (cmds):
Пример #29
0
    if ((news_link not in Predictor.links_repository) and news_link != ''
            and company_name != 'DUMMY'):
        Predictor.links_repository.append(news_link)
        # Navigate to the new link
        return True, company_name, news_link
    else:
        return False, company_name, ''


words = []
people = [1652541]
locations = []

stream = tweetstream.FilterStream("PDSStern",
                                  "rebeccaBlack",
                                  track=words,
                                  follow=people,
                                  locations=locations)
logger.debug("Connected to Reuters twitter stream and listening..")

#test_tweet_text = "U.S. to sell rest of AIG stock, ending $182 billion rescue http://t.co/BSbT9ezC"
#tweet_text = tweet['text']
for tweet in stream:
    #while True:

    if (tweet['text']):

        logger.debug("Incoming tweet: %s", tweet['text'])
        isValidTweet, company_ticker_name, news_link = checkIfValidTweet(
            tweet['text'])
Пример #30
0
import geocoder
import tweetstream
from webcast import *
import networkx as net

words = ["Obama", "Romney", "republican", "democrat", "election"]
# people = [123,124,125]
# locations = ["-122.75,36.8", "-121.75,37.8"] #, follow=people, locations=locations

retweets = net.DiGraph()
hashtag_net = net.Graph()
spatial = net.Graph()

geo = geocoder.geocoder()

with tweetstream.FilterStream("<your user ID>", "<password>",
                              track=words) as stream:
    for js in stream:

        # process tweet to extract information
        try:
            author = js['user']['screen_name']
            entities = js['entities']
            mentions = entities['user_mentions']
            hashtags = entities['hashtags']
            location = geo.geocode(js)

            for rt in mentions:
                alter = rt['screen_name']
                retweets.add_edge(author, alter)

            tags = [tag['text'].lower() for tag in hashtags]