Beispiel #1
0
 def delete(id):
     try:
         user = User.objects(id=current_user.id).get()
         item = SubscriptionItem.objects(id=id).get()
         user.update(pull__subscriptions=item)
         return jsonify(status='ok')
     except Exception as e:
         logging.warning(e)
         return jsonify(status='error')
Beispiel #2
0
 def show(id):
     try:
         count = request.args.get('count', 20)
         offset = int(request.args.get('offset', 0))
         item = SubscriptionItem.objects(id=id).get()
         papers = Paper.objects(subscriptions=item).order_by('-date').skip(offset).limit(count)
         if papers.count() > 0:
             return jsonify(response=[paper.serialize() for paper in papers])
         else:
             return jsonify(response=[], more=False)
     except Exception as e:
         logging.warning(e)
         logging.warning(id)
         return jsonify(error="error")
Beispiel #3
0
 def add(args):
     try:
         keyword = args.get('keyword')
         user = User.objects(id=current_user.id).get()
         if SubscriptionItem.objects(keyword=keyword).count() == 0:
             item = SubscriptionItem(keyword=keyword)
             item.save()
             Subscription.update(item)
         else:
             item = SubscriptionItem.objects(keyword=keyword).first()
         user.update(push__subscriptions=item)
         return jsonify(status='ok', item=item.serialize())
     except Exception as e:
         logging.warning(e)
         return jsonify(status='error')
Beispiel #4
0
 def update_all():
     for item in SubscriptionItem.objects():
         Subscription.update(item)
         time.sleep(5)