Skip to content

Instantly share code, notes, and snippets.

@jcrist
Created August 25, 2022 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcrist/c4bf065c2c2e84d11a996fafb4895bbc to your computer and use it in GitHub Desktop.
Save jcrist/c4bf065c2c2e84d11a996fafb4895bbc to your computer and use it in GitHub Desktop.
Clips from a tweet about ibis-datasette analyzing the scotrail datasette
import ibis
from ibis import _
con = ibis.datasette.connect("https://scotrail.datasette.io/scotrail")
t = con.tables.announcements
def random(category):
return (
t.filter(_.Category == category)
.sort_by(ibis.random())
.limit(1)
)
def phrase(text):
return t.filter(_.Transcription == text).limit(1)
query = ibis.union(
random("Apology"),
random("Train operating company"),
random("Destination"),
phrase("has been cancelled"),
phrase("due to"),
random("Reason"),
).Transcription.group_concat(" ")
print(query.execute())
# 'I am sorry to announce that the Southeastern service to Bentley has been
# cancelled due to Overcrowding because of a football match'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment