Skip to content

Commit

Permalink
Ingest review from remote fedireads user
Browse files Browse the repository at this point in the history
fixes #35
  • Loading branch information
mouse-reeve committed Feb 19, 2020
1 parent 400ddaa commit 9f2bad6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions fedireads/remote_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from urllib.parse import urlparse

from fedireads import models
from fedireads.status import create_review


def get_or_create_remote_user(actor):
Expand Down Expand Up @@ -44,6 +45,27 @@ def get_or_create_remote_user(actor):
local=False,
fedireads_user=data.get('fedireadsUser', False),
)
if user.fedireads_user:
get_remote_reviews(user)
return user


def get_remote_reviews(user):
''' ingest reviews by a new remote fedireads user '''
outbox_page = user.outbox + '?page=true'
response = requests.get(
outbox_page,
headers={'Accept': 'application/activity+json'}
)
data = response.json()
for status in data['orderedItems']:
if status.get('fedireadsType') == 'Review':
book_id = status['inReplyToBook'].split('/')[-1]
create_review(
user,
book_id,
status['name'],
status['content'],
status['rating']
)

0 comments on commit 9f2bad6

Please sign in to comment.