1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50import os
from flask import Flask, request, jsonify
from logger.config import logger, configure_logger
from crawls.kraken import setup_kraken_cartocrawler
# Log Emoji: π
app = Flask("A11yπΈοΈ ")
API_KEY = os.environ.get('API_KEY', 'CrawlTheWorld')
configure_logger()
@app.route('/crawl', methods=['POST'])
def crawl_handler():
type = request.args.get('type')
payload = request.get_json()
logger.debug(f"π Request type: {type}")
logger.debug(f"π Request payload: {payload}")
if type == 'kraken':
logger.info('π Kraken π¦ Requested! YOU HAVE UNLEASHED ME!')
logger.debug('π Setting up Kraken cartocrawler')
crawl_started = setup_kraken_cartocrawler() # Store result? Should we?
if crawl_started: # Check the result of the function call
logger.info('π Rolling the Kraken!')
return jsonify({"message": "Crawl started successfully"}), 200
else:
logger.error('π Crawl could not be started')
return jsonify({"error": "π Crawl could not be started"}), 500
elif type == 'harpoon':
logger.info('π Harpoon π― crawl requested')
logger.warning('π This is not implemented yet')
return jsonify({"error": "π This is not implemented yet"}), 501
else:
logger.warning('π What do you want me to do? Invalid URL: %s', type)
return jsonify({"error": "Invalid URL type"}), 400
if __name__ == '__main__':
# Load the host and port from environment vars or set them to the default values
HOST = os.environ.get('HOST', '0.0.0.0')
PORT = int(os.environ.get('PORT', 8084))
logger.info('π Starting π the A11yπͺ΅ Equalify Crawler...')
app.run(host=HOST, port=PORT, threaded=True, debug=True)