
    gRD                     F   d dl mZ d dlZd dlmZ 	 d dlmZ  G d de	      Z
 G d de
      Z G d	 d
e
      Z G d de
      Z G d de
      Z G d de
      Z G d de
      Z G d de
      Z G d de
      Z G d de
      Z G d de
      Zy# e$ r	 d dlmZ Y w xY w)    )unicode_literalsN)timegm)	parsedatec                   L    e Zd ZdZd Zd Zd Zd Zd ZddZ	d Z
ed	        Zy
)TwitterModelz8 Base class from which all twitter models will inherit. c                     i | _         y N)param_defaults)selfkwargss     #/opt/Tautulli/lib/twitter/models.py__init__zTwitterModel.__init__   s
         c                 "    | j                         S )zi Returns a string representation of TwitterModel. By default
        this is the same as AsJsonString(). )AsJsonStringr   s    r   __str__zTwitterModel.__str__   s       ""r   c                 L    |xr! | j                         |j                         k(  S r	   )AsDictr   others     r   __eq__zTwitterModel.__eq__   s    8%,,.88r   c                 &    | j                  |       S r	   )r   r   s     r   __ne__zTwitterModel.__ne__   s    ;;u%%%r   c                     t        | d      rt        | j                        S t        dj	                  t        |                   )Nidz%unhashable type: {} (no id attribute))hasattrhashr   	TypeErrorformattyper   s    r   __hash__zTwitterModel.__hash__   s8    4= C#VDJ/1 1r   c                 N    t        j                  | j                         |d      S )zo Returns the TwitterModel as a JSON string based on key/value
        pairs returned from the AsDict() method. T)ensure_ascii	sort_keys)jsondumpsr   )r   r$   s     r   r   zTwitterModel.AsJsonString&   s     zz$++-ldSSr   c                 
   i }| j                   j                         D ]  \  }}t        t        | |d      t        t
        t        f      rdt	               ||<   t        | |d      D ]F  }t        |dd      r#||   j                  |j                                3||   j                  |       H t        t        | |d      dd      rt        | |      j                         ||<   t        | |d      st        | |d      ||<    |S )z Create a dictionary representation of the object. Please see inline
        comments on construction when dictionaries contain TwitterModels. Nr   )	r
   items
isinstancegetattrlisttuplesetappendr   )r   datakeyvaluesubobjs        r   r   zTwitterModel.AsDict+   s      //557 	5LS% '$T2T5#4FG FS	%dC6 1Fvx6S	((9S	((0	1 sD18TB#D#.557S	
 sD)#D#t4S	7	58 r   c                     |j                         }|r|j                         D ]
  \  }}|||<     | di |}||_        |S )z Create a new instance based on a JSON dict. Any kwargs should be
        supplied by the inherited, calling class.

        Args:
            data: A JSON dict, as converted from the JSON in the twitter API.

         )copyr)   _json)clsr0   r   	json_datar1   valcs          r   NewFromJsonDictzTwitterModel.NewFromJsonDictN   sO     IIK	"LLN %S!$	#% )r   N)T)__name__
__module____qualname____doc__r   r   r   r   r"   r   r   classmethodr<   r5   r   r   r   r      s>    B!#
9&1T
!F  r   r   c                       e Zd ZdZd Zd Zy)Mediaz5A class representing the Media component of a tweet. c                     d d d d d d d d d d d
| _         | j                   j                         D ]"  \  }}t        | ||j                  ||             $ y )N)
display_urlexpanded_urlext_alt_textr   	media_urlmedia_url_httpssizesr!   url
video_infor
   r)   setattrgetr   r   paramdefaults       r   r   zMedia.__init__f   sf      #
 !% 3 3 9 9 ; 	=UGD%E7!;<	=r   c                 f    dj                  | j                  | j                  | j                        S )Nz;Media(ID={media_id}, Type={media_type}, DisplayURL='{url}'))media_id
