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)
The will return a dictionary 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
from prettytable import PrettyTable
x = PrettyTable()
td = get_poll_data(
"https://www.realclearpolitics.com/epolls/other/president_trump_job_approval-6179.html"
)
x.field_names = list(td[0]["data"][0].keys())
x.align = "l"
for row in td[0]["data"]:
x.add_row(row.values())
print(x)
Metadata
Release files for realclearpolitics 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| realclearpolitics-1.4.0.tar.gz | 4.3 kB | Without provenance | Details for realclearpolitics-1.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| realclearpolitics-1.4.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for realclearpolitics-1.4.0-py2.py3-none-any.whl |
Total release size: 9.0 kB
Release files / realclearpolitics-1.4.0.tar.gz
| Download URL | realclearpolitics-1.4.0.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fdc1a865fb3606c8692d4db1f4e0294b6793af2a52ef63753c627cb66c6bfe21
|
|
BLAKE2b-256 checksum How to use checksums |
c51f0a736b5fdd8f1538cde898209af9414a7fd0cb16660b18fbe37befd464c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7
|
Release files / realclearpolitics-1.4.0-py2.py3-none-any.whl
| Download URL | realclearpolitics-1.4.0-py2.py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
59da79127a8ad33cca3236ce0c2acf75eb37b72f041bbae2ecde69c1142affb0
|
|
BLAKE2b-256 checksum How to use checksums |
56eb5db2722b89c6198ad5f6fac4cebc7a491345269a77aa6a4fa46192183228
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7
|
Security for realclearpolitics 1.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.