Skip to main content

A Python based API wrapper for CraftiGames community

Project description

CraftiGames

Pikanetwork API Wrapper A easy to use, feature-rich, and Asynchronous warpping.

Key Features

  • Wraps Pikanetwork's and JartexNetwork's API Asynchronously.
  • Fast and efficient.
  • Handles Ratelimits, ResponseErrors, faulty response.
  • Covers all parts of PikaNetwork's and JartexNetwork's

Credits

Installing

    pip install CraftiGames

EXAMPLES

  1. Profile and Stats
from  CraftiGames import Pikanetwork, PikaAnnotations
import asyncio


async def main():

    # Sending API requests with an asynchronous environment
    async with Pikanetwork() as api:

        profile = await api.Profile('Fireor')
        stats = await api.Stats('Fireor', "bedwars", "total", "all_modes")
    
    # Extracting items from the response
    username = profile.username
    rank = profile.highest_minigame_rank
    level = profile.level
    last_seen = profile.last_seen_text

    # Extracting guild from player's profile
    guild = profile.guild()

    # Assigning variables if player is not in a guild
    if guild is None:
        guild_name = None
        guild_tag = None
        guild_owner = None
        guild_level = None
        guild_mc = None
    
    guild_name = guild.name
    guild_tag = guild.tag
    guild_owner = guild.leader
    guild_level = guild.level
    guild_mc = guild.member_count

    # Extracting stats
    wins = stats.wins
    wins_lb = stats.wins_lb

    losses = stats.losses
    losses_lb = stats.losses

    wlr = stats.wlr
    win_rate = stats.win_rate
    
    # creating a templet to output
    description = f"""
    {username}'s Stats [{rank}]

    level: {level}
    last seen: {last_seen}

    Guild:
        Name: {guild_name}
        Tag: {guild_tag}
        Leader: {guild_owner}
        level: {guild_level}
        Members: {guild_mc}

    Stats:
        Wins: {wins} | #{wins_lb}
        Losses: {losses} | #{losses_lb}

        wlr: {wlr}
        win rate: {win_rate}%
    """
    print(description)


asyncio.run(main())
  1. Guilds
from CraftiGames import Pikanetwork, PikaAnnotations
import asyncio


async def main():

    # Sending API requests with an asynchronous environment
    async with Pikanetwork() as api:

        guild = await api.Guild("RIP")
    
    # If guild doesn't exists
    if guild is None:
        print("Guild not found!")
        return
    
    # Extracting items from the response
    guild_created_at = guild.created_at # UnixTimestamp usable in discord timestamp(<t:UnixTimestamp:R>)
    guild_name = guild.name
    guild_tag = guild.tag
    guild_owner = guild.leader
    guild_level = guild.level
    guild_member_count = guild.member_count

    guild_members = guild.member_list

    
    # creating a templet to output
    description = f"""
    Guild [<t:{guild_created_at}:R>]:

        Name: {guild_name}
        Tag: {guild_tag}
        Leader: {guild_owner}
        level: {guild_level}
        Members: {guild_member_count}

        list: {guild_members}
    """
    print(description)


asyncio.run(main())
  1. Recaps
from CraftiGames import Pikanetwork, PikaAnnotations
import asyncio


async def main():

    # Sending API requests with an asynchronous environment
    async with Pikanetwork() as api:

        recap = await api.Recap("c19218da-69fc-4c27-99f6-c607c1676ac2")
    
    # If recap doesn't exists
    if recap is None:
        print("Recap not found!")
        return
    
    # Extracting items from the response
    recap_id = recap.id
    winners = ', '.join(winner for winner in recap.winners)
    most_kills = recap.most_kills
    player_with_most_kills = recap.player_with_most_kills
    mapname = recap.map_name
    started = recap.game_start # UnixTimestamp
    duration = recap.game_duration
    link = recap.recap_link
    players = ", ".join(player for player in recap.players)
    
    # creating a templet to output
    description = f"""
    Recap: {recap_id} | Game started: <:t{started}:F> | Duration: {duration}:
    link: {link}

        winners: {winners}
        map: {mapname}
        most kills: {player_with_most_kills} | {most_kills}

        players: {players}
    """
    print(description)


asyncio.run(main())
  1. MultiProcessing
from CraftiGames import Pikanetwork, PikaAnnotations
import asyncio

# CraftiGames automates batch processing.
# No matter how big the lists are it will automatically break it into batches and fetch the responses.
players = ["Fireor", "fwgazes", "ignLone"]
guilds = ["RIP", "EKITTENS", "Menace"]

async def main():

    # Sending API requests with an asynchronous environment
    async with Pikanetwork() as api:

        _profiles = await api.MultiProfile(api, players)
        _stats = await api.MultiStats(api, players, "bedwars", "total", "all_modes")
        _guilds = await api.MultiGuilds(api, guilds)
    
    
    # Multi-Processing always returns response in the form of ("object's name", 'API Response')
    for player, profile in _profiles:
        
        player: str
        profile: PikaAnnotations.Profile

        if profile is None:
            print(f'Couldn\'t find any player named {player}!')

        print(player, profile.level)

    for player, stats in _stats:
        
        player: str
        stats: PikaAnnotations.Stats

        if profile is None:
            print(f'Couldn\'t find any player named {player}!')

        print(player, stats.wins)

    for name, guild in _guilds:
        
        name: str
        guild: PikaAnnotations.Guild

        if profile is None:
            print(f'Couldn\'t find any guild named {name}!')

        print(name, guild.totalexp)


asyncio.run(main())

How to Change Configuration

Changing the configuration is not recommended as the default settings ensure efficiency and prevent rate limits. You can still edit it for even higher efficency and logging.

from CraftiGames import config

config.update(
    Logging = True,
    Allowed_Recursion = 50,
    Batch_Size = 25,
    Batch_Delay = 0.8,
    Default_Skins = ['fwgazes', 'ignLone'],
    Interval = 1,
    Max_Requests_Per_Interval = 25,
    Delay = 0.8,
    Delay_After_Exceeding_Ratelimit = 1
)

image

How to reset to default configuration

from CraftiGames import config

config.update() # reset config to default settings

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

CraftiGames.py-1.2.1.tar.gz (29.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

CraftiGames.py-1.2.1-py3-none-any.whl (51.7 kB view details)

Uploaded Python 3

File details

Details for the file CraftiGames.py-1.2.1.tar.gz.

File metadata

  • Download URL: CraftiGames.py-1.2.1.tar.gz
  • Upload date:
  • Size: 29.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.3

File hashes

Hashes for CraftiGames.py-1.2.1.tar.gz
Algorithm Hash digest
SHA256 3ce129edb88f3860bc82a495195f210eea2290babecd16d196b1d943a297428e
MD5 6e16757ce380d5a4ca0ff7e1b776bff9
BLAKE2b-256 26250f0c9a61bb644111838821f8f30d31ddbbde75d3ca2a38b78c0d3b13461c

See more details on using hashes here.

File details

Details for the file CraftiGames.py-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: CraftiGames.py-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 51.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.3

File hashes

Hashes for CraftiGames.py-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 29cb5be115a3fd655bd0b704076c5d75dc5e239f191694a7f0944cdd281ebea7
MD5 0030437e80c26842f14af5b966904359
BLAKE2b-256 2094676dc93ce0aa399b607abefb06772673e5963a1598d64e77c59560db9c8f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page