Ejemplo n.º 1
0
    def get_data(self):
        '''Returns the JSON file with data on images.'''
        client_id = Parser().config.get("imgur")
        if not client_id.get("client_id"):
            headers = {
                "Authorization": "Client-ID 53bdf7a3b30690b"
            }
        else:
            headers = {
                "Authorization": "Client-ID {}".format(
                    client_id.get("client_id")
                )
            }

        params = {
            "include": "media,tags,account"
        }
        match = re.match(self.valid_url, self.link)
        imgur_id = match.group('id')
        if not match.group("col"):
            url = "https://api.imgur.com/post/v1/media/{}".format(imgur_id)
        else:
            url = "https://api.imgur.com/post/v1/albums/{}".format(imgur_id)

        r = requests.get(url, headers=headers, params=params)
        if r.status_code == requests.codes.ok:
            return r.json()

        self.logger.warning("Imgur API returns a bad status code: {}".format(r.status_code))
        return None
Ejemplo n.º 2
0
    def __init__(self):
        self.logger = logging.getLogger(__name__)

        parser = Parser()
        self.config = parser.config
        self.reddit = None
        self.start_reddit()
Ejemplo n.º 3
0
    def load_config(self):
        parser = Parser()
        data = parser.config

        try:
            int(data["media_download"]["retries"])
            int(data["media_download"]["wait_time"])
            self.retries = data["media_download"]["retries"]
            self.wait_time = data["media_download"]["wait_time"]

        except TypeError:
            self.logger.warning(
                "TypeError: Media download retries or wait time is not an integer."
            )
            self.retries = 5
            self.wait_time = 60
Ejemplo n.º 4
0
    def get_data(self):
        '''Returns the JSON file with data on images.'''
        imgur_cookie = Parser().config.get("imgur")
        if not imgur_cookie:
            imgur_cookie = {}
        else:
            imgur_cookie = {
                "Cookie":
                "authautologin={};".format(imgur_cookie.get("authautologin"))
            }

        page_html = self.get_html(imgur_cookie)
        if page_html:
            page_html_text = page_html.text
            data_string = re.search('image( ){15}: (?P<data>(.)+)',
                                    page_html_text)
            if data_string:
                data = data_string.group('data')[:-1]
                data = json.loads(data)
                return data
        self.logger.warning("Imgur album page returning None")
        return None
Ejemplo n.º 5
0
                with open(filepath) as f:
                    line = f.readline()
                    while line:
                        subR = "{}".format(line.strip())
                        feeder(subR, parser)
                        line = f.readline()
            else:
                feeder(subR, parser)
            if parser.cycles > 1:
                logger.info("Waiting {} seconds".format(parser.wait))
                time.sleep(parser.wait)
            current_cycle += 1


if __name__ == '__main__':
    parser = Parser()

    config = parser.config

    # verbose / logger
    log_path = config['general']['log_file']
    log_path = os.path.dirname(log_path)
    if not os.path.exists(log_path):
        os.makedirs(log_path)
    if config["general"]["logger_append"]:
        filemode = 'a'
    else:
        filemode = 'w'
    if config['general']['log_timestamp']:
        now = datetime.now()
        log_path = config['general']['log_file']