本文整理匯總了Python中tweepy.streaming.StreamListener類的典型用法代碼示例。如果您正苦於以下問題:Python StreamListener類的具體用法?Python StreamListener怎麽用?Python StreamListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了StreamListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
def __init__(self, collection, stream_name, data_dir, seed=False, duration_minutes=15, tweets_per_record=25000):
StreamListener.__init__(self)
log.info("Streaming %s tweets for %s collection into %s. Rotating files every %s minutes. Rotating "
"records every %s tweets",
stream_name, collection, data_dir, duration_minutes, tweets_per_record)
self.collection = collection
self.stream_name = stream_name
self.duration_minutes = duration_minutes
self.tweets_per_record = tweets_per_record
self.data_dir = data_dir
self.seed = seed
#Create data_dir
if not os.path.exists(self.data_dir):
os.makedirs(self.data_dir)
self.period_start = None
self.period_start_time = None
self.warc = None
self.warc_filepath = None
self.segment_origin_id = None
self.payload = ""
self.segment = 1
self.segment_total_length = 0
self.tweet_count = 0
#These will be set by StreamDecorator
self.session = None
self.url = None
示例2: __init__
def __init__(self, api=None, fobj=None):
StreamListener.__init__(self, api)
if fobj is None:
fobj = sys.stdout
self.fobj = fobj
self.ratelimit = open('ratelimits.log', 'a')
self.ratelimit.write('\n\n# Stream restarted on {0}'.format(time.strftime('%c')))
示例3: __init__
def __init__(self,db_path,verbose,*args,**kwargs):
self._verbose = verbose
#setup database:
self._conn = sqlite3.connect(options.db_path)
c = self._conn.cursor()
# Create table
# c.execute('''CREATE TABLE IF NOT EXISTS GeoTweet
# (text text, lat real, lng real, time text, rt text, rt_count text, tw_id text)''')
cmd = """
CREATE TABLE IF NOT EXISTS "capture_geotweet" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, -- table ID
"time" varchar(100) NOT NULL, -- time in string, e.g., "Sun Jun 22 14:24:56 +0000 2014"
"text" varchar(200) NOT NULL, -- content of tweet
"lat" decimal NOT NULL, -- latitude of tweet (all tweets in the database are geotagged)
"lng" decimal NOT NULL, -- longitude of tweet
"rt" bool NOT NULL, -- whether the tweet was retweeted
"rt_count" integer NOT NULL, -- the number of times the tweet has been retweeted
"tw_id" varchar(50) NOT NULL -- the Twitter assigned ID
, "epoch_time" integer); -- time of tweet in seconds since Thursday Jan 1st, 1970 00:00:00 GMT
"""
c.execute(cmd)
self._conn.commit()
self._time_format = '%a %b %d %H:%M:%S +0000 %Y'
self._pattern = re.compile("[\W,.:/\']+")
StreamListener.__init__(self,*args,**kwargs)
示例4: __init__
def __init__(self, botname, taghandler, customhandler):
self.botname = botname
self.rsettag = re.compile(u"^@%s [email protected]?([a-zA-Z0-9_-]+) *[\=\=] *([^\s]+)$" % self.botname, re.IGNORECASE)
self.rgettag = re.compile(u"^@%s [email protected]?([a-zA-Z0-9_-]+) *$" % self.botname, re.IGNORECASE)
self.rdeltag = re.compile(u"^@%s +\/del +([^\s]+) *$" % self.botname, re.IGNORECASE)
StreamListener.__init__(self)
self.taghandler = taghandler
self.customhandler = customhandler
示例5: __init__
def __init__(self, hashtags, session, engine):
StreamListener.__init__(self)
self.cpt = 0 # FIXME: test if useful
self.eu = EncodingUtils()
self.hashtags = self.format_hashtags(hashtags)
self.session = session # bridge to the db
self.engine = engine
示例6: __init__
def __init__(self,timer):
self.inc = 0
StreamListener.__init__(self)
# report the start of data collection...
print "Gathering data at %s"%(str(ctime()))
self.startTime = time()
print "Start Time = %s"%(str(ctime()))
self.timer = timer
self.count = 0
示例7: __init__
def __init__(self,timer):
self.inc = 0
StreamListener.__init__(self)
# report the start of data collection...
print "Gathering data at %s"%(str(ctime()))
self.startTime = time()
print "Start Time = %s"%(str(ctime()))
self.timer = timer
self.count = 0
self.conn = psycopg2.connect(database="postgres", user="postgres", password="pass", host="localhost", port="5432")
示例8: __init__
def __init__(self,useBrowser,ofile,colorDict):
StreamListener.__init__(self)
self.useBrowser = useBrowser
self.ofile = ofile
(self.twMap,self.controller) = mapper.initMap(self.ofile,self.useBrowser)
self.allCoordinates = []
self.flog = codecs.open("log.txt",mode="w",encoding="utf-8")
self.gcCount = 0
self.tweetCount = 0
self.colorDict = colorDict
示例9: __init__
def __init__(self, count=100):
"""
creates a Custom Listener of Tweets that will end after a given amount of streamed Tweets
:param count: number of Tweets to stream
"""
# instantiating the super class StreamListener
StreamListener.__init__(self)
self.max_count = count
self.counter = 0
self.tweets = []
示例10: __init__
def __init__(self, *args, **kwargs):
state_dir = kwargs.pop('state_dir')
self.post_replies = kwargs.pop('post_replies', False)
self.gather = kwargs.pop('gather', None)
StreamListener.__init__(self, *args, **kwargs)
self.me = self.api.me()
self._state = State.load(self.me.screen_name, state_dir)
if self.gather:
os.makedirs(self.gather, exist_ok=True)
示例11: __init__
def __init__(self,timer):
self.inc = 0
StreamListener.__init__(self)
# report the start of data collection...
print "Gathering data at %s"%(str(ctime()))
self.startTime = time()
print "Start Time = %s"%(str(ctime()))
### When initialized, connects to MongoDB database tweets
self.db=pymongo.MongoClient().tweets
self.timer = timer
self.count = 0
示例12: __init__
def __init__(self, user_id_to_monitor, handle_status_callback):
""" user_id_to_monitor: a valid Twitter user handle
handle_status_callback: a callback that takes
(hashtag, originating_twitter_user_id, tweet) as parameters.
The client callback will be invoked on every hashtag in a tweet
that mentions it."""
StreamListener.__init__(self)
self.user_id_to_monitor = user_id_to_monitor
self.handle_status = handle_status_callback
示例13: __init__
def __init__(self, node, southwest, northeast, extras):
logging.info("Beginning TwitterStreamer init")
StreamListener.__init__(self)
# Lock and target location
self.lock = threading.Lock()
self.buckets = {}
self.deltas = {}
self.uploaders = {}
self.location = [southwest[LONG],southwest[LAT],northeast[LONG],northeast[LAT]]
self.event_manager = EventManager()
# Upload handler
self.node = node
logging.info("TwitterStreamer init successful")
示例14: __init__
def __init__(self):
StreamListener.__init__(self)
self.destinations = []
示例15: __init__
def __init__(self, handler_class, api=None, **opts):
StreamListener.__init__(self)
self.handler = handler_class(**opts)