
codingame Release 1.0.1 takos22 Aug 22, 2021 CONTENTS 1 Getting started 3 2 Getting help 5 3 User Guide 7 4 API Reference 13 5 Changelog 33 6 Indices and tables 37 Index 39 i ii codingame, Release 1.0.1 The codingame module is a wrapper for the undocumented CodinGame API, it enables developers to interact with CodinGame through a Python programming interface. Features: • Easy to develop • Supports both synchronous and asynchronous code CONTENTS 1 codingame, Release 1.0.1 2 CONTENTS CHAPTER ONE GETTING STARTED Is this your first time using the module? This is the place to get started! • First steps: Introduction | Quickstart • Examples: Many examples are available in the repository. 3 codingame, Release 1.0.1 4 Chapter 1. Getting started CHAPTER TWO GETTING HELP If you’re having trouble with something, these resources might help. • Ask us and hang out with us in our Discord server. • If you’re looking for something specific, try the index or searching. • Report bugs in the issue tracker. 5 codingame, Release 1.0.1 6 Chapter 2. Getting help CHAPTER THREE USER GUIDE 3.1 Introduction This is the documentation for the codingame module. 3.1.1 Prerequisites Python 3.6 or higher is required. 3.1.2 Installing Install codingame with pip: Linux or MacOS python3 -m pip install -U codingame Windows py -3 -m pip install -U codingame Installing the asynchronous version If you want to use the asynchronous client, make sure to have the correct modules installed by doing: Linux or MacOS python3 -m pip install -U codingame[async] 7 codingame, Release 1.0.1 Windows py -3 -m pip install -U codingame[async] Virtual Environments Sometimes you want to keep libraries from polluting system installs or use a different version of libraries than the ones installed on the system. You might also not have permissions to install libraries system-wide. For this purpose, the standard library as of Python comes with a concept called “Virtual Environment”s to help maintain these separate versions. A more in-depth tutorial is found on Virtual Environments and Packages. However, for the quick and dirty: 1. Go to your project’s working directory: Linux or MacOS cd your-website-dir Windows cd your-website-dir 2. Create a virtual environment: Linux or MacOS python3 -m venv venv Windows py -3 -m venv venv 3. Activate the virtual environment: Linux or MacOS source venv/bin/activate 8 Chapter 3. User Guide codingame, Release 1.0.1 Windows venv\Scripts\activate.bat 4. Use pip like usual: Linux or MacOS pip install -U codingame Windows pip install -U codingame Congratulations. You now have a virtual environment all set up. You can start to code, learn more in the Quickstart. 3.2 Quickstart This page gives a brief introduction to the module. It assumes you have the module already installed, if you don’t check the Installing portion. You can find examples here. 3.2.1 Get a CodinGamer Let’s get a CodinGamer from their pseudo with the Client.get_codingamer() method: import codingame client= codingame.Client() codingamer= client.get_codingamer("pseudo") print(codingamer) print(codingamer.pseudo) print(codingamer.public_handle) print(codingamer.avatar_url) Note: You can also use a public handle (39 character long hexadecimal string at the end of its profile link) or a user ID. Just replace the "pseudo" with the public handle or user ID. See also: See Client.get_codingamer() and CodinGamer for more info. 3.2. Quickstart 9 codingame, Release 1.0.1 3.2.2 Get a Clash of Code Let’s get a Clash of Code from its public handle with the Client.get_clash_of_code() method: import codingame client= codingame.Client() # get a pending public clash of code coc= client.get_pending_clash_of_code() # or get a clash of code from its public handle coc= client.get_clash_of_code("clash of code handle here") print(coc) print(coc.join_url) print(coc.modes) print(coc.programming_languages) print(coc.public_handle) print(coc.players) Note: The public handle is the 39 character long hexadecimal string at the end of the Clash of Code invite link. See also: See Client.get_pending_clash_of_code(), Client.get_clash_of_code() and ClashOfCode for more info. 3.2.3 Login Let’s log in into a profile with the email and password with the Client.login() method: import codingame client= codingame.Client("email","password") # then you can access the logged in codingamer like this print(client.logged_in) print(client.codingamer) print(client.codingamer.pseudo) print(client.codingamer.public_handle) print(client.codingamer.avatar_url) See also: See Client and Client.login() for more info. Note: Don’t worry, the email and the password aren’t stored. You can see that here. 10 Chapter 3. User Guide codingame, Release 1.0.1 3.3 Asynchronous client The asynchronous client has the same methods as the synchronous client, but all of them are coroutines. That means that you can use methods like Client.login(), but you need to do await client.login(...) instead of client.login(...). It works like this for methods of CodinGame models like CodinGamer.get_followers() needs to be awaited with the asynchronous client. 3.3.1 Example Here’s the first block of code of Quickstart but with the asynchronous client: import codingame import asyncio async def main(): client= codingame.Client(is_async= True) codingamer= await client.get_codingamer("pseudo") print(codingamer) print(codingamer.pseudo) print(codingamer.public_handle) print(codingamer.avatar_url) asyncio.run(main()) 3.3. Asynchronous client 11 codingame, Release 1.0.1 12 Chapter 3. User Guide CHAPTER FOUR API REFERENCE 4.1 API Reference The following section outlines the API of the codingame module. All the public classes, methods and functions are documented here. 4.1.1 Version Related Info There are two main ways to query version information about the library. codingame.version_info A named tuple that is similar to sys.version_info. Just like sys.version_info the valid values for releaselevel are ‘alpha’, ‘beta’, ‘candidate’ and ‘final’. codingame.__version__ A string representation of the version. e.g. '1.0.0rc1'. This is based off of PEP 440. 4.1.2 Client Hybrid client class codingame.Client(is_async=False) Client for the CodinGame API. Instanciates a SyncClient if is_async is False or not given. Instanciates a AsyncClient if is_async is True. Parameters is_async (bool) – Whether the client is asynchronous. Defaults to False. close() This function can be a coroutine. Closes the client session. property codingamer The CodinGamer that is logged in. None if the client isn’t logged in. Type Optional CodinGamer abstract get_challenge_leaderboard(challenge_id, group='global') This function can be a coroutine. Get the leaderboard of a challenge. 13 codingame, Release 1.0.1 You can specify an optional group of users to rank. Parameters • challenge_id (str) – The string that identifies the challenge. • group (Optional str) – The group of users to rank. For every group except "global", you need to be logged in. One of "global", "country", "company", "school" or "following". Default: "global". Raises • ValueError – One of the arguments isn’t one of the accepted arguments. • LoginRequired – The client isn’t logged in and the group is one of "country", "company", "school" or "following". • ChallengeNotFound – There is no challenge with the given challenge_id. Returns The challenge leaderboard. Return type ChallengeLeaderboard abstract get_clash_of_code(handle) This function can be a coroutine. Get a Clash of Code from its public handle. Parameters handle (str) – The Clash of Code’s public handle. 39 character long hexadecimal string (regex: [0-9]{7}[0-9a-f]{32}). Raises • ValueError – The Clash of Code handle isn’t in the good format. • ClashOfCodeNotFound – The Clash of Code with the given public handle isn’t found. Returns The ClashOfCode. Return type ClashOfCode abstract get_codingamer(codingamer) This function can be a coroutine. Get a CodinGamer from their public handle, their ID or from their username. Note: codingamer can be the public handle, the id or the username. Using the public handle or the ID is reccomended because it won’t change even if the codingamer changes their username. The public handle is a 39 character long hexadecimal string that represents the user. Regex of a public handle: [0-9a-f]{32}[0-9]{7} The ID is a 7 number long integer. Parameters codingamer (str or int) – The CodinGamer’s public handle, ID or username. Raises CodinGamerNotFound – The CodinGamer with the given public handle, ID or username isn’t found. Returns The CodinGamer. Return type CodinGamer 14 Chapter 4. API Reference codingame, Release 1.0.1 abstract get_global_leaderboard(page=1, type='GENERAL', group='global') This function can be a coroutine. Get the global leaderboard in CodinGame. You can specify an optional page, type of leaderboard and the group of users to rank. Parameters • page (Optional int) – The page of the leaderboard to get the users from. Default: 1. • type (Optional str) – The type of global leaderboard to show. One of "GENERAL", "CONTESTS", "BOT_PROGRAMMING", "OPTIM" or "CODEGOLF". Default: "GENERAL". • group (Optional str) – The group of users to rank. For every group except "global", you need to be logged in. One of "global", "country", "company", "school" or "following". Default: "global". Raises • ValueError – One of the arguments isn’t one of the accepted arguments. • LoginRequired – The client isn’t logged in and the group is one of "country", "company", "school" or "following". Returns The global leaderboard. Return type GlobalLeaderboard abstract get_language_ids() This function can be a coroutine. Get the list of all available language ids. abstract get_pending_clash_of_code() This function can be a coroutine. Get a pending Clash of Code. Returns The pending ClashOfCode if there’s one or None. Return type Optional ClashOfCode abstract get_puzzle_leaderboard(puzzle_id, group='global') This function can be a coroutine. Get the leaderboard of a puzzle.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages45 Page
-
File Size-