fantraxapi


Namefantraxapi JSON
Version 0.2.9 PyPI version JSON
download
home_pagehttps://github.com/meisnate12/FantraxAPI
SummaryA lightweight Python library for The Fantrax API.
upload_time2024-10-15 20:52:19
maintainerNone
docs_urlNone
authorNathan Taggart
requires_python>=3.8
licenseMIT License
keywords fantraxapi fantrax fantasy wrapper api
VCS
bugtrack_url
requirements requests setuptools
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Welcome to Fantrax Documentation!
==========================================================

.. image:: https://img.shields.io/github/v/release/meisnate12/FantraxAPI?style=plastic
    :target: https://github.com/meisnate12/FantraxAPI/releases
    :alt: GitHub release (latest by date)

.. image:: https://img.shields.io/github/actions/workflow/status/meisnate12/FantraxAPI/tests.yml?branch=master&style=plastic
    :target: https://github.com/meisnate12/FantraxAPI/actions/workflows/tests.yml
    :alt: Build Testing

.. image:: https://img.shields.io/codecov/c/github/meisnate12/FantraxAPI?color=greenred&style=plastic
    :target: https://codecov.io/gh/meisnate12/FantraxAPI
    :alt: Build Coverage

.. image:: https://img.shields.io/github/commits-since/meisnate12/FantraxAPI/latest?style=plastic
    :target: https://github.com/meisnate12/FantraxAPI/commits/master
    :alt: GitHub commits since latest release (by date) for a branch

.. image:: https://img.shields.io/pypi/v/FantraxAPI?style=plastic
    :target: https://pypi.org/project/FantraxAPI/
    :alt: PyPI

.. image:: https://img.shields.io/pypi/dm/FantraxAPI.svg?style=plastic
    :target: https://pypi.org/project/FantraxAPI/
    :alt: Downloads

.. image:: https://img.shields.io/readthedocs/plex-meta-manager?color=%2300bc8c&style=plastic
    :target: https://fantraxapi.metamanager.wiki/en/latest/
    :alt: Wiki

.. image:: https://img.shields.io/discord/822460010649878528?color=%2300bc8c&label=Discord&style=plastic
    :target: https://discord.gg/NfH6mGFuAB
    :alt: Discord

.. image:: https://img.shields.io/reddit/subreddit-subscribers/PlexMetaManager?color=%2300bc8c&label=r%2FPlexMetaManager&style=plastic
    :target: https://www.reddit.com/r/PlexMetaManager/
    :alt: Reddit

.. image:: https://img.shields.io/github/sponsors/meisnate12?color=%238a2be2&style=plastic
    :target: https://github.com/sponsors/meisnate12
    :alt: GitHub Sponsors

.. image:: https://img.shields.io/badge/-Sponsor_or_Donate-blueviolet?style=plastic
    :target: https://github.com/sponsors/meisnate12
    :alt: Sponsor or Donate


Overview
----------------------------------------------------------
Unofficial Python bindings for the Fantrax API. The goal is to make interaction with the API as easy as possible while emulating the endpoints as much as possible


Installation & Documentation
----------------------------------------------------------

.. code-block:: python

    pip install fantraxapi

Documentation_ can be found at Read the Docs.

.. _Documentation: https://fantraxapi.metamanager.wiki


Using the API
==========================================================

Getting a FantraxAPI Instance
----------------------------------------------------------

To connect to the Fantrax API you use the FantraxAPI object.

.. code-block:: python

    from fantraxapi import FantraxAPI

    league_id = "96igs4677sgjk7ol"

    api = FantraxAPI(league_id)


.. code-block:: python

    import fantraxapi

    api = fantraxapi.FantraxAPI()


Usage Examples
==========================================================

Example: Get the Scores for the Season.

.. code-block:: python

    from fantraxapi import FantraxAPI

    league_id = "96igs4677sgjk7ol"

    api = FantraxAPI(league_id)

    for _, scoring_period in api.scoring_periods().items():
        print("")
        print(scoring_period)


Connecting with a private League
==========================================================

I was unable to decipher the api login method so in order to connect to a private league or specific pages in a public
league that are not public you need to use a cookie. The code below uses Google Chrome and the :code:`selenium` and
:code:`webdriver-manager` packages to open a chrome instance where you can login and after 30 seconds a cookie file with
that login will be save to :code:`fantraxloggedin.cookie`.

First install the two packages:

.. code-block:: python

    pip install selenium
    pip install webdriver-manager

Second run the code below and login when the chrome window loads the Fantrax login page:

.. code-block:: python

    import pickle
    import time
    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service
    from selenium.webdriver.chrome.options import Options
    from webdriver_manager.chrome import ChromeDriverManager

    service = Service(ChromeDriverManager().install())

    options = Options()
    options.add_argument("--window-size=1920,1600")
    options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36")

    with webdriver.Chrome(service=service, options=options) as driver:
        driver.get("https://www.fantrax.com/login")
        time.sleep(30)
        pickle.dump(driver.get_cookies(), open("fantraxloggedin.cookie", "wb"))


