o
    rZh                     @   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re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   ?/var/www/auris/lib/python3.10/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      dS )zJ
        Deal appropriately with data returned by the Twitter API
        Nr   )r   datar   r   r   handlem       zTweetHandlerI.handlec                 C   r$   )z?
        Actions when the tweet limit has been reached
        Nr   r   r   r   r   	on_finishs   r'   zTweetHandlerI.on_finishFc                 C   s   | j s| jrCd}t|d |jtjd}| j r|| j ks%| jrE|| jk rG| 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 %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   s0   

zTweetHandlerI.check_date_limit)r   NN)F)	r   r   r   r   r   r   r&   r(   r0   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   