Exemplo n.º 1
0
class TestCapitolWords(unittest.TestCase):

    def setUp(self):
        self.phrases_kwargs = {
            'entity_type': 'legislator',
            'entity_value':  'L000551'
        }
        self.service = CapitolWords()

    def test__get_url(self):
        '''This is probably a bad idea and should be replaced.'''
        url = self.service._get_url(['phrases'],
                                    sunlight.config.API_KEY,
                                    **self.phrases_kwargs)

        expected_hostname = 'capitolwords.org'
        expected_path = '/api/1/phrases.json'
        expected_query = {
            'apikey': sunlight.config.API_KEY
        }
        expected_query.update(self.phrases_kwargs)

        parsed_url = urlparse(url)
        parsed_query = dict(parse_qsl(parsed_url.query))

        self.assertEqual(parsed_url.hostname, expected_hostname)
        self.assertEqual(parsed_url.path, expected_path)
        self.assertDictEqual(parsed_query, expected_query)

    def test_dates(self):
        results = self.service.dates('Obamacare')
        self.assertNotEqual(len(results), 0)

    def test_phrases_by_entity(self):
        results = self.service.phrases_by_entity('state', phrase='Obamacare')
        self.assertNotEqual(len(results), 0)

    def test_legislator_phrases(self):
        results = self.service.phrases(
            self.phrases_kwargs['entity_type'],
            self.phrases_kwargs['entity_value'])

        self.assertNotEqual(len(results), 0)

    def test_text(self):
        results = self.service.text('Christmas')
        self.assertNotEqual(len(results), 0)

    def test_text_title(self):
        results = self.service.text(title='Christmas')
        self.assertNotEqual(len(results), 0)

    def test_text_bad_request(self):
        with self.assertRaises(BadRequestException):
            self.service.text()
Exemplo n.º 2
0
    try:
        with open('capitolwords.csv') as f:
            reader = csv.reader(f)
            for i, r in enumerate(reader):
                pass
            return i - 1
    except:
        return 0
 
if __name__ == "__main__":
    if len(sys.argv) > 2:
        outfile = sys.argv[1]
    else:
        outfile = "capitolwords.csv"
 
    cw = CapitolWords()
    start_date = '2013-01-03'
    end_date = '2014-12-16'
    sort = "date asc"
    results = cw.text(phrase=" ", start_date=start_date, sort=sort)
    if len(results) > 1:
        headers = results[0].keys()
    else:
        print("Not found")
        sys.exit()
 
    nrow = csv_rowcount(outfile)
    print nrow
    if nrow > 0:
        start = nrow
        f = open(outfile, "ab")
Exemplo n.º 3
0
    try:
        with open('capitolwords.csv') as f:
            reader = csv.reader(f)
            for i, r in enumerate(reader):
                pass
            return i - 1
    except:
        return 0

if __name__ == "__main__":
    if len(sys.argv) > 2:
        outfile = sys.argv[1]
    else:
        outfile = "capitolwords.csv"

    cw = CapitolWords()
    start_date = '2013-01-03'
    end_date = '2015-01-03'
    #end_date = datetime.today().strftime('%Y-%m-%d')
    sort = "date asc"
    results = cw.text(phrase=" ", start_date=start_date, end_date=end_date, sort=sort)
    if len(results) > 1:
        headers = results[0].keys()
    else:
        print("Not found")
        sys.exit()

    nrow = csv_rowcount(outfile)
    print nrow
    if nrow > 0:
        start = nrow
Exemplo n.º 4
0
 def setUp(self):
     self.phrases_kwargs = {
         'entity_type': 'legislator',
         'entity_value':  'L000551'
     }
     self.service = CapitolWords()