-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
37 lines (25 loc) · 958 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
# Working URL Example: http://127.0.0.1:5000/rest?hashtag=trump&duration=20 - Replace Trump with any other word and
# 20 seconds with any other duration in seconds
# http://127.0.0.1:5000/home - home page
# http://127.0.0.1:5000/about - about page
# Error Handling to be added - duration value of not an integer will crash
import tweetcollector as tc
from flask import Flask, render_template, jsonify, request
app = Flask(__name__)
# Route to get a response for a hashtag
@app.route('/rest', methods=['GET'])
def rest():
hashtag = request.args.get('hashtag')
duration = int(request.args.get('duration'))
my_result = tc.SetupTweetCollector(hashtag, duration)
return jsonify(my_result.retrieve())
# Home page route
@app.route('/home')
def home():
return render_template('home.html')
# About page route
@app.route('/about')
def about():
return render_template('about.html')
if __name__ == '__main__':
app.run(debug=True)