The code for my Bluesky feed generator
1from datetime import datetime, timezone
2
3import peewee
4
5db = peewee.SqliteDatabase("feed_database.db")
6
7
8class BaseModel(peewee.Model):
9 class Meta:
10 database = db
11
12
13class Post(BaseModel):
14 author = peewee.CharField(index=True)
15 uri = peewee.CharField(index=True)
16 cid = peewee.CharField()
17 text = peewee.TextField()
18 reply_parent = peewee.CharField(null=True, default=None)
19 reply_root = peewee.CharField(null=True, default=None)
20 created_at = peewee.DateTimeField()
21 indexed_at = peewee.DateTimeField(default=datetime.now(timezone.utc))
22
23
24class Like(BaseModel):
25 author = peewee.CharField(index=True)
26 uri = peewee.CharField(index=True)
27 cid = peewee.CharField()
28 created_at = peewee.DateTimeField()
29 indexed_at = peewee.DateTimeField(default=datetime.now(timezone.utc))
30
31
32class Repost(BaseModel):
33 author = peewee.CharField(index=True)
34 uri = peewee.CharField(index=True)
35 cid = peewee.CharField()
36 created_at = peewee.DateTimeField()
37 indexed_at = peewee.DateTimeField(default=datetime.now(timezone.utc))
38
39
40class Follow(BaseModel):
41 author = peewee.CharField(index=True)
42 subject = peewee.CharField(index=True)
43 uri = peewee.CharField(index=True)
44 created_at = peewee.DateTimeField()
45 indexed_at = peewee.DateTimeField(default=datetime.now(timezone.utc))
46
47
48class FirehoseSubscriptionState(BaseModel):
49 service = peewee.CharField(unique=True)
50 cursor = peewee.BigIntegerField()
51
52
53if db.is_closed():
54 db.connect()
55 db.create_tables([Post, Like, Repost, Follow, FirehoseSubscriptionState])