0

I have written this script:

import tweetstream   
import pymongo  
connection = pymongo.Connection("mongodb://localhost:27017")  
db = connection.socialdata  
words = ["social media", "innovation", "cloud computing"]  
with tweetstream.FilterStream('username', 'password', track=words) as stream:  
    for tweet in stream:         
        db.tweets.save(tweet)

But on execution I am getting following error please tell me how to remove this error:

Traceback (most recent call last):
    File "tweet.py", line 9, in <module>
        with tweetstream.FilterStream(username, password, track=words) as stream:
TypeError: __init__() takes at least 5 arguments (4 given)</module>

Thanks in advance.

Tharindu Rusira
  • 691
  • 9
  • 17

1 Answers1

2

I'm wondering how you got tweetstream working in the first place because all I know is that basic username/password access was deprecated some time back. Now Twitter allows OAuth access only.


Turning back to your question, your FileStream call is perfectly valid. Look at FileStream class implementation and you'd understand why.

Following are few lines of code from FilterStream class which is available here

def __init__(self, username, password, follow=None, locations=None,
                 track=None, catchup=None, raw=False, timeout=None, url=None):
        self._follow = follow
        self._locations = locations
        self._track = track
        # remove follow, locations, track
        BaseStream.__init__(self, username, password,
                            raw=raw, timeout=timeout, url=url)

So, tweetstream.FilterStream("username", "password", track=words) should work. Because as you can see there are only 3 mandatory arguments for __init__. (self,username, password).

All others are optional. Please be noted that this code is from tweetstream 1.1.1 which I think the last version released.


However, as said in your error,FilterStream constructor in tweetstream takes a minimum of 5 arguments.

This documentation gives an example for what you are trying to do.

As it says, try using this initialization instead,

with tweetstream.FilterStream("username", "password", track=words,
                               follow=people, locations=locations) as stream

According to the source,

  • Locations are a list of bounding boxes in which geotagged tweets should originate. The argument should be an iterable of longitude/latitude pairs.

  • Track specifies keywords to track. The argument should be an iterable of strings.

  • Follow returns statuses that reference given users. Argument should be an iterable of twitter user IDs. The IDs are userid ints, not the screen names.

Tharindu Rusira
  • 691
  • 9
  • 17