-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
38 lines (30 loc) · 957 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
35
36
37
38
from flask import Flask, request
from flask_cors import CORS, cross_origin
import subprocess
app = Flask(__name__)
CORS(app)
@app.route('/')
def hello_world():
return 'Hello, World!'
def run_scraper(post_count):
# call scraper.py
subprocess.Popen(['python3', 'run.py', '-c', str(post_count)])
@app.route('/scrape', methods=['POST'])
@cross_origin(supports_credentials=True, origins='*')
def scrape_data():
# get params from request
search_terms = request.json['search_terms']
try:
post_count = request.json['post_count']
except:
post_count = 10
print(search_terms)
# populate search.terms file
with open('./search.terms', 'w') as f:
for search_term in search_terms:
f.write(search_term + '\n')
# run scraper.py
run_scraper(post_count)
return f'running scraper.py {post_count} {search_terms}'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001)