fix goodreads import, supports mark date

This commit is contained in:
Your Name 2023-01-11 11:31:53 -05:00 committed by Henri Dickson
parent e86f86df6c
commit 43f0b36bbc
4 changed files with 22 additions and 3 deletions

View file

@ -15,6 +15,7 @@
<a href="{% url 'journal:user_profile' user.mastodon_username %}">
<h5 class="user-profile__username mast-displayname">{{ user.mastodon_account.display_name }}</h5>
</a>
<!-- {{ user.id }} -->
</div>
<p><a class="user-profile__link mast-acct" target="_blank" href="{{ user.mastodon_account.url }}">@{{ user.username }}@{{ user.mastodon_site }}</a>
{% current_user_relationship user as relationship %}

View file

@ -30,7 +30,7 @@ class GoodreadsImporter:
match_shelf = re.match(re_shelf, raw_url)
match_profile = re.match(re_profile, raw_url)
if match_profile or match_shelf or match_list:
django_rq.get_queue("doufen").enqueue(
django_rq.get_queue("import").enqueue(
cls.import_from_url_task, raw_url, user
)
return True
@ -142,6 +142,20 @@ class GoodreadsImporter:
)
review = ""
last_updated = None
date_elem = cell.xpath(".//td[@class='field date_added']//span/text()")
for d in date_elem:
date_matched = re.search(r"(\w+)\s+(\d+),\s+(\d+)", d)
if date_matched:
last_updated = make_aware(
datetime.strptime(
date_matched[1]
+ " "
+ date_matched[2]
+ " "
+ date_matched[3],
"%b %d %Y",
)
)
try:
c2 = BasicDownloader(url_shelf).download().html()
review_elem = c2.xpath("//div[@itemprop='reviewBody']/text()")

View file

@ -134,8 +134,12 @@ class DefaultActivityProcessor:
).first()
if not activity:
self.created()
elif activity.visibility != self.action_object.visibility:
elif (
activity.visibility != self.action_object.visibility
or activity.created_time != activity.action_object.created_time
):
activity.visibility = self.action_object.visibility
activity.created_time = activity.action_object.created_time
activity.save()

View file

@ -96,7 +96,7 @@
<form action="{% url 'users:import_goodreads' %}" method="POST" >
{% csrf_token %}
<div class="import-panel__checkbox">输入Goodreads链接
<input type="url" name="url" value="" placeholder="例如 https://www.goodreads.com/user/show/12345-janedoe">
<input type="url" name="url" value="" placeholder="例如 https://www.goodreads.com/user/show/12345-janedoe" required>
<input type="submit" class="import-panel__button" value="{% trans '导入' %}" id="uploadBtn" />
</div>
<div>