B
    >?[                 @   s   d Z ddlZddlmZmZ ddlmZmZmZ ddl	m
Z
 ddlmZ G dd deZe Ze
eG d	d
 d
eZG dd deZdS )zY
This module provides an interface for TweetHandlers, and support for timezone
handling.
    N)ABCMetaabstractmethod)tzinfo	timedeltadatetime)add_metaclass)UTCc               @   s@   e Zd ZdZeej dZejr0eej	 dZ
neZ
dd ZdS )LocalTimezoneOffsetWithUTCa  
    This is not intended to be a general purpose class for dealing with the
    local timezone. In particular:

    * it assumes that the date passed has been created using
      `datetime(..., tzinfo=Local)`, where `Local` is an instance of
      the object `LocalTimezoneOffsetWithUTC`;
    * for such an object, it returns the offset with UTC, used for date comparisons.

    Reference: https://docs.python.org/3/library/datetime.html
    )Zsecondsc             C   s   | j S )z2
        Access the relevant time offset.
        )	DSTOFFSET)selfZdt r   /lib/python3.7/site-packages/nltk/twitter/api.py	utcoffset,   s    z$LocalTimezoneOffsetWithUTC.utcoffsetN)__name__
__module____qualname____doc__r   _timeZtimezoneZ	STDOFFSETZdaylightZaltzoner
   r   r   r   r   r   r	      s   r	   c               @   s"   e Zd ZdZdddZdd ZdS )	BasicTweetHandlerz
    Minimal implementation of `TweetHandler`.

    Counts the number of Tweets and decides when the client should stop
    fetching them.
       c             C   s   || _ d| _d| _d | _d S )Nr   F)limitcounterdo_stopZmax_id)r   r   r   r   r   __init__?   s    zBasicTweetHandler.__init__c             C   s   | j | jk o| j S )zL
        Returns `False` if the client should stop fetching Tweets.
        )r   r   r   )r   r   r   r   do_continueN   s    zBasicTweetHandler.do_continueN)r   )r   r   r   r   r   r   r   r   r   r   r   6   s   
r   c               @   s<   e Zd ZdZdddZedd Zedd	 ZdddZdS )TweetHandlerIzu
    Interface class whose subclasses should implement a handle method that
    Twitter clients can delegate to.
    r   Nc             C   sJ   t | | d| _d| _|r,t|dti| _|r@t|dti| _d| _dS )a  
        :param int limit: The number of data items to process in the current        round of processing.

        :param tuple upper_date_limit: The date at which to stop collecting        new data. This should be entered as a tuple which can serve as the        argument to `datetime.datetime`.        E.g. `date_limit=(2015, 4, 1, 12, 40)` for 12:30 pm on April 1 2015.

        :param tuple lower_date_limit: The date at which to stop collecting        new data. See `upper_data_limit` for formatting.
        Nr   T)r   r   upper_date_limitlower_date_limitr   LOCALZ
startingup)r   r   r   r   r   r   r   r   [   s    zTweetHandlerI.__init__c             C   s   dS )zJ
        Deal appropriately with data returned by the Twitter API
        Nr   )r   datar   r   r   handles   s    zTweetHandlerI.handlec             C   s   dS )z?
        Actions when the tweet limit has been reached
        Nr   )r   r   r   r   	on_finishy   s    zTweetHandlerI.on_finishFc             C   s   | j s| jrd}t|d |jtd}| j r8|| j ksH| jr|| jk r| j rZd}| j }n
d}| j}|rztd||| d| _dS )	z'
        Validate date limits.
        z%a %b %d %H:%M:%S +0000 %YZ
created_at)r   ZearlierZlaterz4Date limit {0} is {1} than date of current tweet {2}TN)	r   r   r   Zstrptimereplacer   printformatr   )r   r   verboseZdate_fmtZ
tweet_datemessageZ
date_limitr   r   r   check_date_limit   s     zTweetHandlerI.check_date_limit)r   NN)F)	r   r   r   r   r   r   r    r!   r'   r   r   r   r   r   U   s
   
r   )r   Ztimer   abcr   r   r   r   r   Zsixr   Znltk.compatr   r	   r   objectr   r   r   r   r   r   <module>   s   