realclearpolitics


Namerealclearpolitics JSON
Version 1.4.0 PyPI version JSON
download
home_pagehttps://github.com/AnthonyBloomer/rcp
SummaryPython client for RealClearPolitics.
upload_time2020-07-06 13:37:31
maintainer
docs_urlNone
authorAnthony Bloomer
requires_python
license
keywords politics polls rcp realclearpolitics web scraping
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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:

.. code-block:: python

    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:

.. code-block::


    [
        {
            '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:

.. code-block:: python

    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:

.. code-block:: python

    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)

.. |Build Status| image:: https://travis-ci.org/AnthonyBloomer/rcp.svg?branch=master
   :target: https://travis-ci.org/AnthonyBloomer/rcp

.. |codecov| image:: https://codecov.io/gh/AnthonyBloomer/rcp/branch/master/graph/badge.svg
   :target: https://codecov.io/gh/AnthonyBloomer/rcp



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AnthonyBloomer/rcp",
    "name": "realclearpolitics",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "politics,polls,rcp,realclearpolitics,web scraping",
    "author": "Anthony Bloomer",
    "author_email": "ant0@protonmail.ch",
    "download_url": "https://files.pythonhosted.org/packages/c5/1f/0a736b5fdd8f1538cde898209af9414a7fd0cb16660b18fbe37befd464c7/realclearpolitics-1.4.0.tar.gz",
    "platform": "",
    "description": "rcp\n===\n\n|Build Status| |codecov|\n\nPython client for RealClearPolitics. \n\nInstall\n^^^^^^^\n\n::\n\n    pip install realclearpolitics\n\nUsage\n^^^^^\n\n::\n\n    usage: rcp [-h] [--output [OUTPUT]] [--generate-table] url [url ...]\n\n    positional arguments:\n      url                The url of the polling data.\n\n    optional arguments:\n      -h, --help         show this help message and exit\n      --output [OUTPUT]  The output file name.\n      --generate-table   Pass this argument to generate a table.\n\n\n\nExamples\n^^^^^^^^\n\nGet the US general election results.\n\n::\n\n    rcp http://www.realclearpolitics.com/epolls/2016/president/us/general_election_trump_vs_clinton-5491.html --output general.csv\n\nDownload multiple polls.\n\n::\n\n    rcp http://www.realclearpolitics.com/epolls/2016/president/us/general_election_trump_vs_clinton-5491.html \\\n    > https://www.realclearpolitics.com/epolls/other/president_trump_job_approval_economy-6182.html \\\n    > https://www.realclearpolitics.com/epolls/other/president_trump_job_approval_foreign_policy-6183.html\n\nAPI Usage\n^^^^^^^^^\n\nSearch for Fox News poll numbers for Trump:\n\n.. code-block:: python\n\n    from rcp import get_polls, get_poll_data\n    from pprint import pprint\n\n    polls = get_polls(candidate=\"Trump\", pollster=\"Fox\")\n\n    for poll in polls:\n        td = get_poll_data(poll['url'])\n        pprint(td)\n\nThe will return a dictionary structured like this:\n\n.. code-block::\n\n\n    [\n        {\n            'data': [{'Biden (D)': '49.6',\n                    'Date': '3/27 - 7/9',\n                    'MoE': '--',\n                    'Poll': 'RCP Average',\n                    'Sample': '--',\n                    'Spread': 'Biden +8.5',\n                    'Trump (R)': '41.1'},\n            ...\n            }],\n        'poll': 'https://www.realclearpolitics.com/epolls/2020/president/us/general_election_trump_vs_biden-6247.html'\n\n    ]\n\nWrite a poll to CSV:\n\n.. code-block:: python\n\n    from rcp import get_polls, get_poll_data, to_csv\n\n    polls = get_polls(candidate=\"Biden\")[0]\n    data = get_poll_data(polls['url'], csv_output=True)\n    to_csv('output.csv', data)\n\nCreate table:\n\n.. code-block:: python\n\n    from rcp import get_poll_data\n    from prettytable import PrettyTable\n\n    x = PrettyTable()\n\n    td = get_poll_data(\n        \"https://www.realclearpolitics.com/epolls/other/president_trump_job_approval-6179.html\"\n    )\n\n    x.field_names = list(td[0][\"data\"][0].keys())\n    x.align = \"l\"\n\n    for row in td[0][\"data\"]:\n        x.add_row(row.values())\n\n    print(x)\n\n.. |Build Status| image:: https://travis-ci.org/AnthonyBloomer/rcp.svg?branch=master\n   :target: https://travis-ci.org/AnthonyBloomer/rcp\n\n.. |codecov| image:: https://codecov.io/gh/AnthonyBloomer/rcp/branch/master/graph/badge.svg\n   :target: https://codecov.io/gh/AnthonyBloomer/rcp\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Python client for RealClearPolitics.",
    "version": "1.4.0",
    "split_keywords": [
        "politics",
        "polls",
        "rcp",
        "realclearpolitics",
        "web scraping"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "1dcea4eb0e0fe9550592cc9d53c8794a",
                "sha256": "59da79127a8ad33cca3236ce0c2acf75eb37b72f041bbae2ecde69c1142affb0"
            },
            "downloads": -1,
            "filename": "realclearpolitics-1.4.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1dcea4eb0e0fe9550592cc9d53c8794a",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 4740,
            "upload_time": "2020-07-06T13:37:29",
            "upload_time_iso_8601": "2020-07-06T13:37:29.613594Z",
            "url": "https://files.pythonhosted.org/packages/56/eb/5db2722b89c6198ad5f6fac4cebc7a491345269a77aa6a4fa46192183228/realclearpolitics-1.4.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "7beea64a84c2c87d9e3996eacac631e9",
                "sha256": "fdc1a865fb3606c8692d4db1f4e0294b6793af2a52ef63753c627cb66c6bfe21"
            },
            "downloads": -1,
            "filename": "realclearpolitics-1.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7beea64a84c2c87d9e3996eacac631e9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4267,
            "upload_time": "2020-07-06T13:37:31",
            "upload_time_iso_8601": "2020-07-06T13:37:31.086782Z",
            "url": "https://files.pythonhosted.org/packages/c5/1f/0a736b5fdd8f1538cde898209af9414a7fd0cb16660b18fbe37befd464c7/realclearpolitics-1.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-07-06 13:37:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "AnthonyBloomer",
    "error": "Could not fetch GitHub repository",
    "lcname": "realclearpolitics"
}
        
Elapsed time: 0.10127s