a
     ˜ëjÃ  ã                   @   sp   d Z ddlZddlmZmZ ddlmZmZmZm	Z	 G dd„ de	ƒZ
e
ƒ ZG dd„ ded	�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)ÚdatetimeÚ	timedeltaÚtimezoneÚtzinfoc                   @   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
    )Úsecondsc                 C   s   | j S )z2
        Access the relevant time offset.
        )Ú	DSTOFFSET)ÚselfÚdt© r   úO/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/nltk/twitter/api.pyÚ	utcoffset'   s    z$LocalTimezoneOffsetWithUTC.utcoffsetN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú_timer   Z	STDOFFSETÚdaylightÚ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__9   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_continueH   s    zBasicTweetHandler.do_continueN)r   )r   r   r   r   r   r   r   r   r   r   r   1   s   
r   )Ú	metaclassc                   @   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   U   s    zTweetHandlerI.__init__c                 C   s   dS )zJ
        Deal appropriately with data returned by the Twitter API
        Nr   )r   Údatar   r   r   Úhandlem   s    zTweetHandlerI.handlec                 C   s   dS )z?
        Actions when the tweet limit has been reached
        Nr   r   r   r   r   Ú	on_finishs   s    zTweetHandlerI.on_finishFc                 C   s†   | j s| jr‚d}t |d |¡jtjd�}| j r:|| j ksJ| jr‚|| jk r‚| j r\d}| j }n
d}| j}|r|td |||¡ƒ d| _	dS )	z'
        Validate date limits.
        z%a %b %d %H:%M:%S +0000 %YZ
created_at)r   ZearlierZlaterz1Date limit {} is {} than date of current tweet {}TN)
r!   r"   r   ÚstrptimeÚreplacer   ÚutcÚprintÚformatr   )r   r$   ÚverboseZdate_fmtZ
tweet_dateÚmessageZ
date_limitr   r   r   Úcheck_date_limity   s,    ÿÿÿÿÿzTweetHandlerI.check_date_limit)r   NN)F)	r   r   r   r   r   r   r%   r&   r.   r   r   r   r   r    O   s   


r    )r   Útimer   Úabcr   r   r   r   r   r   r   r#   r   r    r   r   r   r   Ú<module>	   s   