#!/usr/bin/env python3 from flask import Flask,abort,jsonify from db import db app = Flask(__name__) d = db() BASEPATH="/pymnts" @app.route(BASEPATH+'/') def index(): return "Hello, World!" @app.route(BASEPATH+'/articles/', methods=['GET']) @app.route(BASEPATH+'/articles', methods=['GET']) def get_articles(): return jsonify({'articles': d.articles(limit=100)}) #limit @app.route(BASEPATH+'/article/', 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/', 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)