pychpp


Namepychpp JSON
Version 0.4.4 PyPI version JSON
download
home_pagehttps://framagit.org/Pierre86/pychpp
Summaryframework created to use the API provided by the online game Hattrick
upload_time2024-10-22 21:58:44
maintainerNone
docs_urlNone
authorPierre Gobin
requires_python<4.0,>=3.8
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyCHPP

pyCHPP is an object-oriented python framework created to use the API provided by the online game Hattrick (www.hattrick.org).

## Installation

pyCHPP can be installed using pip :

    pip install pychpp

## Quick start

### First connection
```python-repl
>>> from pychpp import CHPP
    
# Set consumer_key and consumer_secret provided for your app by Hattrick
>>> consumer_key = ''
>>> consumer_secret = ''
    
# Initialize CHPP instance
>>> chpp = CHPP(consumer_key, consumer_secret)
    
# Get url, request_token and request_token_secret to request API access
# You can set callback_url and scope
>>> auth = chpp.get_auth(callback_url="www.mycallbackurl.com", scope="")
  
# auth['url'] contains the url to which the user can grant the application
# access to the Hattrick API
# Once the user has entered their credentials,
# a code is returned by Hattrick (directly or to the given callback url)
>>> code = ""

# Get access token from Hattrick
# access_token['key'] and access_token['secret'] have to be stored
# in order to be used later by the app
>>> access_token = chpp.get_access_token(
                        request_token=auth["request_token"],
                        request_token_secret=auth["request_token_secret"],
                        code=code,
                        )
```
### Further connections
```python-repl
# Once you have obtained access_token for a user
# You can use it to call Hattrick API
>>> chpp = CHPP(consumer_key,
            consumer_secret,
            access_token['key'],
            access_token['secret'],
            )

# Now you can use chpp methods to get datas from Hattrick API
# For example :
>>> current_user = chpp.user()
>>> all_teams = current_user.teams

>>> best_team_ever = chpp.team(1165592)
>>> best_team_ever
<HTTeam object - Les Poitevins de La Chapelle (1165592)>

>>> best_team_arena = best_team_ever.arena.details()
>>> best_team_arena
<HTArena object - Stade de La Chapelle (1162154)>
>>> best_team_arena.name
'Stade de La Chapelle'

>>> worth_team_ever = chpp.team(1750803)
>>> worth_team_ever
<HTTeam object - Capdenaguet (1750803)>

>>> player = chpp.player(6993859)
>>> player
<HTPlayer object - Pedro Zurita (6993859)>
>>> player.career_goals
1167

>>> match = chpp.match(68599186)
>>> match
<HTMatch object - Skou United - FC Barentin (68599186)>
>>> match.date
<HTDatetime object - 2006-02-23 20:00:00 CET+0100 (S28, W8, D4)>
```

## Philosophy
From 0.4.0 version, pyCHPP is build on two class families :
- under `pychpp/models/xml`, you will find a class by CHPP XML file. These classes can be instantiated with a CHPP object, thanks to functions prefixed with `xml_`. For example, `arenadetails.xml` file can be fetched through a CHPP instance with the `xml_arena_details` method.
```python-repl
>>> xml_arena = chpp.xml_arena_details(arena_id=294762)
>>> xml_arena
<ArenaDetails object - Stade Dimitri LiƩnard (294762)>
```
- under `pychpp/models/custom`, pyCHPP moves further away from vanilla xml files, in order to offer a more consistent experience (in our opinion) and to add some convenient methods and attributes (as url), and to allow navigation between objects. For example, you can instantiate a HTTeam object through a CHPP instance by calling the `team` method. From this `HTTeam` instance, you can get the list of this team players by calling its `players` method.
```python-repl
>>> team = chpp.team(294762)
>>> team
<HTTeam object - FC Mistral Gagnant (294762)>
>>> players = team.players()
>>> players[3]
<HTTeamPlayersItem object - Massimiliano Carotta (453279129)>
>>> players[3].first_name
'Massimiliano'
>>> players[3].last_name
'Carotta'
```

## Customization

The easiest way to use pyCHPP is to use the builtin methods of the CHPP object.

However, for more advanced use, it is also possible to customize the framework's built-in templates.

For example, if you need to perform a query on the arenadetails.xml file, but in reality only need the Arena/ArenaID, Arena/ArenaName and Arena/ArenaImage data, one way to proceed is to create a custom class inheriting from the RequestArenaDetails class, and use HTProxyField as follows:
```python
from pychpp.models.xml.arena_details import RequestArenaDetailsDefault, ArenaDetailsDefault
from pychpp.models.ht_field import HTProxyField


class MyCustomArenaClass(RequestArenaDetailsDefault):
    id: int = HTProxyField(ArenaDetailsDefault)
    name: str = HTProxyField(ArenaDetailsDefault)
    image: str = HTProxyField(ArenaDetailsDefault)
```

