Download app.py from bilico/scrapy: direct link, hf CLI and curl.
- Browser
- Download file 2.24 kB
-
https://huggingface.co/spaces/bilico/scrapy/resolve/main/app.py
- Command line
-
hf download hf://spaces/bilico/scrapy/app.py
-
curl -L -o app.py https://huggingface.co/spaces/bilico/scrapy/resolve/main/app.py
2.24 kB
| import logging | |
| import json | |
| from flask import Flask, jsonify, request | |
| from run_spider import start_spider_thread, spider_mapping | |
| app = Flask(__name__) | |
| # Setup logging for the Flask app | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| def home(): | |
| return """<!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | |
| <title>Glowing Text</title> | |
| <style> | |
| body, html { | |
| height: 100%; | |
| margin: 0; | |
| background: #121212; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
| color: #fff; | |
| } | |
| .glow-text { | |
| font-size: 2.5rem; | |
| font-weight: bold; | |
| text-align: center; | |
| position: relative; | |
| color: #f0f0f0; | |
| text-shadow: | |
| 0 0 8px rgba(255, 255, 255, 0.8), | |
| 0 0 20px rgba(0, 150, 255, 0.7), | |
| 0 0 30px rgba(0, 150, 255, 0.6), | |
| 0 0 40px rgba(0, 150, 255, 0.5); | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="glow-text">You are Just A Draft.<br>Goofing Around</div> | |
| </body> | |
| </html> | |
| """ | |
| def list_scrapers(): | |
| return jsonify(["bookspider", "movierulz", "moviezwap", "quoteSpider"]) | |
| def run_spider(spider_name): | |
| try: | |
| thread = start_spider_thread(spider_name) | |
| logger.info(f"Spider '{spider_name}' started in thread {thread.ident}") | |
| return jsonify({"status": "started", "spider": spider_name}), 202 | |
| except RuntimeError as e: | |
| logger.warning(f"Attempted to start already running spider '{spider_name}'") | |
| return jsonify({"error": str(e)}), 409 # Conflict | |
| except ValueError as e: | |
| logger.error(f"Spider not found: {spider_name}") | |
| return jsonify({"error": str(e)}), 404 # Not found | |
| except Exception as e: | |
| logger.exception("Unexpected error starting spider") | |
| return jsonify({"error": "Internal server error"}), 500 | |
| def health_check(): | |
| return jsonify({"status": "ok"}), 200 | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=7860) | |