forked from yeo09898/Easy_Crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
61 lines (46 loc) · 1.72 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from flask import Flask, request, redirect, url_for, render_template, send_file, send_from_directory, session, \
make_response
import os
#from EC import cralwer
import stackoverflow_scraper
import yelp_scraper
# from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
# app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:shuzi@localhost/Web_Crawler'
app.debug = True
# db = SQLAlchemy(app)
# SESSION_TYPE = 'redis'
class requested_tags():
tags = ""
time = 0
@app.route('/')
def index():
return render_template('index.html')
@app.route('/result/<tags>+<time>')
def result(tags, time):
requested_tags.tags = tags
requested_tags.time = time
return render_template('result.html', tags=requested_tags.tags, time=requested_tags.time)
@app.route('/post_tags', methods=['POST'])
def post_tags():
requested_tags.tags = request.form['tags']
requested_tags.time = int(request.form['time'])
# print requested_tags.tags
# print requested_tags.time
selection = request.form['selection']
# print selection
if selection == "Twitter":
cralwer.get_data(requested_tags.tags, requested_tags.time)
if selection == "Yelp":
yelp_scraper.run(requested_tags.tags, requested_tags.time)
if selection == "Stack Overflow":
stackoverflow_scraper.run(requested_tags.tags, requested_tags.time)
return render_template('result.html', tags=requested_tags.tags, time=requested_tags.time)
@app.route("/download/")
def download_file():
directory = os.getcwd()
return send_from_directory(directory, 'doc/result.csv', as_attachment=True)
if __name__ == "__main__":
app.secret_key = 'super secret key'
app.config['SESSION_TYPE'] = 'redis'
app.run()