
    QdT                         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e	          Z
 e
            Z G d de	          Z G 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                   t    e Zd ZdZ eej                   Zej        r eej	                   Z
neZ
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                     | j         S )z2
        Access the relevant time offset.
        )	DSTOFFSET)selfdts     0lib/python3.11/site-packages/nltk/twitter/api.py	utcoffsetz$LocalTimezoneOffsetWithUTC.utcoffset'   s     ~    N)__name__
__module____qualname____doc__r   _timer   	STDOFFSETdaylightaltzoner   r    r   r   r
   r
      sl        
 
 	5>/222I~ Iu}n555			    r   r
   c                        e Zd ZdZddZd ZdS )BasicTweetHandlerz
    Minimal implementation of `TweetHandler`.

    Counts the number of Tweets and decides when the client should stop
    fetching them.
       c                 B    || _         d| _        	 d| _        	 d | _        d S )Nr   F)limitcounterdo_stopmax_id)r   r    s     r   __init__zBasicTweetHandler.__init__9   s0    
	 	 r   c                 2    | j         | j        k     o| j         S )zL
        Returns `False` if the client should stop fetching Tweets.
        )r!   r    r"   r   s    r   do_continuezBasicTweetHandler.do_continueH   s     |dj(=-==r   N)r   )r   r   r   r   r$   r'   r   r   r   r   r   1   sA            > > > > >r   r   )	metaclassc                   N    e Zd ZdZd	dZed             Zed             Zd
dZdS )TweetHandlerIzu
    Interface class whose subclasses should implement a handle method that
    Twitter clients can delegate to.
    r   Nc                     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   LOCAL
startingup)r   r    r,   r-   s       r   r$   zTweetHandlerI.__init__U   ss     	""4/// $ $ 	N$,.>$Mu$M$MD! 	N$,.>$Mu$M$MD!r   c                     dS )zJ
        Deal appropriately with data returned by the Twitter API
        Nr   )r   datas     r   handlezTweetHandlerI.handlem         r   c                     dS )z?
        Actions when the tweet limit has been reached
        Nr   r&   s    r   	on_finishzTweetHandlerI.on_finishs   r3   r   Fc                 z   | j         s| j        rd}t          j        |d         |                              t
          j                  }| j         r|| j         k    s| j        rV|| j        k     rM| j         r
d}| j         }n	d}| j        }|r$t          d                    |||                     d| _	        dS dS dS dS )	z'
        Validate date limits.
        z%a %b %d %H:%M:%S +0000 %Y
created_at)r   earlierlaterz1Date limit {} is {} than date of current tweet {}TN)
r,   r-   r   strptimereplacer   utcprintformatr"   )r   r1   verbosedate_fmt
tweet_datemessage
date_limits          r   check_date_limitzTweetHandlerI.check_date_limity   s      	$D$9 	$3H!*4+=xHHPP| Q  J % $*t7L*L*L% +M*4t7L*L*L( 7'G!%!6JJ%G!%!6J KRR&   
  $)	$ 	$
 +M*L*L*Lr   )r   NN)F)	r   r   r   r   r$   r   r2   r5   rD   r   r   r   r*   r*   O   s|         
   0   ^
   ^
$ $ $ $ $ $r   r*   )r   timer   abcr   r   r   r   r   r   r
   r.   r   r*   r   r   r   <module>rG      s   
     ' ' ' ' ' ' ' ' : : : : : : : : : : : :       6 	#"$$> > > > >' > > > ><B$ B$ B$ B$ B$% B$ B$ B$ B$ B$r   