示例#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
示例#2
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