| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #!/usr/bin/env python3
- from flask import Flask,abort,jsonify,request
- from db import db
- import json
- app = Flask(__name__)
- d = db()
- BASEPATH="/pymnts"
- @app.route(BASEPATH+'/')
- def index():
- return "Hello, World!"
- @app.route(BASEPATH+'/articles/', methods=['POST'])
- @app.route(BASEPATH+'/articles', methods=['POST'])
- def filter_articles():
- return jsonify({'articles': d.filter_articles(request.get_json(),limit=15)})
- @app.route(BASEPATH+'/keywords/', methods=['GET'])
- @app.route(BASEPATH+'/keywords', methods=['GET'])
- def get_keywords():
- return jsonify({'keywords': d.get_keywords_list()}) #limit
- @app.route(BASEPATH+'/articles/', methods=['GET'])
- @app.route(BASEPATH+'/articles', methods=['GET'])
- def get_articles():
- return jsonify({'articles': d.articles(limit=80)}) #limit
- @app.route(BASEPATH+'/article/<string:art_id>', methods=['GET'])
- def get_article(art_id):
- art=d.articles(id=art_id)
- if art is None:
- abort(401)
- return jsonify({'articles': art})
- @app.route(BASEPATH+'/sources/', methods=['GET'])
- @app.route(BASEPATH+'/sources', methods=['GET'])
- def get_sources():
- return jsonify({'sources': d.sources()})
- @app.route(BASEPATH+'/sources/<string:source_id>', methods=['GET'])
- def get_source(source_id):
- source=d.sources(source_id)
- if source is None:
- abort(401)
- return jsonify({'source': source})
- @app.route(BASEPATH+'/add_source', methods=['POST'])
- def create_task():
- if not request.json or not 'title' in request.json:
- abort(400)
- task = {
- 'id': tasks[-1]['id'] + 1,
- 'title': request.json['title'],
- 'description': request.json.get('description', ""),
- 'done': False
- }
- tasks.append(task)
- return jsonify({'task': task}), 201
- if __name__ == '__main__':
- app.run(debug=True)
|