Spaces:
Sleeping
Sleeping
Download app.py from MSivasandeep/EasyTicket: direct link, hf CLI and curl.
- Browser
- Download file 6.38 kB
-
https://huggingface.co/spaces/MSivasandeep/EasyTicket/resolve/main/app.py
- Command line
-
hf download hf://spaces/MSivasandeep/EasyTicket/app.py
-
curl -L -o app.py https://huggingface.co/spaces/MSivasandeep/EasyTicket/resolve/main/app.py
6.38 kB
| from flask import Flask, render_template, request, jsonify, session, redirect, url_for | |
| from datetime import datetime, timedelta | |
| import json | |
| import os | |
| import uuid | |
| app = Flask(__name__) | |
| app.secret_key = os.environ.get('SECRET_KEY', 'dev-secret-key') | |
| app.config['SESSION_TYPE'] = 'filesystem' | |
| # Sample data for Indian museums | |
| MUSEUMS = { | |
| "national_museum": { | |
| "id": "national_museum", | |
| "name": "National Museum, New Delhi", | |
| "location": "New Delhi", | |
| "description": "One of India's largest museums with over 200,000 artifacts spanning 5,000 years of Indian history.", | |
| "price": 50, | |
| "image": "https://images.unsplash.com/photo-1591386768477-84ff7c578a13?w=400&h=300&fit=crop", | |
| "languages": ["Hindi", "English", "Tamil", "Bengali"], | |
| "timings": "10:00 AM - 6:00 PM", | |
| "closed_on": "Monday" | |
| }, | |
| "indian_museum": { | |
| "id": "indian_museum", | |
| "name": "Indian Museum, Kolkata", | |
| "location": "Kolkata", | |
| "description": "Established in 1814, it is the oldest and largest museum in India with rare collections of antiques.", | |
| "price": 20, | |
| "image": "https://images.unsplash.com/photo-1578662996442-48f60103fc96?w=400&h=300&fit=crop", | |
| "languages": ["Hindi", "English", "Bengali"], | |
| "timings": "10:00 AM - 5:00 PM", | |
| "closed_on": "Monday" | |
| }, | |
| "chhatrapati_museum": { | |
| "id": "chhatrapati_museum", | |
| "name": "Chhatrapati Shivaji Maharaj Vastu Sangrahalaya, Mumbai", | |
| "location": "Mumbai", | |
| "description": "Formerly Prince of Wales Museum, features Indo-Saracenic architecture and over 50,000 exhibits.", | |
| "price": 100, | |
| "image": "https://images.unsplash.com/photo-1580503593984-6d6d4e8da530?w=400&h=300&fit=crop", | |
| "languages": ["Hindi", "English", "Marathi"], | |
| "timings": "10:15 AM - 6:00 PM", | |
| "closed_on": "Monday" | |
| }, | |
| "salar_jung": { | |
| "id": "salar_jung", | |
| "name": "Salar Jung Museum, Hyderabad", | |
| "location": "Hyderabad", | |
| "description": "Third largest museum in India featuring one-man collections of Nawab Mir Yousuf Ali Khan.", | |
| "price": 20, | |
| "image": "https://images.unsplash.com/photo-1578662996442-48f60103fc96?w=400&h=300&fit=crop", | |
| "languages": ["Hindi", "English", "Telugu", "Urdu"], | |
| "timings": "10:00 AM - 5:00 PM", | |
| "closed_on": "Friday" | |
| } | |
| } | |
| # Available time slots | |
| TIME_SLOTS = [ | |
| "10:00 AM - 11:00 AM", | |
| "11:00 AM - 12:00 PM", | |
| "12:00 PM - 01:00 PM", | |
| "02:00 PM - 03:00 PM", | |
| "03:00 PM - 04:00 PM", | |
| "04:00 PM - 05:00 PM" | |
| ] | |
| # Store bookings (in production, use a database) | |
| bookings = {} | |
| def home(): | |
| return render_template('index.html') | |
| def museums(): | |
| return render_template('museums.html', museums=MUSEUMS) | |
| def museum_detail(museum_id): | |
| museum = MUSEUMS.get(museum_id) | |
| if not museum: | |
| return redirect(url_for('museums')) | |
| # Set current date for minimum date in form | |
| current_date = datetime.now().strftime('%Y-%m-%d') | |
| return render_template('booking.html', museum=museum, time_slots=TIME_SLOTS, now=current_date) | |
| def book_ticket(): | |
| try: | |
| data = request.get_json() | |
| # Validate required fields | |
| required_fields = ['museum_id', 'visit_date', 'time_slot', 'visitors', 'name', 'email', 'phone'] | |
| for field in required_fields: | |
| if field not in data or not data[field]: | |
| return jsonify({'success': False, 'error': f'Missing field: {field}'}) | |
| museum_id = data['museum_id'] | |
| if museum_id not in MUSEUMS: | |
| return jsonify({'success': False, 'error': 'Invalid museum'}) | |
| # Generate booking ID | |
| booking_id = str(uuid.uuid4())[:8].upper() | |
| # Calculate total amount | |
| museum = MUSEUMS[museum_id] | |
| total_amount = museum['price'] * int(data['visitors']) | |
| # Create booking record | |
| booking = { | |
| 'booking_id': booking_id, | |
| 'museum_id': museum_id, | |
| 'museum_name': museum['name'], | |
| 'visit_date': data['visit_date'], | |
| 'time_slot': data['time_slot'], | |
| 'visitors': int(data['visitors']), | |
| 'total_amount': total_amount, | |
| 'customer_name': data['name'], | |
| 'customer_email': data['email'], | |
| 'customer_phone': data['phone'], | |
| 'language': data.get('language', 'English'), | |
| 'booking_date': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), | |
| 'status': 'confirmed' | |
| } | |
| # Store booking | |
| bookings[booking_id] = booking | |
| return jsonify({ | |
| 'success': True, | |
| 'booking_id': booking_id, | |
| 'booking': booking | |
| }) | |
| except Exception as e: | |
| return jsonify({'success': False, 'error': str(e)}) | |
| def booking_confirmation(booking_id): | |
| booking = bookings.get(booking_id) | |
| if not booking: | |
| return redirect(url_for('home')) | |
| return render_template('confirmation.html', booking=booking) | |
| def check_availability(): | |
| data = request.get_json() | |
| museum_id = data.get('museum_id') | |
| visit_date = data.get('visit_date') | |
| time_slot = data.get('time_slot') | |
| # Simple availability check (in production, check against actual bookings) | |
| capacity = 50 # Maximum visitors per slot | |
| # Count existing bookings for this slot | |
| booked_count = sum( | |
| 1 for booking in bookings.values() | |
| if (booking['museum_id'] == museum_id and | |
| booking['visit_date'] == visit_date and | |
| booking['time_slot'] == time_slot) | |
| ) | |
| available_slots = capacity - booked_count | |
| return jsonify({ | |
| 'available': available_slots > 0, | |
| 'available_slots': available_slots, | |
| 'capacity': capacity | |
| }) | |
| def get_museums(): | |
| return jsonify(MUSEUMS) | |
| def health_check(): | |
| return jsonify({'status': 'healthy', 'timestamp': datetime.now().isoformat()}) | |
| if __name__ == '__main__': | |
| app.run(debug=False, host='0.0.0.0', port=7860) |