def get(self, forum_id, thread_id):
        if Postname.find(forum_id, thread_id) is None:
            return {"message": "forum / thread does not exist"}, 404
        # connection = sqlite3.connect('data.db')
        # cursor = connection.cursor()
        # query = "SELECT * FROM posts where threadid = ? and forumid = ? order by timestamp desc"
        # result = cursor.execute(query, (thread_id, forum_id))
        # rows = result.fetchall()
        # connection.close()

        rv = query_db(
            'SELECT * FROM post where thread_id = ? and forum_id = ? order by timestamp desc',
            [thread_id], [forum_id],
            one=False)
        return rv[0] if rv else None

        postlist = []
        if rv:
            for row in rv:
                postlist.append({
                    "author": row[4],
                    "text": row[3],
                    "timestamp": row[5]
                })
            return postlist, 200
        return {}, 404
Пример #2
0
    def get_forum_id(cls):
        # connection = sqlite3.connect('data.db')
        # cursor = connection.cursor()
        #
        # query = "SELECT forum_id FROM forum ORDER BY id DESC"
        # result = cursor.execute(query)
        # row = result.fetchone()
        # if row:
        #     forum_id = (row[0])
        # else:
        #     forum_id = None
        #
        # connection.close()
        # return forum_id

        rv = query_db('SELECT forum_id FROM forum ORDER BY id DESC', one=True)
        return rv[0] if rv else None
Пример #3
0
    def find_by_forumname(cls, name):
        # connection = sqlite3.connect('data.db')
        # cursor = connection.cursor()
        #
        # query = "SELECT * FROM forums WHERE name = ?"
        # result = cursor.execute(query, (name,))
        # row = result.fetchone()
        # if row:
        #     frm = cls(*row)
        # else:
        #     frm = None
        #
        # connection.close()
        # return frm

        rv = query_db('SELECT name FROM forum WHERE name = ?', [name],
                      one=True)
        return rv[0] if rv else None
Пример #4
0
    def get(self):
        # connection = sqlite3.connect('data.db')
        # cursor = connection.cursor()
        # query = "SELECT * FROM forums"
        # result = cursor.execute(query)
        # rows = result.fetchall()
        # connection.close()

        rv = query_db('SELECT * FROM forum', one=False)
        return rv[0] if rv else None

        forumdic = []
        if rv:
            for row in rv:
                forumdic.append({
                    "id": row[0],
                    "name": row[1],
                    "creator": row[2]
                })
            return forumdic, 200
        return {}, 404
    def get(self, forum_id):

        rv = query_db('SELECT * FROM thread t where t.forumid = ?', [forum_id],
                      one=False)
        return rv[0] if rv else None

        # connection = sqlite3.connect('data.db')
        # cursor = connection.cursor()
        # query = "SELECT * FROM threads t where t.forumid = ?"
        # result = cursor.execute(query, (forum_id,))
        # rows = result.fetchall()
        # connection.close()

        threadlist = []
        if rv:
            for row in rv:
                threadlist.append({
                    "id": row[0],
                    "title": row[2],
                    "creator": row[3]
                })
            return threadlist, 200
        return {}, 404
 def find(cls, forumid, threadid):
     rv = query_db('SELECT * FROM thread WHERE id = ? and forumid = ?',
                   [threadid], [forumid],
                   one=True)
     return rv[0] if rv else None
    def find_by_id(cls, _id):

        rv = query_db('select username from user where id = ?',
                      [_id], one=True)
        return rv[0] if rv else None
    def find_by_username(cls, username):

        rv = query_db('select user_id from user where username = ?',
                      [username], one=True)
        return rv[0] if rv else None
    def get_Thread_id(cls):

        rv = query_db('SELECT thread_id FROM thread ORDER BY id DESC',
                      one=True)
        return rv[0] if rv else None
    def find_by_forumid(cls, forumid):

        rv = query_db('select * from forum where id = ?', [forumid], one=True)
        return rv[0] if rv else None