2021-05-18 22:46:14 +00:00
|
|
|
import os
|
|
|
|
|
2021-04-07 21:34:08 +00:00
|
|
|
from flask import Flask
|
2021-04-14 16:52:22 +00:00
|
|
|
from flask_restful import Resource, Api, reqparse
|
2021-04-07 21:34:08 +00:00
|
|
|
|
2021-05-18 22:46:14 +00:00
|
|
|
import crawler
|
|
|
|
|
2021-04-07 21:34:08 +00:00
|
|
|
app = Flask(__name__)
|
|
|
|
api = Api(app)
|
|
|
|
|
2021-04-14 16:52:22 +00:00
|
|
|
# To parse request data
|
|
|
|
parser = reqparse.RequestParser()
|
2021-05-18 22:46:14 +00:00
|
|
|
parser.add_argument('key', type=str)
|
|
|
|
parser.add_argument('products', type=int, action='append')
|
2021-04-14 16:52:22 +00:00
|
|
|
|
2021-04-07 21:34:08 +00:00
|
|
|
|
|
|
|
class CrawlerApi(Resource):
|
|
|
|
def get(self):
|
|
|
|
return {'Hallo': 'Betterzon'}
|
|
|
|
|
2021-04-14 16:52:22 +00:00
|
|
|
def post(self):
|
|
|
|
# Accept crawler request here
|
|
|
|
args = parser.parse_args()
|
2021-05-18 22:46:14 +00:00
|
|
|
access_key = os.getenv('CRAWLER_ACCESS_KEY')
|
|
|
|
if(args['key'] == access_key):
|
|
|
|
crawler.crawl(args['products'])
|
|
|
|
return {'message': 'success'}
|
|
|
|
else:
|
|
|
|
return {'message': 'Wrong access key'}
|
2021-04-14 16:52:22 +00:00
|
|
|
|
2021-04-07 21:34:08 +00:00
|
|
|
|
|
|
|
api.add_resource(CrawlerApi, '/')
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(host='0.0.0.0', port=22026)
|