-
Notifications
You must be signed in to change notification settings - Fork 0
/
posts.py
38 lines (23 loc) · 1001 Bytes
/
posts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from database import database
from post import post
class posts:
def __init__(self, db):
postz = []
self.db = db
self.db.get_cursor().execute("SELECT * FROM posts ORDER BY created DESC")
rows = self.db.get_cursor().fetchall()
for row in rows:
postz.append(post(db, row["id"], row["title"], row["content"], row["created"], row["author_id"],
row["image_path"]))
self.posts = postz
def most_recent(self, omit=0):
safe_posts = [p for p in self.posts if p.id != omit]
return safe_posts[:3]
def refresh(self):
postz = []
self.db.get_cursor().execute("SELECT * FROM posts ORDER BY created DESC")
rows = self.db.get_cursor().fetchall()
for row in rows:
postz.append(post(self.db, row["id"], row["title"], row["content"], row["created"], row["author_id"],
row["image_path"]))
self.posts = postz