Skip to main content

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

Project description

Leesah Python in English

🇧🇻 Du finner den norske utgaven lengre ned.

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:<see presentation> -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

Leesah Python på norsk

🇬🇧 Go further up 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

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.4.1.tar.gz (10.6 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.4.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for leesah_game-1.4.1.tar.gz
Algorithm Hash digest
SHA256 b3dfea13e26b8a9a8bf86ea87c12d5a256082c10c2859dafc50fb8a404033d73
MD5 9aa583aa3034a083eda7804f2a98235b
BLAKE2b-256 ee881a9d0025421b8292c91d216c5258b9e82d4314147e9d6157727580b7bf92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for leesah_game-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3140606f32ce0f354f86a42e067e5e6f3924926355eaf976db8f35ea4f5714da
MD5 be0a6b60b82c337ab145fe7769988506
BLAKE2b-256 6d5d82b949541dcb134a7268f9021a164f44b06fca6ed20fcef75db1b1a9560b

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