
    Xh$                     H    d Z ddlZddlZddlZ G d d      Z G d d      Zy)zSherlock Sites Information Module

This module supports storing information about websites.
This is the raw data that will be used to search for usernames.
    Nc                   <    e Zd Z ej                  d      fdZd Zy)SiteInformation
   c                     || _         || _        || _        || _        t	        j
                  d      | _        || _        || _        y)a  Create Site Information Object.

        Contains information about a specific website.

        Keyword Arguments:
        self                   -- This object.
        name                   -- String which identifies site.
        url_home               -- String containing URL for home of site.
        url_username_format    -- String containing URL for Username format
                                  on site.
                                  NOTE:  The string should contain the
                                         token "{}" where the username should
                                         be substituted.  For example, a string
                                         of "https://somesite.com/users/{}"
                                         indicates that the individual
                                         usernames would show up under the
                                         "https://somesite.com/users/" area of
                                         the website.
        username_claimed       -- String containing username which is known
                                  to be claimed on website.
        username_unclaimed     -- String containing username which is known
                                  to be unclaimed on website.
        information            -- Dictionary containing all known information
                                  about website.
                                  NOTE:  Custom information about how to
                                         actually detect the existence of the
                                         username will be included in this
                                         dictionary.  This information will
                                         be needed by the detection method,
                                         but it is only recorded in this
                                         object for future use.
        is_nsfw                -- Boolean indicating if site is Not Safe For Work.

        Return Value:
        Nothing.
            N)	nameurl_homeurl_username_formatusername_claimedsecretstoken_urlsafeusername_unclaimedinformationis_nsfw)selfr   r	   r
   r   r   r   r   s           >/var/www/betterdocs.net/sherlock_api/sherlock_project/sites.py__init__zSiteInformation.__init__   sH    N 	 #6  0")"7"7";&    c                 :    | j                    d| j                   dS )zConvert Object To String.

        Keyword Arguments:
        self                   -- This object.

        Return Value:
        Nicely formatted string to get information about this object.
        z ())r   r	   r   s    r   __str__zSiteInformation.__str__=   s     ))Bt}}oQ//r   N)__name__
__module____qualname__r   r   r   r    r   r   r   r   
   s    9N9N9Nr9R0d
0r   r   c                   6    e Zd ZddZg fdefdZd Zd Zd Zy)	SitesInformationNc                    |sd}|j                         j                  d      st        d| d      |j                         j                  d      rG	 t	        j
                  |      }|j                  d
k7  rt        d| d      	 |j                         }n/	 t        |dd      5 }	 t        j                  |      }	 d	d	d	       j                  dd	       i | _        |D ]H  }	 t        |||   d   ||   d   ||   d   ||   ||   j                  dd            | j                  |<   J y	# t        $ r}t        d| d|       d	}~ww xY w# t        $ r}t        d| d| d      d	}~ww xY w# t        $ r}t        d| d| d      d	}~ww xY w# 1 sw Y   xY w# t        $ r t        d| d      w xY w# t        $ r}t        d| d| d      d	}~wt         $ r t#        d| d| d       Y w xY w)a  Create Sites Information Object.

        Contains information about all supported websites.

        Keyword Arguments:
        self                   -- This object.
        data_file_path         -- String which indicates path to data file.
                                  The file name must end in ".json".

                                  There are 3 possible formats:
                                   * Absolute File Format
                                     For example, "c:/stuff/data.json".
                                   * Relative File Format
                                     The current working directory is used
                                     as the context.
                                     For example, "data.json".
                                   * URL Format
                                     For example,
                                     "https://example.com/data.json", or
                                     "http://example.com/data.json".

                                  An exception will be thrown if the path
                                  to the data file is not in the expected
                                  format, or if there was any problem loading
                                  the file.

                                  If this option is not specified, then a
                                  default site list will be used.

        Return Value:
        Nothing.
        zghttps://raw.githubusercontent.com/sherlock-project/sherlock/master/sherlock_project/resources/data.jsonz.jsonz-Incorrect JSON file extension for data file 'z'.http)urlz2Problem while attempting to access data file URL 'z':  N   z,Bad response while accessing data file URL 'z"Problem parsing json contents at '.rzutf-8)encodingz.Problem while attempting to access data file 'z$schemaurlMainr!   r   isNSFWFz':  Missing attribute z8Encountered TypeError parsing json contents for target 'z' at z
Skipping target.
)lowerendswithFileNotFoundError
startswithrequestsget	Exceptionstatus_codejson
ValueErroropenloadpopsitesr   KeyError	TypeErrorprint)r   data_file_pathresponseerror	site_datafile	site_names          r   r   zSitesInformation.__init__K   s   D  GN ##%..w7#&STbScce$fgg !,,V4#<<N; ##s*' +::H9I)M * *$MMO	*.#@ D$(IIdO	 	i&
 # 	GIG $I$-i$8$C$-i$8$?$-i$89K$L$-i$8$-i$8$<$<Xe$L& 

9%	G& 	q  'HHXX\]b\cd    88HUGSTU  % (@@PPTUZT[[\]   % *' +66D5ER)I * **,   88HH^_d^eefg   GPQZP[[`ao`p  qE  F  GGs   D/ E F# (F*E4 F# 'AF?/	E8E		E	E1E,,E14	F=FFFF F# #F<?	G<GG<;G<do_not_removec                     i }|D cg c]  }|j                          }}| j                  D ]@  }| j                  |   j                  r|j                         |vr/| j                  |   ||<   B || _        yc c}w )z
        Remove NSFW sites from the sites, if isNSFW flag is true for site

        Keyword Arguments:
        self                   -- This object.

        Return Value:
        None
        N)casefoldr5   r   )r   r?   r5   sites       r   remove_nsfw_sitesz"SitesInformation.remove_nsfw_sites   sx     5BCTCCJJ 	+Dzz$''DMMO=,P**T*E$K	+ 
 Ds   A7c                 r    t        | D cg c]  }|j                   c}t        j                        S c c}w )zGet Site Name List.

        Keyword Arguments:
        self                   -- This object.

        Return Value:
        List of strings containing names of sites.
        )key)sortedr   strr(   )r   rB   s     r   site_name_listzSitesInformation.site_name_list   s'     T2Ttyy2		BB2s   4c              #   P   K   | j                   D ]  }| j                   |     yw)zIterator For Object.

        Keyword Arguments:
        self                   -- This object.

        Return Value:
        Iterator for sites object.
        N)r5   )r   r>   s     r   __iter__zSitesInformation.__iter__   s*       	(I**Y''	(s   $&c                 ,    t        | j                        S )zLength For Object.

        Keyword Arguments:
        self                   -- This object.

        Return Value:
        Length of sites object.
        )lenr5   r   s    r   __len__zSitesInformation.__len__   s     4::r   )N)	r   r   r   r   listrC   rH   rJ   rM   r   r   r   r   r   J   s*    iV 79 t $
C(	r   r   )__doc__r0   r,   r   r   r   r   r   r   <module>rP      s,   
   =0 =0@` `r   