| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #!/usr/bin/env python3
- from flask import Flask,abort,jsonify,request
- from db import db
- import json
- from linklist import LinkList
- app = Flask(__name__)
- d = db()
- BASEPATH="/pymnts"
- @app.route(BASEPATH+'/')
- def index():
- return "Hello, World!"
- @app.route(BASEPATH+'/source/add/', methods=['POST'])
- def add_source():
- selector=None
- rss=False
- json=request.get_json()
- if "selector" in json:
- selector=json["selector"]
- if "rss" in json:
- rss=json["rss"]
- if "category" not in json:
- json["category"]=1
-
- json["category"]=int(json["category"])
- d.add_source(json["source"],rss,selector,json["name"],json["category"])
- return jsonify({'ok': "ok"})
- @app.route(BASEPATH+'/source/test/', methods=['POST'])
- def test_source():
- selector=None
- rss=False
- json=request.get_json()
- if "selector" in json and len(json["selector"]) >0:
- selector=json["selector"]
- if "rss" in json:
- rss=json["rss"]
- l=LinkList(json["source"],selector,rss=rss)
- return jsonify({'links': l.links})
- @app.route(BASEPATH+'/articles/', methods=['POST'])
- @app.route(BASEPATH+'/articles', methods=['POST'])
- def filter_articles():
- return jsonify(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(d.filter_articles({},limit=15))
- @app.route(BASEPATH+'/article/delete/<string:art_id>', methods=['GET'])
- def delete_article(art_id):
- if not d.delete_article(art_id):
- abort(401)
- return jsonify({'ok':"ok"})
- @app.route(BASEPATH+'/article/<string:art_id>', methods=['GET'])
- def get_article(art_id):
- art=d.article(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(host="0.0.0.0",debug=True)
|