From 1dad787bc45252ec6acab4c6a50cec8c98e2a8a8 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sat, 13 Jan 2024 18:18:32 +1300 Subject: [PATCH] filter certain types of post --- CONTRIBUTING.md | 5 ++++- README.md | 2 +- app/activitypub/util.py | 12 +++++++++++- app/main/routes.py | 5 ++++- requirements.txt | 1 + 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 59a528e2..e2ce8798 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,6 +5,8 @@ When it matures enough, PieFed will aim to work in a way consistent with the [Co Please discuss your ideas in an issue at https://codeberg.org/rimu/pyfedi/issues before starting any large pieces of work to ensure alignment with the roadmap, architecture and processes. +Check out [the Matrix chatroom](https://matrix.to/#/#piefed-community:matrix.org). + The general style and philosophy behind the way things have been constructed is well described by [The Grug Brained Developer](https://grugbrain.dev/). If that page resonates with you then you'll probably enjoy your time here! The codebase needs to be simple enough that new developers of all @@ -19,8 +21,9 @@ Mailing list, Matrix channel, etc still to come. - Python - Flask - Jinja -- SCSS +- SCSS/SASS - SQL - Postgresql +- Redis Python developers with no Flask experience can quickly learn Flask by exploring the [Flask Mega Tutorial](https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world) diff --git a/README.md b/README.md index 90b875d8..5c4b77bb 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A lemmy/kbin clone written in Python with Flask. - Clean, simple code that is easy to understand and contribute to. No fancy design patterns or algorithms. - Easy setup, easy to manage - few dependencies and extra software required. - - GPL. + - AGPL. - First class moderation tools. ## Project goals diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 5f7e5fd4..080c0b11 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -18,6 +18,7 @@ from app.constants import * from urllib.parse import urlparse from PIL import Image, ImageOps from io import BytesIO +import pytesseract from app.utils import get_request, allowlist_html, html_to_markdown, get_setting, ap_datetime, markdown_to_html, \ is_image_url, domain_from_url, gibberish, ensure_directory_exists, markdown_to_text, head_request, post_ranking, \ @@ -551,7 +552,16 @@ def make_image_sizes_async(file_id, thumbnail_width, medium_width, directory): db.session.commit() - + # Alert regarding fascist meme content + text = pytesseract.image_to_string(Image.open(final_place).convert('L')) + if 'Anonymous' in text and ('No.' in text or ' N0' in text): # chan posts usually contain the text 'Anonymous' and ' No.12345' + post = Post.query.filter(image_id=file.id).first() + notification = Notification(title='Review this', + user_id=1, + author_id=post.user_id, + url=url_for('activitypub.post_ap', post_id=post.id)) + db.session.add(notification) + db.session.commit() # create a summary from markdown if present, otherwise use html if available diff --git a/app/main/routes.py b/app/main/routes.py index 1d20a0c3..b8b8e630 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -18,6 +18,8 @@ from app.utils import render_template, get_setting, gibberish, request_etag_matc ap_datetime, ip_address, retrieve_block_list, shorten_string, markdown_to_text, user_filters_home, \ joined_communities, moderating_communities from app.models import Community, CommunityMember, Post, Site, User, utcnow, Domain, Topic +from PIL import Image +import pytesseract @bp.route('/', methods=['HEAD', 'GET', 'POST']) @@ -207,7 +209,8 @@ def robots(): @bp.route('/test') def test(): - return str(current_user.get_id()) + return pytesseract.image_to_string(Image.open('test.png').convert('L')) + #ip = request.headers.get('X-Forwarded-For') or request.remote_addr #if ',' in ip: # Remove all but first ip addresses diff --git a/requirements.txt b/requirements.txt index 513dde0b..9a9c9794 100644 --- a/requirements.txt +++ b/requirements.txt @@ -29,3 +29,4 @@ feedgen==0.9.0 celery==5.3.6 redis==5.0.1 Werkzeug==2.3.3 +pytesseract==0.3.10