Created
August 25, 2022 13:21
-
-
Save jcrist/c4bf065c2c2e84d11a996fafb4895bbc to your computer and use it in GitHub Desktop.
Clips from a tweet about ibis-datasette analyzing the scotrail datasette
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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