Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
303 changes: 303 additions & 0 deletions apps/fakefacts/fake_facts.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
"""
Applet: Fake Facts
Summary: Fake facts and quotes
Description: Uses Google Gemini to make up amusing, absurd facts that sound real but aren't, and quotes that famous historical figures never said. Needs your own Gemini API key. If Gemini doesn't answer, the app is skipped.
Author: Jeremy Blaker
"""

load("http.star", "http")
load("random.star", "random")
load("render.star", "canvas", "render")
load("schema.star", "schema")
load("time.star", "time")

MODE_OPTIONS = [("Facts", "facts"), ("Quotes", "quotes"), ("Both", "both")]
DEFAULT_MODE = "both"

GEMINI_URL = "https://generativelanguage.googleapis.com/v1beta/models/gemini-flash-lite-latest:generateContent"

# Lite, not flash-latest: flash is a slow thinking model that often hangs or
# 503s on the free tier, which makes the render time out.

# Cache answers so a free-tier key isn't spent on every render.
CACHE_TTL = 600

# Left to choose, the model keeps falling back to the same few subjects
# (badgers, refrigeration), so we pick a specific topic and angle for it.
TOPICS = [
"medieval castles",
"the Olympic Games",
"volcanoes",
"postage stamps",
"jazz musicians",
"lighthouses",
"the Roman Empire",
"chess",
"deep sea creatures",
"airports",
"Renaissance painters",
"the moon landing",
"cheese making",
"railway history",
"parliamentary procedure",
"socks",
"the Vikings",
"umbrellas",
"bees",
"the stock market",
"ballet",
"glaciers",
"pirates",
"public libraries",
"the human skeleton",
"golf",
"ancient Egypt",
"elevators",
"octopuses",
"the metric system",
"Shakespeare",
"traffic lights",
"penguins",
"the Eiffel Tower",
"dentistry",
"kites",
"the Wild West",
"bread",
"Antarctica",
"the piano",
"street names",
"cloud formations",
"the printing press",
"tea ceremonies",
"hot air balloons",
"crossword puzzles",
"the Great Wall of China",
"garden gnomes",
]

# Long-dead figures only: the quotes are obvious jokes, not words put in a
# living person's mouth.
FIGURES = [
"Napoleon Bonaparte",
"Cleopatra",
"William Shakespeare",
"Abraham Lincoln",
"Isaac Newton",
"Marie Curie",
"Leonardo da Vinci",
"Julius Caesar",
"Queen Victoria",
"Benjamin Franklin",
"Albert Einstein",
"Mark Twain",
"Genghis Khan",
"Ada Lovelace",
"Socrates",
"Confucius",
"Wolfgang Amadeus Mozart",
"Ludwig van Beethoven",
"Charles Darwin",
"Galileo Galilei",
"Nikola Tesla",
"Amelia Earhart",
"Theodore Roosevelt",
"Henry VIII",
"Queen Elizabeth I",
"Vincent van Gogh",
"Oscar Wilde",
"Jane Austen",
"Edgar Allan Poe",
"Thomas Edison",
"Joan of Arc",
"Charles Dickens",
"Aristotle",
"Florence Nightingale",
]

ANGLES = [
"an obscure law that is supposedly still in force",
"a surprising statistic",
"a historical accident with lasting consequences",
"a scientific study with an odd finding",
"the surprising origin of a name or word",
"a royal decree",
"an unusual world record",
"a forgotten invention",
"a strange tradition",
"a famous person's little-known habit",
]

PROMPT_TEMPLATE = (
"Write one amusing, absurd, completely made-up fact that sounds real but is false. " +
"Topic: %s. Frame it as %s. " +
"State it confidently like a trivia fact. Under 140 characters, one sentence, plain text, no quotes, no markdown, no preamble."
)

# bg: background, text: fact/quote text, accent: quote attribution
THEMES = {
"tabloid": {"name": "Tabloid", "accent": "#FFD700", "bg": "#000000", "text": "#FFFFFF"},
"chalkboard": {"name": "Chalkboard", "accent": "#F5E6C8", "bg": "#123D2B", "text": "#E8E8E0"},
"terminal": {"name": "Terminal", "accent": "#33FF33", "bg": "#000000", "text": "#33FF33"},
"encyclopedia": {"name": "Encyclopedia", "accent": "#E8C872", "bg": "#0A0F24", "text": "#F0E6D2"},
}
THEME_ORDER = ["tabloid", "chalkboard", "terminal", "encyclopedia"]
DEFAULT_THEME = "tabloid"

QUOTE_TEMPLATE = (
"Write one amusing, absurd, completely made-up quote that %s never actually said, about %s. " +
"Make it sound like their voice and era, confident and quotable. " +
"Under 120 characters, plain text, no quotation marks, no attribution, no markdown, no preamble."
)

WIDTH, HEIGHT = canvas.size()
SCALE = 2 if canvas.is2x() else 1
BODY_FONT = "terminus-16" if canvas.is2x() else "tb-8"

def main(config):
"""Render a fake fact or quote from Gemini, or skip the app if none is available.

Args:
config: App config holding the user's Gemini API key, mode and theme.

Returns:
A render.Root, or [] to skip this cycle.
"""

# Seed by cache window so the prompt (and so the cached reply) holds
# steady for CACHE_TTL, then moves to a new topic.
random.seed(time.now().unix // CACHE_TTL)
topic = TOPICS[random.number(0, len(TOPICS) - 1)]

mode = config.get("mode", DEFAULT_MODE)
if mode == "both":
mode = "quotes" if random.number(0, 1) else "facts"

if mode == "quotes":
figure = FIGURES[random.number(0, len(FIGURES) - 1)]
prompt = QUOTE_TEMPLATE % (figure, topic)
else:
figure = None
angle = ANGLES[random.number(0, len(ANGLES) - 1)]
prompt = PROMPT_TEMPLATE % (topic, angle)

text = fetch_text(config.get("api_key"), prompt)
if not text:
return []

theme_key = config.get("theme", DEFAULT_THEME)
if theme_key == "random":
theme_key = THEME_ORDER[random.number(0, len(THEME_ORDER) - 1)]
theme = THEMES.get(theme_key, THEMES[DEFAULT_THEME])

return render.Root(
delay = 100 // SCALE,
show_full_animation = True,
child = render.Box(
color = theme["bg"],
child = render.Marquee(
width = WIDTH,
height = HEIGHT,
scroll_direction = "vertical",
offset_start = HEIGHT,
child = render_body(text, figure, theme),
),
),
)

def render_body(text, figure, theme):
"""Lay out the fact, or the quote with its attribution underneath.

Args:
text: The fact or quote text.
figure: Who the quote is attributed to, or None for a fact.
theme: The theme dict to colour with.

Returns:
A widget for the scrolling body.
"""
if not figure:
return render.WrappedText(text, width = WIDTH, font = BODY_FONT, color = theme["text"])

return render.Column(
children = [
render.WrappedText("\"%s\"" % text, width = WIDTH, font = BODY_FONT, color = theme["text"]),
render.WrappedText("- " + figure, width = WIDTH, font = BODY_FONT, color = theme["accent"]),
],
)

def fetch_text(api_key, prompt):
"""Ask Gemini for a fake fact or quote.

Args:
api_key: The user's Gemini API key; may be None or empty.
prompt: The prompt text to send.

Returns:
The text as a string, or None on any failure (no key, HTTP error,
timeout, quota, blocked or malformed response).
"""
if not api_key:
return None

resp = http.post(
GEMINI_URL,
headers = {"x-goog-api-key": api_key, "Content-Type": "application/json"},
json_body = {
"contents": [{"parts": [{"text": prompt}]}],
"generationConfig": {"temperature": 1.5, "maxOutputTokens": 200},
},
ttl_seconds = CACHE_TTL,
)
if resp.status_code != 200:
return None

# Untrusted response: walk it defensively since Starlark can't catch errors.
body = resp.json()
candidates = body.get("candidates") if type(body) == "dict" else None
if type(candidates) != "list" or not candidates or type(candidates[0]) != "dict":
return None
content = candidates[0].get("content")
parts = content.get("parts") if type(content) == "dict" else None
if type(parts) != "list":
return None

text = "".join([p["text"] for p in parts if type(p) == "dict" and type(p.get("text")) == "string"])
text = " ".join(text.split()).strip("\"' ")
return text or None

def get_schema():
"""Define the app's settings.

Returns:
A schema.Schema with the Gemini API key, mode and theme fields.
"""
return schema.Schema(
version = "1",
fields = [
schema.Text(
id = "api_key",
name = "Gemini API key",
desc = "Free key from aistudio.google.com/apikey",
icon = "key",
secret = True,
),
schema.Dropdown(
id = "mode",
name = "Show",
desc = "Fake facts, fake quotes from historical figures, or a mix.",
icon = "shuffle",
default = DEFAULT_MODE,
options = [schema.Option(display = d, value = v) for d, v in MODE_OPTIONS],
),
schema.Dropdown(
id = "theme",
name = "Theme",
desc = "How the fact looks.",
icon = "palette",
default = DEFAULT_THEME,
options = [schema.Option(display = THEMES[k]["name"], value = k) for k in THEME_ORDER] + [
schema.Option(display = "Random", value = "random"),
],
),
],
)
Binary file added apps/fakefacts/fakefacts.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/fakefacts/fakefacts@2x.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/fakefacts/fakefacts@64x64.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions apps/fakefacts/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
id: fake-facts
name: Fake Facts
summary: Fake facts and quotes
desc: Uses Google Gemini to make up amusing, absurd facts that sound real but aren't, and quotes that famous historical figures never said. Needs your own Gemini API key. If Gemini doesn't answer, the app is skipped.
author: Jeremy Blaker
fileName: fake_facts.star
packageName: fakefacts
recommendedInterval: 10
supports64x64: true
category: entertainment
tags:
- fun
- trivia
- quotes
published: '2026-11-28T00:00:00Z'
updated: '2026-12-01T18:37:33Z'