tweepy.Stream
— Stream Reference¶
- class tweepy.Stream(consumer_key, consumer_secret, access_token, access_token_secret, *, chunk_size=512, daemon=False, max_retries=inf, proxy=None, verify=True)¶
Filter and sample realtime Tweets
- 매개변수
consumer_key (str) – Twitter API Consumer Key
consumer_secret (str) – Twitter API Consumer Secret
access_token (str) – Twitter API Access Token
access_token_secret (str) – Twitter API Access Token Secret
chunk_size (int) – The default socket.read size. Default to 512, less than half the size of a Tweet so that it reads Tweets with the minimal latency of 2 reads per Tweet. Values higher than ~1kb will increase latency by waiting for more data to arrive but may also increase throughput by doing fewer socket read calls.
daemon (bool) – Whether or not to use a daemon thread when using a thread to run the stream
max_retries (int) – Max number of times to retry connecting the stream
proxy (Optional[str]) – URL of the proxy to use when connecting to the stream
verify (Union[bool, str]) – Either a boolean, in which case it controls whether to verify the server’s TLS certificate, or a string, in which case it must be a path to a CA bundle to use.
- session¶
Requests Session used to connect to the stream
- Type
Optional[
requests.Session
]
- thread¶
Thread used to run the stream
- Type
Optional[
threading.Thread
]
- filter(*, follow=None, track=None, locations=None, filter_level=None, languages=None, stall_warnings=False, threaded=False)¶
Filter realtime Tweets
- 매개변수
follow (Optional[List[Union[int, str]]]) – User IDs, indicating the users to return statuses for in the stream
locations (Optional[List[float]]) – Specifies a set of bounding boxes to track
filter_level (Optional[str]) –
Setting this parameter to one of none, low, or medium will set the minimum value of the filter_level Tweet attribute required to be included in the stream. The default value is none, which includes all available Tweets.
When displaying a stream of Tweets to end users (dashboards or live feeds at a presentation or conference, for example) it is suggested that you set this value to medium.
languages (Optional[List[str]]) – Setting this parameter to a comma-separated list of BCP 47 language identifiers corresponding to any of the languages listed on Twitter’s advanced search page will only return Tweets that have been detected as being written in the specified languages. For example, connecting with language=en will only stream Tweets detected to be in the English language.
stall_warnings (bool) – Specifies whether stall warnings should be delivered
threaded (bool) – Whether or not to use a thread to run the stream
- 예외 발생
TweepyException – When number of location coordinates is not a multiple of 4
- 반환값
The thread if
threaded
is set toTrue
, elseNone
- 반환 형식
Optional[threading.Thread]
참조
- sample(*, languages=None, stall_warnings=False, threaded=False)¶
Sample realtime Tweets
- 매개변수
languages (Optional[List[str]]) – Setting this parameter to a comma-separated list of BCP 47 language identifiers corresponding to any of the languages listed on Twitter’s advanced search page will only return Tweets that have been detected as being written in the specified languages. For example, connecting with language=en will only stream Tweets detected to be in the English language.
stall_warnings (bool) – Specifies whether stall warnings should be delivered
threaded (bool) – Whether or not to use a thread to run the stream
- 반환값
The thread if
threaded
is set toTrue
, elseNone
- 반환 형식
Optional[threading.Thread]
참조
- disconnect()¶
Disconnect the stream
- on_closed(response)¶
This is called when the stream has been closed by Twitter.
- 매개변수
response (requests.Response) – The Response from Twitter
- on_connect()¶
This is called after successfully connecting to the streaming API.
- on_connection_error()¶
This is called when the stream connection errors or times out.
- on_disconnect()¶
This is called when the stream has disconnected.
- on_exception(exception)¶
This is called when an unhandled exception occurs.
- 매개변수
exception (Exception) – The unhandled exception
- on_keep_alive()¶
This is called when a keep-alive signal is received.
- on_request_error(status_code)¶
This is called when a non-200 HTTP status code is encountered.
- 매개변수
status_code (int) – The HTTP status code encountered
- on_data(raw_data)¶
This is called when raw data is received from the stream. This method handles sending the data to other methods based on the message type.
- 매개변수
raw_data (JSON) – The raw data from the stream
참조
- on_status(status)¶
This is called when a status is received.
- 매개변수
status (Status) – The Status received
- on_delete(status_id, user_id)¶
This is called when a status deletion notice is received.
- on_disconnect_message(message)¶
This is called when a disconnect message is received.
- 매개변수
message (JSON) – The disconnect message
- on_limit(track)¶
This is called when a limit notice is received.
- 매개변수
track (int) – Total count of the number of undelivered Tweets since the connection was opened
- on_scrub_geo(notice)¶
This is called when a location deletion notice is received.
- 매개변수
notice (JSON) – The location deletion notice
- on_status_withheld(notice)¶
This is called when a status withheld content notice is received.
- 매개변수
notice (JSON) – The status withheld content notice
- on_user_withheld(notice)¶
This is called when a user withheld content notice is received.
- 매개변수
notice (JSON) – The user withheld content notice
- on_warning(warning)¶
This is called when a stall warning message is received.
- 매개변수
warning (JSON) – The stall warning