Beispiel #1
0
    def scrape_stands4():

        # make api call
        scrape_url = 'http://www.stands4.com/services/v2/quotes.php?'
        params = {
            'uid': config.stands4_id,
            'tokenid': config.stands4_token,
            'searchtype': 'RANDOM'
        }

        full_url = scrape_url + '&'.join(
            ['{0}={1}'.format(key, val) for key, val in params.iteritems()])

        res = requests.get(full_url)

        # process res data
        res_tree = ElementTree.fromstring(res.content)

        quote_text = res_tree.find('result').find('quote').text
        quote_author = res_tree.find('result').find('author').text

        # create quote model instance
        quote = Quote.create(quote_text=quote_text.strip(),
                             author=quote_author.strip())

        # store quote
        quote.save()
Beispiel #2
0
    def scrape_brainy(cls):

        brainyquote_base_url = 'https://www.brainyquote.com'

        # make api call
        scrape_url = 'https://www.brainyquote.com/api/rand_q'
        res = requests.get(scrape_url)

        # unescape the result before deserializing json result
        res_json_string = cls.unescape_string(res.text)

        # process res data
        try:
            quote_data = json.loads(res_json_string)
        except:
            ErrorLog.log_exception('json.loads() fail with res json str: ' +
                                   res_json_string)
            sys.exit()

        # create quote model instance
        quote = Quote.create(quote_text=quote_data['qt'].strip(),
                             author=quote_data['an'].strip(),
                             source_url=brainyquote_base_url +
                             quote_data['q_url'].strip())

        # store quote
        quote.save()
Beispiel #3
0
    def scrape_forismatic(cls):

        # make api call
        scrape_url = 'http://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en'
        res = requests.get(scrape_url)

        # unescape the result before deserializing json result
        res_json_string = cls.unescape_string(res.text)

        # process res data
        try:
            quote_data = json.loads(res_json_string)
        except:
            ErrorLog.log_exception('json.loads() fail with res json str: ' +
                                   res_json_string)
            sys.exit()

        # create quote model instance
        quote = Quote.create(quote_text=quote_data['quoteText'].strip(),
                             author=quote_data['quoteAuthor'].strip(),
                             source_url=quote_data['quoteLink'].strip())

        # store quote
        quote.save()