Skip to content

Generate randomised journeys to take on the TfL network!

License

Notifications You must be signed in to change notification settings

tramcrazy/Random-TfL-Journey

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Random TfL Journey Planner

Generate randomised journeys to take on the TfL network! Random TfL Journey Planner is a Flask-based web app that invents a random journey, then pulls data from the Tfl API, showing the steps of how to take the journey.

Tech Stack

The app runs on a Flask backend with an Adapt UI frontend. Adapt UI is LiveG's "user interface library and design language for building consistent and appealing products". I used it for this project because, well, I'm on the LiveG staff team and it'd be wrong not to. When you load the page, Flask serves you a static HTML page with Adapt UI's CSS taking care of the UI layout. As soon as you click the Generate Journey button, JavaScript running in your browser makes a request back to the Flask server on /journey. The Flask server chooses two random stations, calls the TfL API to calculate the journey, then returns the journey information to the JavaScript running in the browser. The JavaScript then inserts the data into the placeholder card, and if the app could not find the journey for whatever reason, it inserts an error message and logs the failed response to the console.

Install

Clone this repo

git clone https://github.com/tramcrazy/Random-TfL-Journey/

Grab a TfL API key

  • Go here.
  • Click sign in, then sign up.
  • Once you're signed up and logged in, go to this product page.
  • Come up with a name for the subscription (maybe RandomJourney) and hit Subscribe.
  • Go to your profile.
  • In Subscriptions, click Show next to the Primary Key - that string of letters and numbers is your key.

Change into the right directory

cd Random-TfL-Journey

Set the API key as an environment variable

Linux/macOS (Bash)

export TFL_API_KEY=yourapikeygoeshere

Windows (PowerShell)

$Env:TFL_API_KEY = "yourapikeygoeshere"

Install dependencies

pip install -r requirements.txt

Run!

flask run

Test

Visit http://localhost:5000 Try clicking the generate journey button. Wait a few seconds and a journey should appear! If you get an error, keep trying as the system isn't perfect!

Credits

I used a snippet of Josh Blewitt's code for help with parsing the TfL API responses.

About

Generate randomised journeys to take on the TfL network!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published