media_typerK   )r    r   r!   rE   r   s    r   __repr__zMedia.__repr__w   s2    LSSWWyy   T " 	"r   Nr=   r>   r?   r@   r   rV   r5   r   r   rC   rC   b   s    ?=""r   rC   c                       e Zd ZdZd Zd Zy)ListzAA class representing the List structure used by the twitter API. c                    d d d d d d d d d d d d| _         | j                   j                         D ]"  \  }}t        | ||j                  ||             $ d|v r*t        j                  |j                  d            | _        y y )N)description	following	full_namer   member_countmodenameslugsubscriber_counturiuserrd   )r
   r)   rN   rO   Userr<   rd   rP   s       r   r   zList.__init__   s      $
 !% 3 3 9 9 ; 	=UGD%E7!;<	= V,,VZZ-?@DI r   c                     dj                  | j                  | j                  | j                  | j                  j
                        S )NzDList(ID={list_id}, FullName={full_name!r}, Slug={slug}, User={user}))list_idr]   ra   rd   )r    r   r]   ra   rd   screen_namer   s    r   rV   zList.__repr__   s=    U\\GGnn&&	 ] ( 	(r   NrW   r5   r   r   rY   rY   ~   s    KA*(r   rY   c                       e Zd ZdZd Zd Zy)Categoryz<A class representing the suggested user category structure. c           	          d d d d| _         | j                   j                         D ]"  \  }}t        | ||j                  ||             $ y )N)r`   sizera   rM   rP   s       r   r   zCategory.__init__   sQ    
 !% 3 3 9 9 ; 	=UGD%E7!;<	=r   c                 f    dj                  | j                  | j                  | j                        S )Nz1Category(Name={name!r}, Slug={slug}, Size={size}))r`   ra   rl   )r    r`   ra   rl   r   s    r   rV   zCategory.__repr__   s0    BII J  	r   NrW   r5   r   r   rj   rj      s    F=r   rj   c                       e Zd ZdZd Zd Zy)DirectMessagez'A class representing a Direct Message. c           	          d d d d d d| _         | j                   j                         D ]"  \  }}t        | ||j                  ||             $ y )N)
created_atr   recipient_id	sender_idtextrM   rP   s       r   r   zDirectMessage.__init__   sW     
 !% 3 3 9 9 ; 	=UGD%E7!;<	=r   c                    | j                   r8t        | j                         dkD  r dj                  | j                   d d       }n| j                   }dj                  | j                  | j                  | j
                  |      S )N   z{text}[...]rt   zKDirectMessage(ID={dm_id}, Sender={sender}, Created={time}, Text='{text!r}'))dm_idsendertimert   )rt   lenr    r   rs   rq   r   rt   s     r   rV   zDirectMessage.__repr__   so    99TYY#- ''TYYt_'=D99D\cc''>>	 d  	r   NrW   r5   r   r   ro   ro      s    1
=	r   ro   c                   ,    e Zd ZdZd Zd Zed        Zy)Trendz( A class representing a trending topic. c           	          d d d d d d d d| _         | j                   j                         D ]"  \  }}t        | ||j                  ||             $ y )N)eventsr`   promoted_contentquery	timestamprK   tweet_volumerM   rP   s       r   r   zTrend.__init__   s]     $ 
 !% 3 3 9 9 ; 	=UGD%E7!;<	=r   c                 d    dj                  | j                  | j                  | j                        S )Nz$Trend(Name={0!r}, Time={1}, URL={2}))r    r`   r   rK   r   s    r   rV   zTrend.__repr__   s*    5<<IINNHH 	r   c                     | j                   S r	   )r   r   s    r   volumezTrend.volume   s       r   N)r=   r>   r?   r@   r   rV   propertyr   r5   r   r   r~   r~      s#    2= ! !r   r~   c                       e Zd ZdZd Zd Zy)Hashtagz) A class representing a twitter hashtag. c           	          dd i| _         | j                   j                         D ]"  \  }}t        | ||j                  ||             $ y )Nrt   rM   rP   s       r   r   zHashtag.__init__   sM    D
 !% 3 3 9 9 ; 	=UGD%E7!;<	=r   c                 :    dj                  | j                        S )NzHashtag(Text={text!r})rw   )r    rt   r   s    r   rV   zHashtag.__repr__   s!    '.. /  	r   NrW   r5   r   r   r   r      s    3=r   r   c                       e Zd ZdZd Zd Zy)Urlz3 A class representing an URL contained in a tweet. c           	          d d d| _         | j                   j                         D ]"  \  }}t        | ||j                  ||             $ y )N)rF   rK   rM   rP   s       r   r   zUrl.__init__  sN      !% 3 3 9 9 ; 	=UGD%E7!;<	=r   c                 P    dj                  | j                  | j                        S )Nz"URL(URL={url}, ExpandedURL={eurl}))rK   eurl)r    rK   rF   r   s    r   rV   zUrl.__repr__
  s*    3::"" ; $ 	$r   NrW   r5   r   r   r   r      s    ==$r   r   c                   >    e Zd ZdZdddddddZd Zed        Zd Zy)
UserStatuszl A class representing the UserStatus structure. This is an abbreviated
    form of the twitter.User object. Fr\   followed_byfollowing_receivedfollowing_requestedblockingmutingc                     dddddd d dd d d
| _         | j                   j                         D ]"  \  }}t        | ||j                  ||             $ d|v r'| j                  D ]  }||d   v st        | |d        y y )NF)
r   r   r\   r   r   r   id_strr   r`   rh   connectionsT)r
   r)   rN   rO   _connectionsrP   s       r   r   zUserStatus.__init__  s     "'#(
 !% 3 3 9 9 ; 	=UGD%E7!;<	= F"** /F=11D%./ #r   c                     | j                   | j                  | j                  | j                  | j                  | j
                  dS )Nr   r   r   s    r   r   zUserStatus.connections2  s<    !^^#//&*&=&='+'?'? MM++' 	'r   c                     | j                   D cg c]  }t        | |      s| }}dj                  | j                  | j                  dj                  |            S c c}w )Nz;UserStatus(ID={uid}, ScreenName={sn}, Connections=[{conn}])z, )uidsnconn)r   r+   r    r   rh   join)r   rQ   r   s      r   rV   zUserStatus.__repr__;  s_    *.*:*:SgdE>RuSSLSS;' T ) 	) Ts
   AAN)	r=   r>   r?   r@   r   r   r   r   rV   r5   r   r   r   r     s@    ) "'#(*/+0 %#%L/, ' ')r   r   c                   8     e Zd ZdZd Zd Ze fd       Z xZS )re   z)A class representing the User structure. c           	      r   i dd dd dd dd dd dd dd dd d	d d
d dd dd dd dd dd dd dd i dd dd dd dd dd dd dd dd dd dd dd dd dd dd d d d!d d"d d d d d d d d#| _         | j                   j                         D ]"  \  }}t        | ||j                  ||             $ y )$Ncontributors_enabledrq   default_profiledefault_profile_imager[   emailfavourites_countfollowers_countr\   friends_countgeo_enabledr   r   langlisted_countlocationr`   notificationsprofile_background_colorprofile_background_image_url"profile_background_image_url_httpsprofile_background_tileprofile_banner_urlprofile_image_urlprofile_image_url_httpsprofile_link_colorprofile_sidebar_border_colorprofile_sidebar_fill_colorprofile_text_colorprofile_use_background_image	protectedrh   statusstatuses_count)	time_zonerK   
utc_offsetverifiedwithheld_in_countrieswithheld_scoperM   rP   s       r   r   zUser.__init__G  s   )
"D)
$)
 t)
 $T	)

 4)
 T)
 )
 t)
 )
 T)
 4)
 $)
 d)
 D)
 D)
  !)
" D#)
$ T%)
& '')
( +D))
* 1$+)
, &t-)
. !$/)
0  1)
2 &t3)
4 !$5)
6 +D7)
8 )$9)
: !$;)
< +D=)
> ?)
@ 4A)
B dC)
D dE)
F %)"Q)
V !% 3 3 9 9 ; 	=UGD%E7!;<	=r   c                 P    dj                  | j                  | j                        S )NzUser(ID={uid}, ScreenName={sn}))r   r   )r    r   rh   r   s    r   rV   zUser.__repr__v  s*    077 8 ! 	!r   c                     ddl m} |j                  dd       r1|j                  |j                  d            }t        | |   ||      S t        | |   |      S )Nr   )Statusr   )r0   r   )r0   )twitterr   rO   r<   super)r8   r0   r   r   r   	__class__s        r   r<   zUser.NewFromJsonDict{  sY    "88Hd#++DHHX,>?Fc2V2LLc22==r   )	r=   r>   r?   r@   r   rV   rA   r<   __classcell__r   s   @r   re   re   C  s%    3-=^!
 > >r   re   c                   H     e Zd ZdZd Zed        Zd Ze fd       Z	 xZ
S )r   zGA class representing the Status structure used by the twitter API.
    c           	         i dd dd dd dd dd dd dd dd d	d d
d dd dd dd dd dd dd dd i dd dd dd dd dd dd dd dd dd dd dd dd dd dd d d d!d d"d d#d i| _         | j                   j                         D ]"  \  }}t        | ||j                  ||             $ |j                  dd       rd$| _        y d%| _        y )&Ncontributorscoordinatesrq   current_user_retweetfavorite_count	favorited	full_textgeohashtagsr   r   in_reply_to_screen_namein_reply_to_status_idin_reply_to_user_idr   r   mediaplacepossibly_sensitivequoted_statusquoted_status_idquoted_status_id_strretweet_count	retweetedretweeted_statusscopessourcert   	truncatedurlsrd   user_mentionswithheld_copyrightr   r   extendedcompatibility)r
   r)   rN   rO   
tweet_moderP   s       r   r   zStatus.__init__  s   $
D$
4$
 $$
 #D	$

 d$
 $
 $
 4$
 $
 $$
 d$
 &t$
 $T$
 "4$
 D$
  !$
" T#$
$ T%$
& !$'$
( T)$
* +$
, #D-$
. T/$
0 1$
2 3$
4 d5$
6 d7$
8 D9$
: ;$
< D=$
> D?$
@ TA$
B !$C$
D $TE$
F dG$
L !% 3 3 9 9 ; 	=UGD%E7!;<	= ::k4((DO-DOr   c                 >    t        t        | j                              S )z Get the time this status message was posted, in seconds since
        the epoch (1 Jan 1970).

        Returns:
            int: The time this status message was posted, in seconds since
            the epoch.
        )r   r   rq   r   s    r   created_at_in_secondszStatus.created_at_in_seconds  s     i011r   c                 0   | j                   dk(  r| j                  }n| j                  }| j                  r<dj	                  | j
                  | j                  j                  | j                  |      S dj	                  | j
                  | j                  |      S )a   A string representation of this twitter.Status instance.
        The return value is the ID of status, username and datetime.

        Returns:
            string: A string representation of this twitter.Status instance with
            the ID of status, username and datetime.
        r   z7Status(ID={0}, ScreenName={1}, Created={2}, Text={3!r})z'Status(ID={0}, Created={1}, Text={2!r}))r   r   rt   rd   r    r   rh   rq   r|   s     r   rV   zStatus.__repr__  s     ??j(>>D99D99LSS		%%	  >DD r   c                    d}d}d}d}d}d}d}	d}
d|v r |d   j                         D ]
  \  }}|||<    d|v rt        j                  |d         }	d|v rt        j                  |d         }d|v r|d   d   }d|v r$t        j                  |j	                  d            }d|v rd	|d   v r(|d   d	   D cg c]  }t
        j                  |       }}d
|d   v r(|d   d
   D cg c]  }t        j                  |       }
}d|d   v r(|d   d   D cg c]  }t        j                  |       }}d|d   v r(|d   d   D cg c]  }t        j                  |       }}d|v r/d|d   v r(|d   d   D cg c]  }t        j                  |       }}t        | |   ||||||||	|
	      S c c}w c c}w c c}w c c}w c c}w )z Create a new instance based on a JSON dict.

        Args:
            data: A JSON dict, as converted from the JSON in the twitter API

        Returns:
            A twitter.Status instance
        Nextended_tweetrd   r   r   r   r   entitiesr   r   r   r   extended_entities)	r0   r   r   r   r   r   r   rd   r   )	r)   re   r<   r   rO   r   r   rC   r   )r8   r0   r   r   r   r   r   r   r   rd   r   kvuhmr   s                   r   r<   zStatus.NewFromJsonDict  sD     $ t#-.446 1Q T>''V5D%%55d;M6NO!T)#'(>#?#E d""22488O3LMMj))8<Z8H8PQ1++A.QQ$z"22BFzBRSbBc dQ!5!5a!8 d dT*--@DZ@PQ[@\]1G33A6]]$z**;?
;KG;TUa..q1UU $&$233;?@S;TU\;]^a..q1^^S#.DDX8@5:=J@P4848=J / L 	L R d]U
 _s   7F-&F2F7F<7G)r=   r>   r?   r@   r   r   r   rV   rA   r<   r   r   s   @r   r   r     s=    -.^ 2 20 7L 7Lr   r   )
__future__r   r&   calendarr   rfc822r   ImportErroremail.utilsobjectr   rC   rY   rj   ro   r~   r   r   r   re   r   r5   r   r   <module>r      s    '  & 
R6 Rj"L "8(< (B| *L 8!L !:l "$, $$0) 0)f?>< ?>DNL\ NLy  &%&s   B B B 