Third use the saved cookie file with the wrapper:

.. code-block:: python

    import pickle
    from fantraxapi import FantraxAPI
    from requests import Session

    session = Session()

    with open("fantraxloggedin.cookie", "rb") as f:
        for cookie in pickle.load(f):
            session.cookies.set(cookie["name"], cookie["value"])

    league_id = "96igs4677sgjk7ol"

    api = FantraxAPI(league_id, session=session)

    print(api.trade_block()) # The Trade Block Page is always private


Usage & Contributions
----------------------------------------------------------

* Source is available on the `Github Project Page <https://github.com/meisnate12/FantraxAPI>`_.
* Contributors to FantraxAPI own their own contributions and may distribute that code under
  the `MIT license <https://github.com/meisnate12/FantraxAPI/blob/master/LICENSE.txt>`_.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/meisnate12/FantraxAPI",
    "name": "fantraxapi",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "fantraxapi, fantrax, fantasy, wrapper, api",
    "author": "Nathan Taggart",
    "author_email": "meisnate12@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/03/bf/0df34a9af4e5ecc5bd13df8bd9eaafcf40c59ebdef1cb1b09d5fe5258588/fantraxapi-0.2.9.tar.gz",
    "platform": null,
    "description": "Welcome to Fantrax Documentation!\n==========================================================\n\n.. image:: https://img.shields.io/github/v/release/meisnate12/FantraxAPI?style=plastic\n    :target: https://github.com/meisnate12/FantraxAPI/releases\n    :alt: GitHub release (latest by date)\n\n.. image:: https://img.shields.io/github/actions/workflow/status/meisnate12/FantraxAPI/tests.yml?branch=master&style=plastic\n    :target: https://github.com/meisnate12/FantraxAPI/actions/workflows/tests.yml\n    :alt: Build Testing\n\n.. image:: https://img.shields.io/codecov/c/github/meisnate12/FantraxAPI?color=greenred&style=plastic\n    :target: https://codecov.io/gh/meisnate12/FantraxAPI\n    :alt: Build Coverage\n\n.. image:: https://img.shields.io/github/commits-since/meisnate12/FantraxAPI/latest?style=plastic\n    :target: https://github.com/meisnate12/FantraxAPI/commits/master\n    :alt: GitHub commits since latest release (by date) for a branch\n\n.. image:: https://img.shields.io/pypi/v/FantraxAPI?style=plastic\n    :target: https://pypi.org/project/FantraxAPI/\n    :alt: PyPI\n\n.. image:: https://img.shields.io/pypi/dm/FantraxAPI.svg?style=plastic\n    :target: https://pypi.org/project/FantraxAPI/\n    :alt: Downloads\n\n.. image:: https://img.shields.io/readthedocs/plex-meta-manager?color=%2300bc8c&style=plastic\n    :target: https://fantraxapi.metamanager.wiki/en/latest/\n    :alt: Wiki\n\n.. image:: https://img.shields.io/discord/822460010649878528?color=%2300bc8c&label=Discord&style=plastic\n    :target: https://discord.gg/NfH6mGFuAB\n    :alt: Discord\n\n.. image:: https://img.shields.io/reddit/subreddit-subscribers/PlexMetaManager?color=%2300bc8c&label=r%2FPlexMetaManager&style=plastic\n    :target: https://www.reddit.com/r/PlexMetaManager/\n    :alt: Reddit\n\n.. image:: https://img.shields.io/github/sponsors/meisnate12?color=%238a2be2&style=plastic\n    :target: https://github.com/sponsors/meisnate12\n    :alt: GitHub Sponsors\n\n.. image:: https://img.shields.io/badge/-Sponsor_or_Donate-blueviolet?style=plastic\n    :target: https://github.com/sponsors/meisnate12\n    :alt: Sponsor or Donate\n\n\nOverview\n----------------------------------------------------------\nUnofficial Python bindings for the Fantrax API. The goal is to make interaction with the API as easy as possible while emulating the endpoints as much as possible\n\n\nInstallation & Documentation\n----------------------------------------------------------\n\n.. code-block:: python\n\n    pip install fantraxapi\n\nDocumentation_ can be found at Read the Docs.\n\n.. _Documentation: https://fantraxapi.metamanager.wiki\n\n\nUsing the API\n==========================================================\n\nGetting a FantraxAPI Instance\n----------------------------------------------------------\n\nTo connect to the Fantrax API you use the FantraxAPI object.\n\n.. code-block:: python\n\n    from fantraxapi import FantraxAPI\n\n    league_id = \"96igs4677sgjk7ol\"\n\n    api = FantraxAPI(league_id)\n\n\n.. code-block:: python\n\n    import fantraxapi\n\n    api = fantraxapi.FantraxAPI()\n\n\nUsage Examples\n==========================================================\n\nExample: Get the Scores for the Season.\n\n.. code-block:: python\n\n    from fantraxapi import FantraxAPI\n\n    league_id = \"96igs4677sgjk7ol\"\n\n    api = FantraxAPI(league_id)\n\n    for _, scoring_period in api.scoring_periods().items():\n        print(\"\")\n        print(scoring_period)\n\n\nConnecting with a private League\n==========================================================\n\nI was unable to decipher the api login method so in order to connect to a private league or specific pages in a public\nleague that are not public you need to use a cookie. The code below uses Google Chrome and the :code:`selenium` and\n:code:`webdriver-manager` packages to open a chrome instance where you can login and after 30 seconds a cookie file with\nthat login will be save to :code:`fantraxloggedin.cookie`.\n\nFirst install the two packages:\n\n.. code-block:: python\n\n    pip install selenium\n    pip install webdriver-manager\n\nSecond run the code below and login when the chrome window loads the Fantrax login page:\n\n.. code-block:: python\n\n    import pickle\n    import time\n    from selenium import webdriver\n    from selenium.webdriver.chrome.service import Service\n    from selenium.webdriver.chrome.options import Options\n    from webdriver_manager.chrome import ChromeDriverManager\n\n    service = Service(ChromeDriverManager().install())\n\n    options = Options()\n    options.add_argument(\"--window-size=1920,1600\")\n    options.add_argument(\"user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36\")\n\n    with webdriver.Chrome(service=service, options=options) as driver:\n        driver.get(\"https://www.fantrax.com/login\")\n        time.sleep(30)\n        pickle.dump(driver.get_cookies(), open(\"fantraxloggedin.cookie\", \"wb\"))\n\n\nThird use the saved cookie file with the wrapper:\n\n.. code-block:: python\n\n    import pickle\n    from fantraxapi import FantraxAPI\n    from requests import Session\n\n    session = Session()\n\n    with open(\"fantraxloggedin.cookie\", \"rb\") as f:\n        for cookie in pickle.load(f):\n            session.cookies.set(cookie[\"name\"], cookie[\"value\"])\n\n    league_id = \"96igs4677sgjk7ol\"\n\n    api = FantraxAPI(league_id, session=session)\n\n    print(api.trade_block()) # The Trade Block Page is always private\n\n\nUsage & Contributions\n----------------------------------------------------------\n\n* Source is available on the `Github Project Page <https://github.com/meisnate12/FantraxAPI>`_.\n* Contributors to FantraxAPI own their own contributions and may distribute that code under\n  the `MIT license <https://github.com/meisnate12/FantraxAPI/blob/master/LICENSE.txt>`_.\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A lightweight Python library for The Fantrax API.",
    "version": "0.2.9",
    "project_urls": {
        "Documentation": "https://fantraxapi.metamanager.wiki",
        "Funding": "https://github.com/sponsors/meisnate12",
        "Homepage": "https://github.com/meisnate12/FantraxAPI",
        "Issues": "https://github.com/meisnate12/FantraxAPI/issues",
        "Source": "https://github.com/meisnate12/FantraxAPI"
    },
    "split_keywords": [
        "fantraxapi",
        " fantrax",
        " fantasy",
        " wrapper",
        " api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0fbdc1d57fa8066e36d167c3f7642601c31d6c7e38474444170a6c930129af19",
                "md5": "80c317f02720925bb3943393462c92b2",
                "sha256": "e14cd899ca4f13d146361cd85ec83d89f983e98b9dacdfb56cd8c84c175a8c33"
            },
            "downloads": -1,
            "filename": "fantraxapi-0.2.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "80c317f02720925bb3943393462c92b2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 10981,
            "upload_time": "2024-10-15T20:52:18",
            "upload_time_iso_8601": "2024-10-15T20:52:18.350446Z",
            "url": "https://files.pythonhosted.org/packages/0f/bd/c1d57fa8066e36d167c3f7642601c31d6c7e38474444170a6c930129af19/fantraxapi-0.2.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "03bf0df34a9af4e5ecc5bd13df8bd9eaafcf40c59ebdef1cb1b09d5fe5258588",
                "md5": "bc3eeff57e64955e98c486bbefe70551",
                "sha256": "c8b01676079e17308cfda396d0854ddf833ce64645966fb9d32fdb2e9d380770"
            },
            "downloads": -1,
            "filename": "fantraxapi-0.2.9.tar.gz",
            "has_sig": false,
            "md5_digest": "bc3eeff57e64955e98c486bbefe70551",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 12843,
            "upload_time": "2024-10-15T20:52:19",
            "upload_time_iso_8601": "2024-10-15T20:52:19.715664Z",
            "url": "https://files.pythonhosted.org/packages/03/bf/0df34a9af4e5ecc5bd13df8bd9eaafcf40c59ebdef1cb1b09d5fe5258588/fantraxapi-0.2.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-15 20:52:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "meisnate12",
    "github_project": "FantraxAPI",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "setuptools",
            "specs": []
        }
    ],
    "lcname": "fantraxapi"
}
        
Elapsed time: 0.45158s