pax_global_header00006660000000000000000000000064141752625440014524gustar00rootroot0000000000000052 comment=2c443811b3f89e8f377ddd5f16ab69fcf8ebb48d Sander0542-fivem-api-2c44381/000077500000000000000000000000001417526254400154005ustar00rootroot00000000000000Sander0542-fivem-api-2c44381/.github/000077500000000000000000000000001417526254400167405ustar00rootroot00000000000000Sander0542-fivem-api-2c44381/.github/workflows/000077500000000000000000000000001417526254400207755ustar00rootroot00000000000000Sander0542-fivem-api-2c44381/.github/workflows/python-publish.yml000066400000000000000000000011561417526254400245100ustar00rootroot00000000000000name: Upload Python Package on: release: types: [published] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies run: | python -m pip install --upgrade pip pip install build - name: Build package run: python -m build - name: Publish package uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} Sander0542-fivem-api-2c44381/LICENSE000066400000000000000000000020571417526254400164110ustar00rootroot00000000000000MIT License Copyright (c) 2022 Sander Jochems Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Sander0542-fivem-api-2c44381/README.md000066400000000000000000000000141417526254400166520ustar00rootroot00000000000000# Fivem API Sander0542-fivem-api-2c44381/fivem/000077500000000000000000000000001417526254400165065ustar00rootroot00000000000000Sander0542-fivem-api-2c44381/fivem/__init__.py000066400000000000000000000001071417526254400206150ustar00rootroot00000000000000from fivem.fivem import FiveM, FiveMServerOfflineError, Player, Server Sander0542-fivem-api-2c44381/fivem/fivem.py000066400000000000000000000031001417526254400201600ustar00rootroot00000000000000import json import aiohttp from fivem.player import Player from fivem.server import Server class FiveM: """Base class for a FiveM server""" def __init__(self, host, port): self.host = host self.port = port async def get_server(self) -> Server: dynamic = await self.get_dynamic_raw() info = await self.get_info_raw() players = list[Player]() if (dynamic['clients'] > 0): players = await self.get_players() return Server.parse(dynamic, info, players) async def get_players(self) -> list[Player]: players = list() for rawPlayer in await self.get_players_raw(): players.append(Player.parse(rawPlayer)) return players async def get_dynamic_raw(self) -> dict: return await self.make_request('dynamic.json') async def get_info_raw(self) -> dict: return await self.make_request('info.json') async def get_players_raw(self) -> list[dict]: return await self.make_request('players.json') async def make_request(self, uri): base = 'http://{}:{}/{}' url = base.format(self.host, self.port, uri) async with aiohttp.ClientSession() as session: try: async with session.get(url) as response: data = await response.text() return json.loads(data) except aiohttp.ClientConnectorError as e: raise FiveMServerOfflineError class FiveMServerOfflineError(Exception): pass Sander0542-fivem-api-2c44381/fivem/player.py000066400000000000000000000021241417526254400203530ustar00rootroot00000000000000class Player: def __init__(self, id, name, identifiers, ping): self.id = id self.name = name self.identifiers = Identifiers(identifiers) self.ping = ping @staticmethod def parse(data: dict): return Player(data.get('id'), data.get('name'), data.get('identifiers'), data.get('ping')) class Identifiers: def __init__(self, identifiers): self.raw = identifiers self.license = None self.steam = None self.xbl = None self.discord = None self.live = None if identifiers is not None: for identifier in identifiers: service, id = identifier.split(':') if service == "license": self.license = id elif service == "steam": self.steam = id elif service == "xbl": self.xbl = id elif service == "discord": self.discord = id elif service == "live": self.live = id Sander0542-fivem-api-2c44381/fivem/server.py000066400000000000000000000014771417526254400203770ustar00rootroot00000000000000from fivem.player import Player class Server: def __init__(self, hostname, server, players: list[Player], max_players, resources: list[str], vars: list[str], game_type, map_name): self.hostname = hostname self.server = server self.players = players self.max_players = max_players self.resources = resources self.vars = vars self.game = Game(game_type, map_name) @staticmethod def parse(dynamic: dict, info: dict, players: list[Player]): return Server(dynamic.get('hostname'), info.get('server'), players, dynamic.get('sv_maxclients'), info.get('resources'), info.get('vars'), dynamic.get('gametype'), dynamic.get('mapname')) class Game: def __init__(self, game_type, map_name): self.game_type = game_type self.map_name = map_name Sander0542-fivem-api-2c44381/setup.py000066400000000000000000000015171417526254400171160ustar00rootroot00000000000000import setuptools with open("README.md", "r") as fh: long_description = fh.read() setuptools.setup( name="fivem-api", use_scm_version=True, author="Sander Jochems", author_email="contact@sanderjochems.com", description="A library to query info, players and resources from FiveM server", long_description=long_description, long_description_content_type="text/markdown", license="MIT", url="https://github.com/Sander0542/fivem-api", packages=setuptools.find_packages(exclude=['tests', 'tests.*']), install_requires=[ 'aiohttp>=3.8.1' ], setup_requires=[ 'setuptools_scm' ], classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ] )