<s> """<STR_LIT>""" <EOL> import logging <EOL> import re <EOL> from urllib . parse import urljoin <EOL> from bs4 import BeautifulSoup <EOL> import requests <EOL> LOGGER = logging . getLogger ( __name__ ) <EOL> class Site ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , url_base , url_archive , paste_tag , target_patterns , paste ) : <EOL> self . url_base = url_base <EOL> self . url_archive = url_archive <EOL> self . paste_tag = paste_tag <EOL> self . target_patterns = target_patterns <EOL> self . headers = { '<STR_LIT>' : '<STR_LIT>' '<STR_LIT>' } <EOL> self . paste = paste <EOL> def get ( self ) : <EOL> """<STR_LIT>""" <EOL> req = requests . get ( self . url_base + self . url_archive , headers = self . headers ) <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> while req . status_code != <NUM_LIT:200> : <EOL> LOGGER . error ( '<STR_LIT>' ) <EOL> req = requests . get ( self . url_base + self . url_archive ) <EOL> soup = BeautifulSoup ( req . text , '<STR_LIT>' ) <EOL> links = soup . find_all ( self . paste_tag ) <EOL> LOGGER . debug ( '<STR_LIT>' , len ( links ) ) <EOL> return [ self . paste ( urljoin ( self . url_base , link . a . get ( '<STR_LIT>' ) ) ) for link in links ] <EOL> def get_paste ( self , paste ) : <EOL> """<STR_LIT>""" <EOL> req = requests . get ( paste . url , headers = self . headers ) <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> while req . status_code != <NUM_LIT:200> : <EOL> LOGGER . error ( '<STR_LIT>' ) <EOL> req = requests . get ( paste . url ) <EOL> found = [ ] <EOL> for name , pattern in self . target_patterns : <EOL> LOGGER . debug ( '<STR_LIT>' , pattern ) <EOL> matches = re . findall ( pattern , req . text ) <EOL> LOGGER . debug ( '<STR_LIT>' , len ( matches ) ) <EOL> if matches : <EOL> found . append ( ( name , len ( matches ) ) ) <EOL> return found <EOL> class Paste ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , url ) : <EOL> _id = url . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] <EOL> self . _id = _id <EOL> class PastebinPaste ( Paste ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , url ) : <EOL> super ( ) . __init__ ( url ) <EOL> self . url = '<STR_LIT>' . format ( self . _id ) <EOL> class PastiePaste ( Paste ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , url ) : <EOL> super ( ) . __init__ ( url ) <EOL> self . url = '<STR_LIT>' . format ( self . _id ) <EOL> class SlexyPaste ( Paste ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , url ) : <EOL> super ( ) . __init__ ( url ) <EOL> self . url = '<STR_LIT>' . format ( self . _id ) <EOL> class Pastebin ( Site ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , target_patterns ) : <EOL> self . url_base = '<STR_LIT>' <EOL> self . url_archive = '<STR_LIT>' <EOL> self . paste_tag = lambda tag : tag . name == '<STR_LIT>' and tag . a and '<STR_LIT>' not in tag . a [ '<STR_LIT>' ] and tag . a [ '<STR_LIT>' ] [ <NUM_LIT:1> : ] <EOL> super ( ) . __init__ ( self . url_base , self . url_archive , self . paste_tag , target_patterns , <EOL> PastebinPaste ) <EOL> class Pastie ( Site ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , target_patterns ) : <EOL> self . url_base = '<STR_LIT>' <EOL> self . url_archive = '<STR_LIT>' <EOL> self . paste_tag = lambda tag : tag . name == '<STR_LIT:p>' and tag . a and self . url_base in tag . a [ '<STR_LIT>' ] <EOL> super ( ) . __init__ ( self . url_base , self . url_archive , self . paste_tag , target_patterns , <EOL> PastiePaste ) <EOL> class Slexy ( Site ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , target_patterns ) : <EOL> self . url_base = '<STR_LIT>' <EOL> self . url_archive = '<STR_LIT>' <EOL> self . paste_tag = lambda tag : tag . name == '<STR_LIT>' and tag . a and '<STR_LIT>' in tag . a [ '<STR_LIT>' ] <EOL> super ( ) . __init__ ( self . url_base , self . url_archive , self . paste_tag , target_patterns , <EOL> SlexyPaste ) </s>
