Skip to content

Commit

Permalink
add GTFS-RT Header Display
Browse files Browse the repository at this point in the history
add GTFS-RT Header display
  • Loading branch information
Amaury-DB committed Aug 23, 2024
1 parent cae177e commit 12d9ede
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@

## Description

GTFS-RT Validator is a simple web application built with Flask that allows users to validate the correctness of GTFS-RT (General Transit Feed Specification - Realtime) feeds. Users can input the URL of a GTFS-RT feed, and the application will check if the feed is valid according to the GTFS-RT specification.
GTFS-RT Validator is a simple web application built with Flask that allows users to validate the correctness of GTFS-RT (General Transit Feed Specification - Realtime) feeds. Users can input the URL of a GTFS-RT feed, and the application will check if the feed is valid according to the GTFS-RT specification. If valid, an extract of the feed is displayed on the webpage.

## Features

- **URL Validation:** Ensures the provided GTFS-RT feed URL is valid.
- **GTFS-RT Validation:** Parses and validates the GTFS-RT feed to ensure it conforms to the expected format.
- **Feed Extract Display:** Displays an extract of the GTFS-RT feed if it is valid.
- **User-Friendly Interface:** Simple and intuitive web interface for easy use.

## Prerequisites

- Python 3.x
- Pip (Python package manager)
- `protoc` (Protocol Buffers compiler)

## Installation

1. **Clone the repository:**

```bash
git clone https://github.com/Amaury-DB/gtfs-rt-validator.git
git clone https://github.com/yourusername/gtfs-rt-validator.git
cd gtfs-rt-validator
```

Expand All @@ -30,41 +32,44 @@ GTFS-RT Validator is a simple web application built with Flask that allows users
pip install -r requirements.txt
```

If `requirements.txt` does not exist, manually install the dependencies:
3. **Generate the `gtfs_realtime_pb2.py` file:**

Download the GTFS-Realtime `.proto` file and generate the Python file:

```bash
pip install flask protobuf validators
wget https://raw.githubusercontent.com/google/transit/master/gtfs-realtime/proto/gtfs-realtime.proto
protoc --python_out=. gtfs-realtime.proto
```

## Usage

1. **Run the application:**

```bash
python app.py
sudo python app.py
```

2. **Access the application:**

Open your web browser and navigate to `http://127.0.0.1:5000/`.
Open your web browser and navigate to `http://[hostname or IP]`.

3. **Validate a GTFS-RT feed:**

- Enter the URL of a GTFS-RT feed in the provided input field.
- Click on the "Validate" button to check the validity of the feed.
- The result of the validation will be displayed on the screen.
- If the feed is valid, an extract will be displayed on the webpage.

## Project Structure

```
gtfs_rt_validator/
gtfs-rt-validator/
├── app.py # Main Flask application
├── gtfs_realtime_pb2.py # Generated Python file from .proto
├── templates/
│ └── index.html # HTML template for the web interface
└── static/
└── style.css # CSS file for styling the interface
```
├── static/
│ └── style.css # CSS file for styling the interface
├── requirements.txt # Python dependencies
└── README.md # Project documentation

## Contributing

Expand All @@ -79,3 +84,7 @@ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file
- [Flask](https://flask.palletsprojects.com/) - A lightweight WSGI web application framework in Python.
- [GTFS Realtime](https://developers.google.com/transit/gtfs-realtime) - Real-time public transit data specification.
- [Protobuf](https://developers.google.com/protocol-buffers) - Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data.
## Author
© Amaury DUCHENE 2024
4 changes: 3 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import gtfs_realtime_pb2
import validators
import urllib.request
import google.protobuf.json_format as json_format

app = Flask(__name__)

Expand All @@ -21,11 +22,12 @@ def validate_gtfs_rt(url):
feed = gtfs_realtime_pb2.FeedMessage()
try:
feed.ParseFromString(feed_data)
feed_json = json_format.MessageToJson(feed) # Convert feed to JSON
except Exception as e:
return {"status": "error", "message": f"Error parsing GTFS-RT data: {str(e)}"}

# Si tout est valide
return {"status": "success", "message": "GTFS-RT feed is valid."}
return {"status": "success", "message": "GTFS-RT feed is valid.", "feed_extract": feed_json}

@app.route('/')
def index():
Expand Down
16 changes: 16 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GTFS-RT Validator</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<style>
footer {
text-align: center;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
Expand All @@ -15,7 +21,11 @@ <h1>GTFS-RT Validator</h1>
<button type="submit">Validate</button>
</form>
<div id="result"></div>
<div id="feed-extract"></div>
</div>
<footer>
<p>© Amaury DUCHENE 2024</p>
</footer>

<script>
document.getElementById('gtfs-form').addEventListener('submit', function(event) {
Expand All @@ -32,10 +42,16 @@ <h1>GTFS-RT Validator</h1>
.then(response => response.json())
.then(data => {
var resultDiv = document.getElementById('result');
var feedExtractDiv = document.getElementById('feed-extract');

if (data.status === 'success') {
resultDiv.innerHTML = '<p class="success">' + data.message + '</p>';
var feedExtract = JSON.parse(data.feed_extract);
var feedExtractHTML = '<pre>' + JSON.stringify(feedExtract, null, 2) + '</pre>';
feedExtractDiv.innerHTML = feedExtractHTML;
} else {
resultDiv.innerHTML = '<p class="error">' + data.message + '</p>';
feedExtractDiv.innerHTML = '';
}
});
});
Expand Down

0 comments on commit 12d9ede

Please sign in to comment.