clean
Diff
scrape_ecourtindia_v6/web.py | 49 +------------------------------------------------
1 file changed, 1 insertion(+), 48 deletions(-)
@@ -1,72 +1,25 @@
import os
from flask import Flask, send_from_directory, abort
app = Flask(__name__)
PDF_DIRECTORY = './pdf'
@app.route('/pdf/<filename>')
def view_pdf(filename):
"""
Route to view a PDF file from the specified directory.
Args:
filename (str): Name of the PDF file to display
Returns:
PDF file or 404 error if file doesn't exist
"""
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)}")
@app.route('/pdf')
def list_pdfs():
"""
Route to list all available PDF files in the directory.
Returns:
HTML page with list of PDFs or error message
"""
try:
pdf_files = [f for f in os.listdir(PDF_DIRECTORY) if f.endswith('.pdf')]
pdf_links = "\n".join([
f'<li><a href="/pdf/{file}">{file}</a></li>'
for file in pdf_files
])
return f"""
<html>
<head><title>PDF Viewer</title></head>
<body>
<h1>Available PDFs</h1>
<ul>{pdf_links}</ul>
</body>
</html>
"""
except Exception as e:
abort(500, description=f"Error listing PDFs: {str(e)}")
if __name__ == '__main__':
os.makedirs(PDF_DIRECTORY, exist_ok=True)
app.run(host='0.0.0.0', port=8000, debug=True)
app.run(host='0.0.0.0', port=8000)