-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
29 lines (22 loc) · 812 Bytes
/
main.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
import subprocess
from datetime import datetime
from flask import Flask, render_template, request
from twisted.internet import reactor
from scrapy.crawler import CrawlerRunner
import config
app = Flask(__name__)
@app.route('/')
def scrape():
"""
Run spider in another process and store items in file. Simply issue command:
> scrapy crawl spidername
wait for this command to finish, and read output.json to client.
"""
try:
spider_name = "Amazon"
subprocess.run(['scrapy', 'crawl', spider_name])
except subprocess.CalledProcessError as e:
raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
return ""
if __name__ == '__main__':
app.run(host=config.HOST, port=config.PORT, debug=config.DEBUG)