Commits

ronald martinez  committed 8f5ef48

ok

  • Participants
  • Parent commits dffdfe1

Comments (0)

Files changed (3)

 from datetime import datetime
 from tasks import get_likes
 
+from pymongo import Connection
+
+cn = Connection()
+db = cn.likes
+
+db.metadata.drop()
+db.metadata.insert(dict(id=1))
+
+
+total_posts = 0
+total_posts_likes = 0
+
 
 def posts(url=None):
 
+    global total_posts
+    global total_posts_likes
+
     if not url:
         params = dict(
             limit=settings.POSTS_PER_PAGE,
             urllib.urlencode(params)
         )
 
-    #logging.info("url: %s" % url)
     print "url: %s" % url
 
     try:
     items = data.get('data')
 
     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(
+                    {'id': 1}, {
+                        '$inc': {'count_likes': 1}
+                    }
+                )
+
+                #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:
-            #if not settings.STOP_NEXT_PAGE:
             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()
-    logging.info('estimated_time: %s' % (tend - tstart))
+    print 'estimated_time: %s' % (tend - tstart)
 ID_PAGE = ''
 
 POSTS_PER_PAGE = 5
-LIKES_PER_PAGE = 5
+LIKES_PER_PAGE = 50
 
 STOP_NEXT_PAGE = False
 
             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
-            else:
-                total_likes = 1
+            #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: