diff --git a/README.md b/README.md index 1019fb8..583f169 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -30,10 +32,13 @@ 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 @@ -41,30 +46,30 @@ GTFS-RT Validator is a simple web application built with Flask that allows users 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 @@ -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 diff --git a/app.py b/app.py index 62f842a..cfba1f6 100644 --- a/app.py +++ b/app.py @@ -2,6 +2,7 @@ import gtfs_realtime_pb2 import validators import urllib.request +import google.protobuf.json_format as json_format app = Flask(__name__) @@ -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(): diff --git a/templates/index.html b/templates/index.html index ce5563b..81bfb0a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,6 +5,12 @@