April 2018
Beginner
340 pages
7h 54m
English
The first thing we will need is the ability to select new messages from our conversation databases. We will need to provide the current user's username and the last time when we checked for messages. Our database will then return all new messages by a different author since the last time we checked for messages.
Open up your conversation.py file and add the following method to it:
def get_new_messages(self, timestamp, username): sql = "SELECT author, message FROM conversation WHERE date_sent > ? AND author <> ?" params = (timestamp, username) conn = sqlite3.connect(self.database) conn.row_factory = sqlite3.Row cursor = conn.cursor() cursor.execute(sql, params) results = [dict(row) for row in cursor.fetchall()] conn.close() ...