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:<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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file leesah_game-1.3.4.tar.gz.
File metadata
- Download URL: leesah_game-1.3.4.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09360df39cfb276c70b42f0cc30baaf8bc5c9b5865f2c76fc4db9645a32dc462
|
|
| MD5 |
8510cbc6fafaac76e0117464a77f8dce
|
|
| BLAKE2b-256 |
5b58cd42ab7fdb1057df5c8f63cb32d591abe94a419442eb0929ed3f525c224a
|
File details
Details for the file leesah_game-1.3.4-py3-none-any.whl.
File metadata
- Download URL: leesah_game-1.3.4-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27ccf569c8f9db5b6c5ace0e40c48e34ba45d6126d7640783785409ce23c4366
|
|
| MD5 |
989698e8c5f54df0506522d2300b8f99
|
|
| BLAKE2b-256 |
743efc71c8a2c50be67cc46da724fd5b50a9ec5bec8bce461ea7941d1163ad14
|