From 5fc67f2bcff8d9a06c2b095e6a4eb7596fb4d032 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Fri, 15 Apr 2022 02:52:37 +0000 Subject: [PATCH] Add support for 'message me' cards --- snscrape/modules/twitter.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/snscrape/modules/twitter.py b/snscrape/modules/twitter.py index 0504193..51d7369 100644 --- a/snscrape/modules/twitter.py +++ b/snscrape/modules/twitter.py @@ -279,6 +279,13 @@ class SpacesCard(Card): id: str +@dataclasses.dataclass +class MessageMeCard(Card): + recipient: 'User' + url: str + buttonText: str + + UnifiedCardComponentKey = str UnifiedCardDestinationKey = str UnifiedCardMediumKey = str @@ -1077,6 +1084,14 @@ class _TwitterAPIScraper(snscrape.base.Scraper): return AppPlayerCard(**kwargs) elif cardName == '3691233323:audiospace': return SpacesCard(**_kwargs_from_map({'card_url': 'url', 'id': 'id'})) + elif cardName == '2586390716:message_me': + # Note that the strings in Twitter's JS appear to have an incorrect mapping that then gets changed somewhere in the 1.8 MiB of JS! + # cta_1, 3, and 4 should mean 'Message us', 'Send a private message', and 'Send me a private message', but the correct mapping is currently unknown. + ctas = {'message_me_card_cta_2': 'Send us a private message'} + if bindingValues['cta'] not in ctas: + _logger.warning(f'Unsupported message_me card cta on tweet {tweetId}: {bindingValues["cta"]!r}') + return + return MessageMeCard(**_kwargs_from_map({'recipient': 'recipient', 'card_url': 'url'}), buttonText = ctas[bindingValues['cta']]) elif cardName == 'unified_card': o = json.loads(bindingValues['unified_card']) kwargs = {}