David 10 سال پیش
والد
کامیت
08628c3289
4فایلهای تغییر یافته به همراه40 افزوده شده و 16 حذف شده
  1. 2 2
      db.py
  2. 25 2
      front/index.html
  3. 2 2
      front/js/app.js
  4. 11 10
      web.py

+ 2 - 2
db.py

@@ -17,9 +17,9 @@ class db():
         return el
 
 
-    def articles(self, id=None):
+    def articles(self, id=None, limit=100):
         if id is None:
-            return [ self.jsonable(p) for p in self.c_articles.find() ]
+            return [ self.jsonable(p) for p in self.c_articles.find().limit(limit) ]
 
         ret=self.c_articles.find_one({"_id":ObjectId(id)})
         return self.jsonable(ret)

+ 25 - 2
front/index.html

@@ -19,8 +19,31 @@
 			<div class="col-sm-2 col-md-2 col-lg-2 col-xl-2" style="min-height:100%;background-color:red">
 			</div>
 			<div class="col-sm-4 col-md-4 col-lg-4 col-xl-4" style="min-height:100%;background-color:blue">
-				<div class="row" ng-repeat="n in news">
-					news:
+				<div class="row" style="background-color:white; border:1px solid black" ng-repeat="n in news">
+					<div class="col-md-12">
+						<div class="row">
+							<div class="col-md-7">
+							</div>
+							<div class="col-md-5">
+								{{n.scrap_date}}
+							</div>
+						</div>
+						<!--
+						source: {{n.source}}
+						-->
+						<div class="summary" style="font-size:11px">
+							{{n.summary}}
+						</div>
+							<div class="row">
+								<div class="col-md-7">
+									<a ng-href="{{n.url}}">Visit site</a>
+								</div>
+								<div class="col-md-5">
+									<a ng-click="getArticle(n._id)">Read complete article</a>
+								</div>
+							</div>
+						Keyword(s): {{n.kw.join(", ")}}
+					</div>
 				</div>
 			</div>
 			<div class="col-sm-6 col-md-6 col-lg-6 col-xl-6" style="min-height:100%;background-color:green">

+ 2 - 2
front/js/app.js

@@ -4,7 +4,7 @@ app.controller('main', function($scope,$http) {
 	$scope.news=[];
 
 	$scope.getNews = function() {
-		$http.get("/news/").then(
+		$http.get("/pymnts/articles/").then(
 		function(data) {
 			/*
 			data.data=data.data.map(function(el) {
@@ -13,7 +13,7 @@ app.controller('main', function($scope,$http) {
 				return el;
 			});
 			*/
-			$scope.news=data.data;
+			$scope.news=data.data.articles;
 		},
 		function(data){
 			console.log("error");

+ 11 - 10
web.py

@@ -7,28 +7,29 @@ app = Flask(__name__)
 d = db()
 
 
-@app.route('/')
+BASEPATH="/pymnts"
+@app.route(BASEPATH+'/')
 def index():
     return "Hello, World!"
 
-@app.route('/articles/', methods=['GET'])
-@app.route('/articles', methods=['GET'])
+@app.route(BASEPATH+'/articles/', methods=['GET'])
+@app.route(BASEPATH+'/articles', methods=['GET'])
 def get_articles():
-    return jsonify({'articles': d.articles()})
+    return jsonify({'articles': d.articles(limit=100)}) #limit
 
-@app.route('/articles/<string:art_id>', methods=['GET'])
+@app.route(BASEPATH+'/article/<string:art_id>', methods=['GET'])
 def get_article(art_id):
-    art=d.articles(art_id)
+    art=d.articles(id=art_id)
     if art is None:
         abort(401)
     return jsonify({'articles': art})
 
-@app.route('/sources/', methods=['GET'])
-@app.route('/sources', methods=['GET'])
+@app.route(BASEPATH+'/sources/', methods=['GET'])
+@app.route(BASEPATH+'/sources', methods=['GET'])
 def get_sources():
     return jsonify({'sources': d.sources()})
 
-@app.route('/sources/<string:source_id>', methods=['GET'])
+@app.route(BASEPATH+'/sources/<string:source_id>', methods=['GET'])
 def get_source(source_id):
     source=d.sources(source_id)
     if source is None:
@@ -36,7 +37,7 @@ def get_source(source_id):
     return jsonify({'source': source})
 
 
-@app.route('/add_source', methods=['POST'])
+@app.route(BASEPATH+'/add_source', methods=['POST'])
 def create_task():
     if not request.json or not 'title' in request.json:
         abort(400)