Skip to main content

Leesah er et Pythonbibliotek for å spille det hendelsedrevet applikasjonsutviklingspillet Leesah Game

Project description

Leesah Python

Go further down 🇬🇧 for the English documentation.

Leesah-game er et hendelsedrevet applikasjonsutviklingspill som utfordrer spillerne til å bygge en hendelsedrevet applikasjon. Applikasjonen håndterer forskjellige typer oppgaver som den mottar som hendelser på en Kafka-basert hendelsestrøm. Oppgavene varierer fra veldig enkle til mer komplekse.

Python-bibliotek for å spille Leesah!

Kom i gang

Det finnes to versjoner av Leesah-game! En hvor man lager en applikasjon som kjører på Nais, og en hvor man spiller lokalt direkte fra terminalen. Dette biblioteket kan brukes i begge versjoner, men denne dokumentasjonen dekker kun lokal spilling.

Sett opp lokalt miljø

Vi anbefaler at du bruker et virtuelt miljø for å kjøre koden din, som for eksempel Venv.

Start med å opprette en katalog leesah-game.

For macOS/Linux

cd leesah-game
python3 -m venv venv
source ./venv/bin/activate

For Windows

cd leesah-game
python3 -m venv venv
.\venv\Scripts\activate

Installer biblioteket

Det er kun en avhengighet du trenger, og det er biblioteket leesah-game.

python3 -m pip install leesah-game

Hent Kafkasertifikat

Sertifikater for å koble seg på Kafka ligger tilgjengelig på leesah.io/certs, passord får du utdelt.

Du kan også bruke kommandoen nedenfor:

curl -u leesah-game:<se presentasjon> -o leesah-certs.zip https://leesah.io/certs && unzip leesah-certs.zip

Du vil nå ende opp med filen leesah-certs.yaml i leesah-game-katalogen du lagde tidligere.

Eksempelkode

For å gjøre det enklere å komme i gang har vi et fungerende eksempel som svarer på spørsmålet om lagregistrering med et navn og en farge (hexkode). Opprett filen main.py og lim inn koden nedenfor.

"""Spill Leesah Game

1. Hent ned sertifikater, og sikre deg at de ligger i filen leesah-certs.yaml
2. Sett 'LAGNAVN' til ditt valgte lagnavn
3. Sett 'HEXKODE' til din valgte farge
"""
import leesah

LAGNAVN = "BYTT MEG"
HEXKODE = "BYTT MEG"


class Rapid(leesah.KvissRapid):
    """Klassen som svarer på spørsmålene."""

    def kjør(self):
        """Start quizen!

        Vi anbefaler at du bruker funksjoner til å svare på spørsmålene.
        """
        while True:
            melding = self.hent_spørsmål()
            if melding.kategori == "lagregistrering":
                self.behandle_lagregistrering(melding.spørsmål)

    def behandle_lagregistrering(self, spørsmål):
        self.publiser_svar(HEXKODE)


if __name__ == "__main__":
    rapid = Rapid(LAGNAVN, ignorerte_kategorier=[
        # "lagregistrering",
    ])

    try:
        rapid.kjør()
    except (KeyboardInterrupt, SystemExit):
        rapid.avslutt()

Kjør koden

Kjør koden din med:

python3 main.py

Leesah Python English

Leesah-game is an event-driven application development game that challenges players to build an event-driven application. The application handles different types of tasks that it receives as events on a Kafka-based event stream. The tasks vary from very simple to more complex.

This is the Python library to play Leesah!

Getting started

There are two versions of the the Leesah game! On is for local play, directly in the terminal. While the other is running on the Nais platform, and you learn how to be a developer in Nav and use Nais. This library is used by both versions, but the following documentation is just for local play.

Setting up local environment

We recommend to use a virtual environment when playing Leesah, for example using Venv.

Start by creating the folder leesah-game. Then set up the virtual environment using the following commands.

For macOS/Linux

cd leesah-game
python3 -m venv venv
source ./venv/bin/activate

For Windows

cd leesah-game
python3 -m venv venv
.\venv\Scripts\activate

Install the library

There is only one dependency you need to play, and that is the leesah-game library.

python3 -m pip install leesah-game

Fetch Kafka certificates

You need some certificates to connect to the Kafka cluster, which is available at leesah.io/certs. The username is always leesah-game, and the password will be distributed.

You can also use the one-liner below:

curl -u leesah-game:<se presentasjon> -o leesah-certs.zip https://leesah.io/certs && unzip leesah-certs.zip

Using the command above you will end up with leesah-certs.yaml in the leesah-game directory you made earlier.

Example code

To make it easy to start we have made a working example that answer the first question, team-registration, with a dummy name and color. All you need to do is update TEAM_NAME and HEX_CODE, and your ready to compete!

Create a file called main.py and paste the code below.

"""Play Leesah Game

1. Download the Kafka certificate, and make sure that you have a file called leesah-certs.yaml in the same directory as this file
2. Set your own 'TEAM_NAME'
3. Set your own 'HEX_CODE' as team color
"""
import leesah

TEAM_NAME = "CHANGE ME"
HEX_CODE = "CHANGE ME"


class Rapid(leesah.QuizRapid):
    """The class that will answer the questions."""

    def run(self):
        """Start quiz!

        We recommend that you use seperate functions to answer each question.
        """
        while True:
            message = self.fetch_question()
            if message.category == "team-registration":
                self.handle_team_registration(message.question)

    def handle_team_registration(self, message):
        self.publish_answer(HEX_CODE)


if __name__ == "__main__":
    rapid = Rapid(TEAM_NAME, ignored_categories=[
        # "team-registration",
    ])

    try:
        rapid.run()
    except (KeyboardInterrupt, SystemExit):
        rapid.close()

Running code

Run you code:

python3 main.py

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

leesah_game-1.3.2.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

leesah_game-1.3.2-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file leesah_game-1.3.2.tar.gz.

File metadata

  • Download URL: leesah_game-1.3.2.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.3

File hashes

Hashes for leesah_game-1.3.2.tar.gz
Algorithm Hash digest
SHA256 d3a15bda594d7ceea7682448ac2a0e0909536da29a103129631b7614a92f1f19
MD5 a5b99033fe5d25cb3561f906259d97dc
BLAKE2b-256 ca75d85eb3e4c3bdff7c55de6d803e0ef75771beccd0a154a479e8b3bfd54f0b

See more details on using hashes here.

File details

Details for the file leesah_game-1.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for leesah_game-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cda259cc50a2e72e959a305260a69d116ac232b388070d3cc4ecfe2a9bb69da9
MD5 ab5d51713dbd854a9abd04167e8b5ca0
BLAKE2b-256 ddd6b6649fb6216b900dcaea2d576380011703cdbc6ca98dad3e335f872f8ad6

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