Exemplo n.º 1
0
 def own_stories(self):
     cursor = connection.cursor()
     returnedstories = cursor.execute('''
                                     SELECT storyID from stories WHERE storyID IN
                                     (
                                         SELECT storyID FROM words WHERE author=? AND parentID IS NULL
                                     )
                                     ''', (self.username,))
     stories = [Story.from_id(x[0]) for x in returnedstories.fetchall()]
     return stories
Exemplo n.º 2
0
 def top_story(self):
     cursor = connection.cursor()
     result = cursor.execute("""
         SELECT
             storyID,
             (
             SELECT count(*) FROM votes
             WHERE votes.wordID IN
                 (SELECT wordID FROM words WHERE words.storyID = stories.storyID)
             ) as totalVotes
             ,(
             SELECT author FROM words WHERE words.storyID = stories.storyID AND
                 parentID IS NULL
             ) as sauthor
         FROM stories
         WHERE sauthor = ?
         ORDER BY totalVotes DESC
         LIMIT 1
     """, (self.username,))
     story = result.fetchone()
     if story is not None:
         return Story.from_id(story[0])
     return None