Beispiel #1
0
 def loadNext(self, since_id=None, count=100):
     if count > 100:
         raise ValueError("Too many elements requested.")
     api = twapi.create_api()
     self.addItems(self.fetchFriendsTimeline(api, count*2, since_id=since_id), None)
     for term in self.searches:
         results = self.fetchSearch(api, term, count*2, since_id=since_id)
         self.addItems(results, term)
     #log.debug("Found a total of %d items" % len(self.items))
     rkeys = [k for k in reversed(sorted(self.items.keys()))]
     results = self.matchResults(rkeys, count, since_id=since_id)
     #log.debug("Giving %d items" % len(results))
     results_json = []
     for result in results:
         status = twapi.get_status(result)
         if not status:
             continue # someone deleted their status, most likely
         rdata = '"status": %s,' % status.AsJsonString()
         vote = model.findVoteByUserAndTweet(self.user_id, result)
         if vote:
             rdata += '"vote": %s,' % vote.toJSON()
         sources = filter(None, self.items[result])
         rdata += '"sources": %s,' % json.dumps(sources)
         rdata += '"score": %.2f' % classify.classify(status, self.user_id)
         results_json.append(rdata)
     #log.debug("Assembled")
     return "[{%s}]" % "},{".join(results_json)
Beispiel #2
0
    
    @with_auth()
    @with_format()
    def create(self, format='html'):
        """POST /votes: Create a new item"""
        
        form = dict()
        try:
            form = rest_validate(VoteCreateForm)
        except formencode.Invalid, i:
            return fstatus(i.message, format=format, http_code=400)
        
        user_id = session['user_id']
        tweet_id = form.get("tweet_id")
        
        if model.findVoteByUserAndTweet(user_id, tweet_id):
            return fstatus("This rating already exists, please update it instead.", 
                format=format, http_code=409)
        
        model.meta.Session.begin()
        vote = model.Vote(tweet_id, user_id, 
            weight=form.get("weight"))
        model.meta.Session.add(vote)
        model.meta.Session.commit()
        
        classify.learn_vote(vote)
        log.debug("Created: %s" % vote)
        
        return self.view(vote.id, format=format)

    @with_auth()