-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
34 lines (25 loc) · 902 Bytes
/
app.py
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
from flask import Flask, jsonify, request
from flask_restful import Api, Resource
from scanner import Crawler
app = Flask(__name__)
api = Api(app)
PORT = 1234
HOST = '0.0.0.0'
sampleData = "{'url': 'http://<host>:<port>/', 'depth': '<depth 0-n>'}"
getMessage = "Send a post request to http://localhost:{port}/ with something like: {data}"
class CrawlerApi(Resource):
def get(self):
return {'Name': 'Simple Crawler API',
'Description': getMessage.format(port=PORT,
data=sampleData)}
def post(self):
json_data = request.get_json(force=True)
url = json_data['url']
depth = json_data['depth']
crawlOutput = Crawler.crawl(Crawler(), url, depth)
return jsonify(crawlOutput)
api.add_resource(CrawlerApi, '/')
if __name__ == '__main__':
app.run(host=HOST, port=PORT)