
    g                         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y)zY
This module provides an interface for TweetHandlers, and support for timezone
handling.
    N)ABCMetaabstractmethod)datetime	timedeltatimezonetzinfoc                       e Zd ZdZ eej                         Zej                  r eej                         Z
d ZyeZ
d Zy)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     E/var/www/openai/venv/lib/python3.12/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
      sA    
 5>>/2I~~u}}n5	 	r   r
   c                       e Zd ZdZddZd Zy)BasicTweetHandlerz
    Minimal implementation of `TweetHandler`.

    Counts the number of Tweets and decides when the client should stop
    fetching them.
    c                 @    || _         d| _        	 d| _        	 d | _        y )Nr   F)limitcounterdo_stopmax_id)r   r   s     r   __init__zBasicTweetHandler.__init__9   s,    
	 	 r   c                 R    | j                   | j                  k  xr | j                   S )zL
        Returns `False` if the client should stop fetching Tweets.
        )r    r   r!   r   s    r   do_continuezBasicTweetHandler.do_continueH   s#     ||djj(=-==r   N)   )r   r   r   r   r#   r&   r   r   r   r   r   1   s    >r   r   )	metaclassc                   @    e Zd ZdZddZed        Zed        ZddZy)	TweetHandlerIzu
    Interface class whose subclasses should implement a handle method that
    Twitter clients can delegate to.
    Nc                     t         j                  | |       d| _        d| _        |rt	        |dt
        i| _        |rt	        |dt
        i| _        d| _        y)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   sW     	""4/ $ $$,.>$Mu$MD!$,.>$Mu$MD!r   c                      y)zJ
        Deal appropriately with data returned by the Twitter API
        Nr   )r   datas     r   handlezTweetHandlerI.handlem       r   c                      y)z?
        Actions when the tweet limit has been reached
        Nr   r%   s    r   	on_finishzTweetHandlerI.on_finishs   r3   r   c                    | j                   s| j                  rd}t        j                  |d   |      j	                  t
        j                        }| j                   r|| j                   kD  s| j                  r_|| j                  k  rO| j                   rd}| j                   }nd}| j                  }|rt        dj                  |||             d| _	        yyyy)	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$93H!**4+=xHPP|| Q J %%*t7L7L*L%%*t7L7L*L(('G!%!6!6J%G!%!6!6JKRR&
  $ +M% %:r   )r'   NN)F)	r   r   r   r   r#   r   r2   r5   rD   r   r   r   r*   r*   O   s9    
0  
  
$r   r*   )r   timer   abcr   r   r   r   r   r   r
   r.   r   r*   r   r   r   <module>rG      sI   
  ' : : 6 	#$>' ><B$% B$r   