From 4a337e6b20201c68757e0caf15829c1f2a5d2442 Mon Sep 17 00:00:00 2001 From: Kharec Date: Sat, 20 Dec 2025 17:24:05 +0100 Subject: [PATCH] feat: add post analysis utilities --- skywipe/post_analysis.py | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 skywipe/post_analysis.py diff --git a/skywipe/post_analysis.py b/skywipe/post_analysis.py new file mode 100644 index 0000000..acdebc4 --- /dev/null +++ b/skywipe/post_analysis.py @@ -0,0 +1,60 @@ +"""Post analysis utilities for Skywipe""" + + +class PostAnalyzer: + MEDIA_TYPES = { + 'app.bsky.embed.images', + 'app.bsky.embed.video', + 'app.bsky.embed.external' + } + + QUOTE_TYPES = { + 'app.bsky.embed.record', + 'app.bsky.embed.recordWithMedia', + 'app.bsky.embed.record_with_media' + } + + @staticmethod + def has_media(post_record): + embed = getattr(post_record, 'embed', None) + if not embed: + return False + + embed_type = getattr(embed, 'py_type', None) + if embed_type: + embed_type_base = embed_type.split('#')[0] + + if embed_type_base in PostAnalyzer.MEDIA_TYPES: + return True + + if embed_type_base in ('app.bsky.embed.recordWithMedia', 'app.bsky.embed.record_with_media'): + media = getattr(embed, 'media', None) + if media: + media_type = getattr(media, 'py_type', None) + if media_type: + media_type_base = media_type.split('#')[0] + if media_type_base in PostAnalyzer.MEDIA_TYPES: + return True + + for attr in ('images', 'video', 'external'): + if hasattr(embed, attr): + return True + if isinstance(embed, dict) and embed.get(attr): + return True + + return False + + @staticmethod + def has_quote(post_record): + embed = getattr(post_record, 'embed', None) + if not embed: + return False + + embed_type = getattr(embed, 'py_type', None) + if embed_type: + embed_type_base = embed_type.split('#')[0] + if embed_type_base in PostAnalyzer.QUOTE_TYPES: + return True + + return (hasattr(embed, 'record') or + (isinstance(embed, dict) and embed.get('record')))