Commits

ronald martinez committed fbbabac

ok

  • Participants
  • Parent commits e716223

Comments (0)

Files changed (4)

 db.metadata.drop()
 db.metadata.insert(dict(id=1))
 
-
 total_posts = 0
 total_posts_likes = 0
 
             urllib.urlencode(params)
         )
 
-    print "url: %s" % url
-
     try:
         data = json.loads(urllib.urlopen(url).read())
     except IOError as exc:
 
     if items:
 
-        #post = db.progress.find_one({'id': 1})
-
         for x in items:
-
             db.metadata.update(
                 {'id': 1}, {
                     '$inc': {'count_posts': 1}
                 }
             )
 
-            #total_posts += 1
-
             if 'likes' in x.keys():
 
                 db.metadata.update(
                     }
                 )
 
-                #total_posts_likes += 1
-
-                """
                 get_likes.delay(
                     post_id=x.get('id'),
                     total_likes=x.get('likes').get('count')
                 )
-                """
 
         paging = data.get('paging')
 
         if 'next' in paging:
             posts(url=paging.get('next'))
 
-    """
-    db.metadata.update({}, dict(
-        total_posts=total_posts,
-        total_posts_likes=total_posts_likes
-    ))
-    """
-
 
 if __name__ == "__main__":
     tstart = datetime.now()
     posts()
-
-    """
-    db.metadata.insert(dict(
-        total_posts=total_posts,
-        total_posts_likes=total_posts_likes
-    ))
-    """
-
     tend = datetime.now()
     print 'estimated_time: %s' % (tend - tstart)
 @app.route('/get_metadata')
 def get_metadata():
     item = db.metadata.find_one({'id': 1})
+
+    count_posts = '0'
+
+    if 'count_posts' in item:
+        count_posts = item['count_posts']
+
+    count_likes = '0'
+
+    if 'count_likes' in item:
+        count_likes = item['count_likes']
+
     return jsonify(
-        count_posts=str(item['count_posts']),
-        count_likes=str(item['count_likes']),
+        count_posts=count_posts,
+        count_likes=count_likes,
     )
 
+
 @app.route('/get_percent/<post_id>')
 def get_percent(post_id):
     item = db.progress.find_one(
 
 @app.route('/progress_bar')
 def progress_bar():
+
+    #db.progress.find({'percent': {'$lt': 100}})
+
     data = []
-    for x, y in enumerate(db.progress.find()):
+    for x, y in enumerate(db.progress.find({'percent': {'$lt': 100}})):
         data.append(dict(
             n=x,
             post=y.get('post_id'),
             urllib.urlencode(params)
         )
 
-
-    print "url: %s" % url
-
     data = json.loads(urllib.urlopen(url).read())
     likes = data.get('data')
 
             count = int(post.get('count')) + 1 if post else 1
 
             if count > total_likes:
-                print "HERE!!!!!!!!!!!!!!!!!!!!!!!"
                 return
 
-            #if total_likes > 1:
-            #total_likes = total_likes - 1
-            percent = ((count  - 1) * 100) / total_likes
-            #else:
-            #percent = 8
-
-
+            percent = (count * 100) / total_likes
 
             if not post:
                 db.progress.insert(dict(
                     }
                 )
 
-            print 'count: %d, percent: %d, total_likes : %d' % (
-                count,
-                percent,
-                total_likes
-            )
-
         paging = data.get('paging')
 
         if 'next' in paging:
                 total_likes=total_likes
             )
 
+    else:
+        db.progress.update(
+            {'post_id': post_id}, {
+                '$set': {'percent': 100}
+            }
+        )
+
     event_log.send(
         sender=None,
         post_id=post_id,

File templates/index.html

         $.getJSON('/get_metadata', function(data) {
             count_posts = data['count_posts']
             count_likes = data['count_likes']
-            $("#count_posts").html(count_posts)
+            //$("#count_posts").html(count_posts)
             $("#count_likes").html(count_likes)
         });
-        setTimeout(get_metadata, 2000);
+        setTimeout(get_metadata, 1000);
     }
 
 
             for (x in values){
                 post_id = values[x]['post']
                 percent = values[x]['percent']
+
+                $('#bar').append('<tr id="row_'+post_id+'"><td width="40%">'+post_id+'</td><td id="td_'+post_id+'" ></td></tr>');
+                $('#td_' + post_id).html('<div style="width: 100%;"  id="progressbar_' + post_id + '"></div>')
                 $("#progressbar_" + post_id).progressbar({ value: 0 });
-                setTimeout(update_progress, 500, post_id);
+                setTimeout(update_progress, 1000, post_id);
             }});
         });
 
                 progress = parseInt(value)
                 $('#progressbar_' + id).progressbar("option", "value", progress);
                 if (progress < 100){
-                    setTimeout(update_progress, 500, id);
+                    setTimeout(update_progress, 1000, id);
+                }
+                else{
+                    $('#row_' + id).remove();
+                    //$('#row_' + id).delay(800)
                 }
             });
         })
     }
 
-    //add_progress()
+    add_progress()
     get_metadata()
 
+
 </script>
 </head>
 
 
     <table id="bar" border="1" width="50%">
         <tr>
-            <td>Nro</td>
             <td>ID</td>
             <td>Progress</td>
         </tr>
-        {% for n, row in items %}
-        <tr>
-            <td width="5%">{{ n+1 }}</td>
-            <td width="30%"><font size="1">{{ row.post_id }}</font></td>
-            <td><div style="width: 100%;"  id="progressbar_{{ row.post_id }}"></div></td>
-        </tr>
-        {% endfor %}
     </table>
 </body>
 </html>