···
6
+
from . import BaseFeed
8
+
# https://bsky.app/profile/nora.zone/post/3kv35hqi4a22b
9
+
TARGET_QUOTE_URI = 'at://did:plc:4qqizocrnriintskkh6trnzv/app.bsky.feed.post/3kv35hqi4a22b'
11
+
class NoraZoneInteresting(BaseFeed):
12
+
FEED_URI = 'at://did:plc:4nsduwlpivpuur4mqkbfvm6a/app.bsky.feed.generator/nz-interesting'
15
+
self.db_cnx = apsw.Connection('db/nz-interesting.db')
16
+
self.db_cnx.pragma('journal_mode', 'WAL')
17
+
self.db_cnx.pragma('wal_autocheckpoint', '0')
20
+
self.db_cnx.execute("""
21
+
create table if not exists posts (uri text, create_ts timestamp);
22
+
create index if not exists create_ts_idx on posts(create_ts);
25
+
self.logger = logging.getLogger('feeds.nz_interesting')
27
+
def process_commit(self, commit):
28
+
if commit['opType'] != 'c':
31
+
if commit['collection'] != 'app.bsky.feed.post':
34
+
record = commit.get('record')
38
+
embed = record.get('embed')
42
+
inner_record = embed.get('record')
43
+
if inner_record is None:
46
+
if inner_record.get('uri') == TARGET_QUOTE_URI:
47
+
self.logger.debug('found quote post of target, adding to feed')
48
+
uri = 'at://{repo}/app.bsky.feed.post/{rkey}'.format(
49
+
repo = commit['did'],
50
+
rkey = commit['rkey']
52
+
ts = self.safe_timestamp(record.get('createdAt')).timestamp()
53
+
self.db_cnx.execute(
54
+
'insert into posts (uri, create_ts) values (:uri, :ts)',
55
+
dict(uri=uri, ts=ts)
58
+
def commit_changes(self):
59
+
self.logger.debug('committing changes')
60
+
self.wal_checkpoint(self.db_cnx, 'RESTART')
62
+
def serve_feed(self, limit, offset, langs):
63
+
cur = self.db_cnx.execute(
64
+
'select uri from posts order by create_ts desc limit :limit offset :offset',
65
+
dict(limit=limit, offset=offset)
67
+
return [uri for (uri,) in cur]