示例#1
0
 def test_nonsite_parameter(self):
     """Testing that it can retrieve data on end points that don't want
     the `site` parameter. Tested using Jeff Atwood's user id"""
     with patch('stackapi.StackAPI.fetch', fake_stackoverflow_exists) as mock_site:
         site = StackAPI('stackoverflow')
     site._api_key = None
     with patch('stackapi.StackAPI.fetch', fake_users) as mock_users:
         self.assertGreaterEqual(len(site.fetch('/users/1/associated')['items']), 1)
示例#2
0
    def test_exceptions_thrown(self):
        """Testing that a StackAPIError is properly thrown

        This test hits the real API."""
        with self.assertRaises(StackAPIError) as cm:
            site = StackAPI('stackoverflow')
            site._api_key = None
            site.fetch('errors/400')
        self.assertEqual(cm.exception.error, 400)
        self.assertEqual(cm.exception.code, 'bad_parameter')
示例#3
0
 def test_nonsite_parameter(self):
     """Testing that it can retrieve data on end points that don't want
     the `site` parameter. Tested using Jeff Atwood's user id"""
     with patch('stackapi.StackAPI.fetch',
                fake_stackoverflow_exists) as mock_site:
         site = StackAPI('stackoverflow')
     site._api_key = None
     with patch('stackapi.StackAPI.fetch', fake_users) as mock_users:
         self.assertGreaterEqual(
             len(site.fetch('/users/1/associated')['items']), 1)
示例#4
0
    def test_exceptions_thrown(self):
        """Testing that a StackAPIError is properly thrown

        This test hits the real API."""
        with self.assertRaises(StackAPIError) as cm:
            site = StackAPI('stackoverflow')
            site._api_key = None
            site.fetch('errors/400')
        self.assertEqual(cm.exception.error, 400)
        self.assertEqual(cm.exception.code, 'bad_parameter')
示例#5
0
def _get_api(**kwargs):
    # TODO FIXME max_page documentation is wrong, it's 5 by default?
    kinda_infinity = 1_000_000
    # api = StackAPI('stackoverflow', max_pages=kinda_infinity)

    api = StackAPI('stackoverflow', **kwargs)
    # right. not sure if there is any benefit in using authorised user? not that much data is private

    api._name = None
    api._api_key = None
    return api
示例#6
0
# Let's find the text of the answers first.
# For that, we need access to the stack exchange API

import csv
import html
import json
import sys

from stackapi import StackAPI

API = StackAPI('stackoverflow')
API._api_key = None

FIELDS = [
    '.backoff',
    '.error_id',
    '.error_message',
    '.error_name',
    '.has_more',
    '.items',
    '.quota_max',
    '.quota_remaining',
    'answer.answer_id',
    'answer.body_markdown',
]

FILTER = API.fetch('filters/create', base='none',
                   include=';'.join(FIELDS))['items'][0]['filter']

MS = StackAPI('medicalsciences')