From dfe0c3b4e2da737944186c60cff9d776dc3f6ce1 Mon Sep 17 00:00:00 2001 From: doubaniux Date: Fri, 8 Oct 2021 18:09:30 -0400 Subject: [PATCH 1/7] fix imdb link parsing for DoubanMovie --- common/scraper.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/scraper.py b/common/scraper.py index f5db791b..4e6bb9d0 100644 --- a/common/scraper.py +++ b/common/scraper.py @@ -450,6 +450,9 @@ class DoubanMovieScraper(DoubanScrapperMixin, AbstractScraper): imdb_elem = content.xpath( "//div[@id='info']//span[text()='IMDb链接:']/following-sibling::a[1]/text()") + if not imdb_elem: + imdb_elem = content.xpath( + "//div[@id='info']//span[text()='IMDb:']/following-sibling::text()[1]") imdb_code = imdb_elem[0].strip() if imdb_elem else None director_elem = content.xpath( From 622e840c0dac48d01c83bf530528061af79c6ee3 Mon Sep 17 00:00:00 2001 From: doubaniux Date: Wed, 27 Oct 2021 15:31:49 +0200 Subject: [PATCH 2/7] fix scraping failure with wepb image --- common/scraper.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/common/scraper.py b/common/scraper.py index f5db791b..47188ad5 100644 --- a/common/scraper.py +++ b/common/scraper.py @@ -6,8 +6,8 @@ import re import dateparser import datetime import time +import filetype from lxml import html -from mimetypes import guess_extension from threading import Thread from boofilsic.settings import LUMINATI_USERNAME, LUMINATI_PASSWORD, DEBUG, IMDB_API_KEY, SCRAPERAPI_KEY from boofilsic.settings import SPOTIFY_CREDENTIAL @@ -199,7 +199,7 @@ class AbstractScraper: if img_response.status_code == 200: raw_img = img_response.content content_type = img_response.headers.get('Content-Type') - ext = guess_extension(content_type.partition(';')[0].strip()) + ext = filetype.get_type(mime=content_type.partition(';')[0].strip()).extension else: ext = None return raw_img, ext @@ -207,7 +207,7 @@ class AbstractScraper: @classmethod def save(cls, request_user): entity_cover = { - 'cover': SimpleUploadedFile('temp' + cls.img_ext, cls.raw_img) + 'cover': SimpleUploadedFile('temp.' + cls.img_ext, cls.raw_img) } form = cls.form_class(cls.raw_data, entity_cover) if form.is_valid(): @@ -246,7 +246,8 @@ class DoubanScrapperMixin: if img_response.status_code == 200: raw_img = img_response.content content_type = img_response.headers.get('Content-Type') - ext = guess_extension(content_type.partition(';')[0].strip()) + ext = filetype.get_type( + mime=content_type.partition(';')[0].strip()).extension else: ext = None return raw_img, ext From 26f3195f6e699378c9d417eff7ef5615699419da Mon Sep 17 00:00:00 2001 From: doubaniux Date: Fri, 29 Oct 2021 10:11:49 +0200 Subject: [PATCH 3/7] delete douban image download mixin --- common/scraper.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/common/scraper.py b/common/scraper.py index 47188ad5..3b791ed3 100644 --- a/common/scraper.py +++ b/common/scraper.py @@ -235,22 +235,6 @@ class DoubanScrapperMixin: # fp.write(r.content.decode('utf-8')) return html.fromstring(r.content.decode('utf-8')) - @classmethod - def download_image(cls, url): - if url is None: - return - raw_img = None - - if url: - img_response = requests.get(url, timeout=TIMEOUT) - if img_response.status_code == 200: - raw_img = img_response.content - content_type = img_response.headers.get('Content-Type') - ext = filetype.get_type( - mime=content_type.partition(';')[0].strip()).extension - else: - ext = None - return raw_img, ext class DoubanBookScraper(DoubanScrapperMixin, AbstractScraper): site_name = SourceSiteEnum.DOUBAN.value From 0c8e1fa880dc276988872f1fa8b7855affb2d0cb Mon Sep 17 00:00:00 2001 From: doubaniux Date: Fri, 29 Oct 2021 10:58:10 +0200 Subject: [PATCH 4/7] add readme --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..c65c5c9d --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# Boofilsic +An application allows you to mark any books, movies and more things you love. + +Depends on Mastodon. + +## Contribution +The project is based on Django. If you are familiar with this technique and willing to read through the terrible code😝, your contribution would be the most welcome! + +Currently looking for someone to help with: +- Writing instrucations on how to deploy this +- Explaining the structure of code +- Refactoring (this is something big) + +## Deployment +This project is still in the early stage, so you are not encouraged to deploy it on your own. If you do want to give it a try, please check the [fork of *alphatownsman*](https://github.com/alphatownsman/boofilsic), which is more friendly. + +## Sponsor +If you like this project, please consider sponsor us on [Patreon](https://patreon.com/tertius). \ No newline at end of file From 3887ce8ecd0ba18627ff0d6fbcd2c0ba09b0f707 Mon Sep 17 00:00:00 2001 From: doubaniux <56670055+doubaniux@users.noreply.github.com> Date: Tue, 14 Dec 2021 12:21:43 +0100 Subject: [PATCH 5/7] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c65c5c9d..ed8b2d05 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Currently looking for someone to help with: - Refactoring (this is something big) ## Deployment -This project is still in the early stage, so you are not encouraged to deploy it on your own. If you do want to give it a try, please check the [fork of *alphatownsman*](https://github.com/alphatownsman/boofilsic), which is more friendly. +This project is still in its early stage, so you are not encouraged to deploy it on your own. If you do want to give it a try, please check the [fork of *alphatownsman*](https://github.com/alphatownsman/boofilsic), which is more friendly. ## Sponsor -If you like this project, please consider sponsor us on [Patreon](https://patreon.com/tertius). \ No newline at end of file +If you like this project, please consider sponsoring us on [Patreon](https://patreon.com/tertius). From 031388a6f83c2556226c6ac54cddba57ca7b9566 Mon Sep 17 00:00:00 2001 From: doubaniux Date: Sat, 18 Dec 2021 20:36:52 -0500 Subject: [PATCH 6/7] remove usage of eval --- common/forms.py | 19 +++++++++---------- users/views.py | 6 ++---- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/common/forms.py b/common/forms.py index d010b583..5372ce12 100644 --- a/common/forms.py +++ b/common/forms.py @@ -17,7 +17,7 @@ class KeyValueInput(forms.Widget): data = None if context['widget']['value'] is not None: data = json.loads(context['widget']['value']) - context['widget']['value'] = [ {p[0]: p[1]} for p in data.items()] if data else [] + context['widget']['value'] = [{p[0]: p[1]} for p in data.items()] if data else [] return context class Media: @@ -50,18 +50,18 @@ class JSONField(postgres.JSONField): def to_python(self, value): if not value: return None - json = {} + j = {} if isinstance(value, dict): - json = value + j = value else: - pairs = eval(value) + pairs = json.loads('[' + value + ']') if isinstance(pairs, dict): - json = pairs + j = pairs else: # list or tuple for pair in pairs: - json = {**json, **pair} - return super().to_python(json) + j = {**j, **pair} + return super().to_python(j) class RadioBooleanField(forms.ChoiceField): @@ -167,9 +167,7 @@ class HstoreField(forms.CharField): # already in python types if isinstance(value, list): return value - pairs = eval(value) - if len(pairs) == 1: - pairs = (pairs,) + pairs = json.loads('[' + value + ']') return pairs @@ -259,6 +257,7 @@ class MarkForm(forms.ModelForm): label=_("短评"), ) + class ReviewForm(forms.ModelForm): IS_PRIVATE_CHOICES = [ (True, _("仅关注者")), diff --git a/users/views.py b/users/views.py index 264be10d..ff77d066 100644 --- a/users/views.py +++ b/users/views.py @@ -721,10 +721,8 @@ def music_list(request, id, status): @login_required def set_layout(request): if request.method == 'POST': - # json to python - raw_layout_data = request.POST.get('layout').replace('false', 'False').replace('true', 'True') - layout = eval(raw_layout_data) - request.user.preference.home_layout = eval(raw_layout_data) + layout = json.loads(request.POST.get('layout')) + request.user.preference.home_layout = layout request.user.preference.save() return redirect(reverse("common:home")) else: From d4015a62d4e32f275e8907351a25c2e21b1e0d82 Mon Sep 17 00:00:00 2001 From: doubaniux <56670055+doubaniux@users.noreply.github.com> Date: Wed, 27 Jul 2022 21:58:25 +0200 Subject: [PATCH 7/7] fix tag search result pagination (#109) (#114) * fix imdb link parsing for DoubanMovie * delete douban image download mixin * add readme * remove usage of eval * fix tag search result pagination Co-authored-by: Your Name Co-authored-by: doubaniux <56670055+doubaniux@users.noreply.github.com> Co-authored-by: doubaniux Co-authored-by: alphatownsman <90480431+alphatownsman@users.noreply.github.com> Co-authored-by: Your Name --- README.md | 2 +- common/templates/common/search_result.html | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ed8b2d05..2cfde8ea 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ Currently looking for someone to help with: - Explaining the structure of code - Refactoring (this is something big) -## Deployment This project is still in its early stage, so you are not encouraged to deploy it on your own. If you do want to give it a try, please check the [fork of *alphatownsman*](https://github.com/alphatownsman/boofilsic), which is more friendly. ## Sponsor If you like this project, please consider sponsoring us on [Patreon](https://patreon.com/tertius). + diff --git a/common/templates/common/search_result.html b/common/templates/common/search_result.html index baec6b0d..cc420eed 100644 --- a/common/templates/common/search_result.html +++ b/common/templates/common/search_result.html @@ -419,23 +419,23 @@