-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_wsgi.py
executable file
·53 lines (40 loc) · 1.25 KB
/
app_wsgi.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
from flask import Flask
import CaveiraTech
app = Flask(__name__)
scrappers = {
'CaveiraTech': CaveiraTech.Scrapper()
}
"""
Scrappers Response template:
def getNews(self): {
'title': 'title',
'abstract': 'abstract',
'content': 'content',
'date': 'date',
'more': 'more'
}
"""
@app.route('/aggregators', methods=['GET'])
def get_all_tech_news():
return {
"aggregators": [ {'url':x.url,'aggregator':x.aggregator} for x in scrappers.values()],
"query_example": {
"caveiratech": "/news/caveiratech",
"caveiratech": "/news/caveiratech/<page>"
}
}
@app.route('/news/<scrapper>', methods=['GET'])
def get_tech_news(scrapper):
if scrapper in scrappers.keys():
return scrappers[scrapper].getNews()
return {'error': 'scrapper not found'}
@app.route('/news/<scrapper>/<page>', methods=['GET'])
def get_page_tech_news(page, scrapper):
if scrapper in scrappers.keys():
scrappers[scrapper].toPage(int(page))
return scrappers[scrapper].getNews()
return {'error': 'scrapper not found'}
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000, debug=True)
def create_app():
app.run(host="0.0.0.0", port=8000, debug=True)