aboutsummaryrefslogtreecommitdiff
path: root/scrape_ecourtindia_v6/web.py
blob: 9c6b111fa2315a437fd902dee33343ba7e277b56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
from flask import Flask, send_from_directory, abort

app = Flask(__name__)

PDF_DIRECTORY = './pdf'

@app.route('/pdf/<filename>')
def view_pdf(filename):
    try:
        if not filename.endswith('.pdf'):
            abort(400, description="Invalid file type. Only PDF files are allowed.")
        
        filepath = os.path.join(PDF_DIRECTORY, filename)
        if not os.path.exists(filepath):
            abort(404, description="PDF file not found")
        
        return send_from_directory(PDF_DIRECTORY, filename, as_attachment=False)
    
    except Exception as e:
        abort(500, description=f"Internal server error: {str(e)}")

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)