-- Leo's gemini proxy

-- Connecting to bbs.geminispace.org:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini; charset=utf-8

Sending plain text, would like to send gemtext


urney.xyz/first


So I have my first gamebook running... a very little thing, but I'm encountering a problem, the client is interpreting the result as plain text, as per the default, but I'd like to show it as gemtext and I don't know how to do that.


#!/usr/bin/python3
import os
from random import randint

#for param in os.environ.keys():  #os.environ[QUERY_STRING]
#   print ("%20s: %s" % (param, os.environ[param]))

sections_dict = {
  "1": {
         "title":"Pines in the mist",
         "text":"""
Halloween, 2013, you're lost in a pine woods somewhere north of Tejeda, in the center of Gran Canaria. The ground is hard, and the trees and the unusual cold mist doesn't allow you to look far away. Oh, yes, the smartphone chose this moment to die.

It's getting late, thankfully there's an abandoned cave home nearby.
""",
          "options":[
             {
               "text":"Get in the cave",
               "link":"2",
               "alt-link":"2",
               "dif":0
             },
             {
               "text":"Press on, it's a small island",
               "link":"3",
               "alt-link":"4",
               "dif":3
             }
             ]
        },
  "2": {
          "title":"The cave",
          "text":"""
That was a good idea, the cave keeps you well
protected through the night. It won't be nice, but you'll make it.
""",
          "options": [],
      },
  "3": {
          "title":"Lucky you!",
          "text":"""
You shouldn't have went on, not on a night like this, but you went lucky and you made it to the road where a couple of cops helped you out.
""",
          "options": [],
      },
  "4": {
          "title":"Unlucky you!",
          "text":"""
You shouldn't have went on, not on a night like this, this island is full of very steep slopes, sometimes suddenly so and without warning. You fell into the abyss.
""",
          "options": [],
      },
  "intro": {
          "title":"Introduction",
          "text":"""
This is a short and simple gamebook, comprising 4 sections. Its main purpose is to teach myself how to do interactive fiction on Gemini.

It won't be obvious to you, but the server will be “rolling dice” and loading the relevant section.

That said, it's easy to play, just follow the links
""",
          "options": [{
               "text":"Start the game",
               "link":"1",
               "alt-link":"1",
               "dif":0
             }],
      },
}

def show_section(section):
  print("# Urney.xyz - First Story")
  print("## ", section["title"])
  print(section["text"])
  if len(section["options"]) > 0:
    print("### Options")
    for option in section["options"]:
      dice = randint(1,6)
      if dice > option["dif"]:
        link = "alt-link"
      else:
        link = "link"
      print("=> gemini://urney.xyz/first?" + option[link],  option["text"])
  else:
    print("### The End")
  print("---")

section_id = os.environ.get("QUERY_STRING")

if section_id:
  show_section(sections_dict[section_id])
else:
  show_section(sections_dict["intro"])
#print(os.environ["QUERY_STRING"])

Posted in: s/GmCapsule

🏕️ Yretek

2023-11-15 · 6 months ago


4 Comments ↓


🕹️ skyjake [mod...] · 2023-11-15 at 14:07:

Your CGI script should print a Gemini header line as its first line of output.

print("20 text/gemini\r")

🏕️ Yretek [OP] · 2023-11-15 at 15:53:

Brilliant. That did it. Perhaps it could be included in the documentation as an example.


🕹️ skyjake [mod...] · 2023-11-15 at 18:07:

Hmm yes, adding an example of printing the meta line in the "CGI programs" section would be a good addition, so there's some concreteness to what is being said there. Thanks for the suggestion.


🕹️ skyjake [mod...] · 2023-11-16 at 14:41:

GmCapsule v0.6.1 has been published. The docs now include this example.

-- Response ended

-- Page fetched on Sun May 19 19:39:50 2024