def get_paging_service(chamber, limit): from sunlight.pagination import PagingService paging_service = PagingService(congress) members = list(paging_service.legislators(chamber=chamber, limit=limit)) return members
class TestPagingService(unittest.TestCase): def setUp(self): self.congress = Congress() self.paginator = PagingService(self.congress) def test_non_pageable_service(self): """Services that are not pageable should result in an exception being raised when instantiating the PagingService. """ with self.assertRaises(ValueError): PagingService(OpenCivic()) def test_paging_past_end(self): """Test that requesting a page past the end of the possible results will return a generator of length 0, instead of raising an exception. """ kwargs = { 'chamber': 'senate', 'page': 1000 } self.assertEqual(0, len(list(self.paginator.legislators(**kwargs)))) def test_limit_too_high(self): """When setting the limit too high on a request, it should return only as many results as exist. """ kwargs = { 'chamber': 'senate', 'limit': 101 } self.assertEqual(100, len(list(self.paginator.legislators(**kwargs))))
def test_non_pageable_service(self): """Services that are not pageable should result in an exception being raised when instantiating the PagingService. """ with self.assertRaises(ValueError): PagingService(OpenCivic())
def fetch_bills_info(): """ downlaods bill metadata from the sunlight api currently it downloads all the bills available in sunlight api consider supporting other filters in the future, like time ..etc """ congress = Congress() congress = PagingService(congress) results = list (congress.bills(fields="versions,history,title,urls,id" ,limit=sys.maxint ) ) return results
def setUp(self): self.congress = Congress() self.paginator = PagingService(self.congress)
from sunlight.pagination import PagingService from raven import Client as Raven from .models import connection from .schedule import delay_until_local from norrin import settings from norrin.util import day_before, yesterday, format_billid logger = logging.getLogger('norrin.notifications') airship = ua.Airship(settings.UA_KEY, settings.UA_MASTER) # terrible, terrible hack because of no sslv3 import sunlight.services.congress sunlight.services.congress.API_ROOT = 'http://congress.api.sunlightfoundation.com' congress = PagingService(congress) class AdapterRegistry(object): def __init__(self): self._adapters = [] def __iter__(self): for adapter in self._adapters: yield adapter def register(self, adapter): if isinstance(adapter, type): adapter = adapter() if adapter not in self._adapters: self._adapters.append(adapter)