Then, to use this new class:
```python-repl
>>> from pychpp.chpp import CHPPBase
>>> chpp = CHPPBase(consumer_key, 
                    consumer_secret,
                    access_token['key'],
                    access_token['secret'],
                    )
>>> arena = MyCustomArenaClass(chpp=chpp, arena_id=1747365)
>>> arena
<MyCustomArenaClass object - La grande taule (1747365)>
>>> arena.id
1747365
>>> arena.name
'La grande taule'
>>> arena.image
'//res.hattrick.org/arenas/18/175/1748/1747365/custom-220-100.jpg'
```
In this way, only the data you're really interested in is parsed, which can in some cases be interesting from a performance point of view.

## List of supported CHPP XML files
![35/57](https://progress-bar.xyz/61/?title=35%20on%2057)

The following table shows the CHPP XML files that are currently supported:

|      pyCHPP class       |      CHPP XML files       |
|:-----------------------:|:-------------------------:|
|      Achievements       |    `achievements.xml`     |
|        Alliances        |      `alliances.xml`      |
|     AllianceDetails     |   `alliancedetails.xml`   |
|          Arena          |    `arenadetails.xml`     |
|         Avatars         |       `avatars.xml`       |
|        Bookmarks        |      `bookmarks.xml`      |
|       Challenges        |     `challenges.xml`      |
|          Club           |        `club.xml`         |
|       CupMatches        |     `cupmatches.xml`      |
|       CurrentBids       |     `currentbids.xml`     |
|         Economy         |       `economy.xml`       |
|          Fans           |        `fans.xml`         |
|    HallOfFamePlayers    |     `hofplayers.xml`      |
|      LadderDetails      |    `ladderdetails.xml`    |
|       LadderList        |     `ladderlist.xml`      |
|      LeagueDetails      |    `leaguedetails.xml`    |
|     LeagueFixtures      |   `leaguefixtures.xml`    |
|      LeagueLevels       |    `leaguelevels.xml`     |
|    ManagerCompendium    |  `managercompendium.xml`  |
|      MatchDetails       |    `matchdetails.xml`     |
|       MatchLineup       |     `matchlineup.xml`     |
|     MatchesArchive      |   `matchesarchive.xml`    |
|   NationalTeamDetails   | `nationalteamdetails.xml` |
|      NationalTeams      |    `nationalteams.xml`    |
|      PlayerDetails      |    `playerdetails.xml`    |
|         Players         |       `players.xml`       |
|      RegionDetails      |    `regiondetails.xml`    |
|       TeamDetails       |     `teamdetails.xml`     |
|        Training         |      `training.xml`       |
|      TransfersTeam      |    `transfersteam.xml`    |
|        WorldCup         |      `worldcup.xml`       |
|      WorldDetails       |    `worlddetails.xml`     |
|   YouthPlayerDetails    | `youthplayerdetails.xml`  |
|     YouthPlayerList     |   `youthplayerlist.xml`   |
|    YouthTeamDetails     |  `youthteamdetails.xml`   |

## License
pyCHPP is licensed under the Apache License 2.0.

            

Raw data

            {
    "_id": null,
    "home_page": "https://framagit.org/Pierre86/pychpp",
    "name": "pychpp",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Pierre Gobin",
    "author_email": "p.dev@gobin.cc",
    "download_url": "https://files.pythonhosted.org/packages/e9/29/7c84b4e2b179a23d8cf3b219be4da2f4d2937c7ab276590c98b520bcb121/pychpp-0.4.4.tar.gz",
    "platform": null,
    "description": "# pyCHPP\n\npyCHPP is an object-oriented python framework created to use the API provided by the online game Hattrick (www.hattrick.org).\n\n## Installation\n\npyCHPP can be installed using pip :\n\n    pip install pychpp\n\n## Quick start\n\n### First connection\n```python-repl\n>>> from pychpp import CHPP\n    \n# Set consumer_key and consumer_secret provided for your app by Hattrick\n>>> consumer_key = ''\n>>> consumer_secret = ''\n    \n# Initialize CHPP instance\n>>> chpp = CHPP(consumer_key, consumer_secret)\n    \n# Get url, request_token and request_token_secret to request API access\n# You can set callback_url and scope\n>>> auth = chpp.get_auth(callback_url=\"www.mycallbackurl.com\", scope=\"\")\n  \n# auth['url'] contains the url to which the user can grant the application\n# access to the Hattrick API\n# Once the user has entered their credentials,\n# a code is returned by Hattrick (directly or to the given callback url)\n>>> code = \"\"\n\n# Get access token from Hattrick\n# access_token['key'] and access_token['secret'] have to be stored\n# in order to be used later by the app\n>>> access_token = chpp.get_access_token(\n                        request_token=auth[\"request_token\"],\n                        request_token_secret=auth[\"request_token_secret\"],\n                        code=code,\n                        )\n```\n### Further connections\n```python-repl\n# Once you have obtained access_token for a user\n# You can use it to call Hattrick API\n>>> chpp = CHPP(consumer_key,\n            consumer_secret,\n            access_token['key'],\n            access_token['secret'],\n            )\n\n# Now you can use chpp methods to get datas from Hattrick API\n# For example :\n>>> current_user = chpp.user()\n>>> all_teams = current_user.teams\n\n>>> best_team_ever = chpp.team(1165592)\n>>> best_team_ever\n<HTTeam object - Les Poitevins de La Chapelle (1165592)>\n\n>>> best_team_arena = best_team_ever.arena.details()\n>>> best_team_arena\n<HTArena object - Stade de La Chapelle (1162154)>\n>>> best_team_arena.name\n'Stade de La Chapelle'\n\n>>> worth_team_ever = chpp.team(1750803)\n>>> worth_team_ever\n<HTTeam object - Capdenaguet (1750803)>\n\n>>> player = chpp.player(6993859)\n>>> player\n<HTPlayer object - Pedro Zurita (6993859)>\n>>> player.career_goals\n1167\n\n>>> match = chpp.match(68599186)\n>>> match\n<HTMatch object - Skou United - FC Barentin (68599186)>\n>>> match.date\n<HTDatetime object - 2006-02-23 20:00:00 CET+0100 (S28, W8, D4)>\n```\n\n## Philosophy\nFrom 0.4.0 version, pyCHPP is build on two class families :\n- under `pychpp/models/xml`, you will find a class by CHPP XML file. These classes can be instantiated with a CHPP object, thanks to functions prefixed with `xml_`. For example, `arenadetails.xml` file can be fetched through a CHPP instance with the `xml_arena_details` method.\n```python-repl\n>>> xml_arena = chpp.xml_arena_details(arena_id=294762)\n>>> xml_arena\n<ArenaDetails object - Stade Dimitri Li\u00e9nard (294762)>\n```\n- under `pychpp/models/custom`, pyCHPP moves further away from vanilla xml files, in order to offer a more consistent experience (in our opinion) and to add some convenient methods and attributes (as url), and to allow navigation between objects. For example, you can instantiate a HTTeam object through a CHPP instance by calling the `team` method. From this `HTTeam` instance, you can get the list of this team players by calling its `players` method.\n```python-repl\n>>> team = chpp.team(294762)\n>>> team\n<HTTeam object - FC Mistral Gagnant (294762)>\n>>> players = team.players()\n>>> players[3]\n<HTTeamPlayersItem object - Massimiliano Carotta (453279129)>\n>>> players[3].first_name\n'Massimiliano'\n>>> players[3].last_name\n'Carotta'\n```\n\n## Customization\n\nThe easiest way to use pyCHPP is to use the builtin methods of the CHPP object.\n\nHowever, for more advanced use, it is also possible to customize the framework's built-in templates.\n\nFor example, if you need to perform a query on the arenadetails.xml file, but in reality only need the Arena/ArenaID, Arena/ArenaName and Arena/ArenaImage data, one way to proceed is to create a custom class inheriting from the RequestArenaDetails class, and use HTProxyField as follows:\n```python\nfrom pychpp.models.xml.arena_details import RequestArenaDetailsDefault, ArenaDetailsDefault\nfrom pychpp.models.ht_field import HTProxyField\n\n\nclass MyCustomArenaClass(RequestArenaDetailsDefault):\n    id: int = HTProxyField(ArenaDetailsDefault)\n    name: str = HTProxyField(ArenaDetailsDefault)\n    image: str = HTProxyField(ArenaDetailsDefault)\n```\n\nThen, to use this new class:\n```python-repl\n>>> from pychpp.chpp import CHPPBase\n>>> chpp = CHPPBase(consumer_key, \n                    consumer_secret,\n                    access_token['key'],\n                    access_token['secret'],\n                    )\n>>> arena = MyCustomArenaClass(chpp=chpp, arena_id=1747365)\n>>> arena\n<MyCustomArenaClass object - La grande taule (1747365)>\n>>> arena.id\n1747365\n>>> arena.name\n'La grande taule'\n>>> arena.image\n'//res.hattrick.org/arenas/18/175/1748/1747365/custom-220-100.jpg'\n```\nIn this way, only the data you're really interested in is parsed, which can in some cases be interesting from a performance point of view.\n\n## List of supported CHPP XML files\n![35/57](https://progress-bar.xyz/61/?title=35%20on%2057)\n\nThe following table shows the CHPP XML files that are currently supported:\n\n|      pyCHPP class       |      CHPP XML files       |\n|:-----------------------:|:-------------------------:|\n|      Achievements       |    `achievements.xml`     |\n|        Alliances        |      `alliances.xml`      |\n|     AllianceDetails     |   `alliancedetails.xml`   |\n|          Arena          |    `arenadetails.xml`     |\n|         Avatars         |       `avatars.xml`       |\n|        Bookmarks        |      `bookmarks.xml`      |\n|       Challenges        |     `challenges.xml`      |\n|          Club           |        `club.xml`         |\n|       CupMatches        |     `cupmatches.xml`      |\n|       CurrentBids       |     `currentbids.xml`     |\n|         Economy         |       `economy.xml`       |\n|          Fans           |        `fans.xml`         |\n|    HallOfFamePlayers    |     `hofplayers.xml`      |\n|      LadderDetails      |    `ladderdetails.xml`    |\n|       LadderList        |     `ladderlist.xml`      |\n|      LeagueDetails      |    `leaguedetails.xml`    |\n|     LeagueFixtures      |   `leaguefixtures.xml`    |\n|      LeagueLevels       |    `leaguelevels.xml`     |\n|    ManagerCompendium    |  `managercompendium.xml`  |\n|      MatchDetails       |    `matchdetails.xml`     |\n|       MatchLineup       |     `matchlineup.xml`     |\n|     MatchesArchive      |   `matchesarchive.xml`    |\n|   NationalTeamDetails   | `nationalteamdetails.xml` |\n|      NationalTeams      |    `nationalteams.xml`    |\n|      PlayerDetails      |    `playerdetails.xml`    |\n|         Players         |       `players.xml`       |\n|      RegionDetails      |    `regiondetails.xml`    |\n|       TeamDetails       |     `teamdetails.xml`     |\n|        Training         |      `training.xml`       |\n|      TransfersTeam      |    `transfersteam.xml`    |\n|        WorldCup         |      `worldcup.xml`       |\n|      WorldDetails       |    `worlddetails.xml`     |\n|   YouthPlayerDetails    | `youthplayerdetails.xml`  |\n|     YouthPlayerList     |   `youthplayerlist.xml`   |\n|    YouthTeamDetails     |  `youthteamdetails.xml`   |\n\n## License\npyCHPP is licensed under the Apache License 2.0.\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "framework created to use the API provided by the online game Hattrick",
    "version": "0.4.4",
    "project_urls": {
        "Homepage": "https://framagit.org/Pierre86/pychpp"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ea8452308c5fcfd036f8b4fefbe978bb000d268e9a83035ddd70e77a33470d7d",
                "md5": "e800886089119f2028333b1255bcb719",
                "sha256": "ed437b78cd47be7914d04d3238958fc3c25c23555c5a86baf0ece2f70b2eabfb"
            },
            "downloads": -1,
            "filename": "pychpp-0.4.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e800886089119f2028333b1255bcb719",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 80152,
            "upload_time": "2024-10-22T21:58:43",
            "upload_time_iso_8601": "2024-10-22T21:58:43.303334Z",
            "url": "https://files.pythonhosted.org/packages/ea/84/52308c5fcfd036f8b4fefbe978bb000d268e9a83035ddd70e77a33470d7d/pychpp-0.4.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e9297c84b4e2b179a23d8cf3b219be4da2f4d2937c7ab276590c98b520bcb121",
                "md5": "4b8f000b974aa6d2a5e3cfc95e59a1d5",
                "sha256": "6efd382ff3b7f9b607f37589ee62cb6c19f088a7dacff65930cab60c70396ba2"
            },
            "downloads": -1,
            "filename": "pychpp-0.4.4.tar.gz",
            "has_sig": false,
            "md5_digest": "4b8f000b974aa6d2a5e3cfc95e59a1d5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 53929,
            "upload_time": "2024-10-22T21:58:44",
            "upload_time_iso_8601": "2024-10-22T21:58:44.524707Z",
            "url": "https://files.pythonhosted.org/packages/e9/29/7c84b4e2b179a23d8cf3b219be4da2f4d2937c7ab276590c98b520bcb121/pychpp-0.4.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-22 21:58:44",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pychpp"
}
        
Elapsed time: 0.56470s