Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom feed generators #47

Merged
merged 7 commits into from
May 27, 2023
Merged

Custom feed generators #47

merged 7 commits into from
May 27, 2023

Conversation

MarshalX
Copy link
Owner

@MarshalX MarshalX commented May 26, 2023

  • firehose support
  • CAR files support
  • add a database of lexicon IDs?
  • provide high-lvl methods to check if a record type is like, post, etc
  • provide high-lvl interface to parse record models from raw data
  • don't raise exceptions on custom records?
  • create example repository with feed server
  • did resolver? (only for authed feed gens). UPD. in the next iteration

@MarshalX
Copy link
Owner Author

MarshalX commented May 26, 2023

We should rewrite this code in Python https://github.com/bluesky-social/feed-generator/blob/9395b18214e3283f8b562fe49f026decff12e308/src/util/subscription.ts#L71-L114

UPD. The code has been rewritten:

atproto/test.py

Lines 141 to 183 in 446d41b

def _get_ops_by_type(commit: models.ComAtprotoSyncSubscribeRepos.Commit) -> dict: # noqa: C901
operation_by_type = {
'posts': {'created': [], 'deleted': []},
'reposts': {'created': [], 'deleted': []},
'likes': {'created': [], 'deleted': []},
'follows': {'created': [], 'deleted': []},
}
car = CAR.from_bytes(commit.blocks)
for op in commit.ops:
uri = AtUri.from_str(f'at://{commit.repo}/{op.path}')
if op.action == 'update':
# not supported yet
continue
if op.action == 'create':
if not op.cid:
continue
create_info = {'uri': str(uri), 'cid': str(op.cid), 'author': commit.repo}
record_raw_data = car.blocks.get(op.cid)
if not record_raw_data:
continue
record = get_or_create_model(record_raw_data)
if uri.collection == ids.AppBskyFeedLike and is_record_type(record, models.AppBskyFeedLike):
operation_by_type['likes']['created'].append({'record': record, **create_info})
elif uri.collection == ids.AppBskyFeedPost and is_record_type(record, models.AppBskyFeedPost):
operation_by_type['posts']['created'].append({'record': record, **create_info})
elif uri.collection == ids.AppBskyGraphFollow and is_record_type(record, models.AppBskyGraphFollow):
operation_by_type['follows']['created'].append({'record': record, **create_info})
if op.action == 'delete':
if uri.collection == ids.AppBskyFeedLike:
operation_by_type['likes']['deleted'].append({'uri': str(uri)})
if uri.collection == ids.AppBskyFeedPost:
operation_by_type['posts']['deleted'].append({'uri': str(uri)})
if uri.collection == ids.AppBskyGraphFollow:
operation_by_type['follows']['deleted'].append({'uri': str(uri)})
return operation_by_type

UPD2. Custom feed generator: https://github.com/MarshalX/bluesky-feed-generator

@MarshalX MarshalX marked this pull request as ready for review May 27, 2023 14:27
@MarshalX MarshalX merged commit ed71383 into main May 27, 2023
@MarshalX MarshalX deleted the custom-feeds branch May 27, 2023 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant