Coder Social home page Coder Social logo

rcp's Introduction

rcp

Build Status codecov

Python client for RealClearPolitics.

Install

pip install realclearpolitics

Usage

usage: rcp [-h] [--output [OUTPUT]] [--generate-table] url [url ...]

positional arguments:
  url                The url of the polling data.

optional arguments:
  -h, --help         show this help message and exit
  --output [OUTPUT]  The output file name.
  --generate-table   Pass this argument to generate a table.

Examples

Get the US general election results.

rcp http://www.realclearpolitics.com/epolls/2016/president/us/general_election_trump_vs_clinton-5491.html --output general.csv

Download multiple polls.

rcp http://www.realclearpolitics.com/epolls/2016/president/us/general_election_trump_vs_clinton-5491.html \
> https://www.realclearpolitics.com/epolls/other/president_trump_job_approval_economy-6182.html \
> https://www.realclearpolitics.com/epolls/other/president_trump_job_approval_foreign_policy-6183.html

API Usage

Search for Fox News poll numbers for Trump:

from rcp import get_polls, get_poll_data
from pprint import pprint

polls = get_polls(candidate="Trump", pollster="Fox")

for poll in polls:
    td = get_poll_data(poll['url'])
    pprint(td)

This function will return data structured like this:

[
    {
        'data': [{'Biden (D)': '49.6',
                'Date': '3/27 - 7/9',
                'MoE': '--',
                'Poll': 'RCP Average',
                'Sample': '--',
                'Spread': 'Biden +8.5',
                'Trump (R)': '41.1'},
        ...
        }],
    'poll': 'https://www.realclearpolitics.com/epolls/2020/president/us/general_election_trump_vs_biden-6247.html'

]

Write a poll to CSV:

from rcp import get_polls, get_poll_data, to_csv

polls = get_polls(candidate="Biden")[0]
data = get_poll_data(polls['url'], csv_output=True)
to_csv('output.csv', data)

Create table:

from rcp import get_poll_data, create_table

 td = get_poll_data(
     "https://www.realclearpolitics.com/epolls/2020/president/me/maine_trump_vs_biden-6922.html"
 )

 print(create_table(td, html_format=True))

rcp's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.