From 267b7d0e32d5495f202ae5824eb3eb0801941520 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Wed, 5 Jan 2022 02:27:09 +0000 Subject: [PATCH] Rename CLI classmethods --- snscrape/_cli.py | 4 ++-- snscrape/base.py | 6 +++--- snscrape/modules/facebook.py | 12 ++++++------ snscrape/modules/instagram.py | 18 +++++++++--------- snscrape/modules/reddit.py | 6 +++--- snscrape/modules/telegram.py | 6 +++--- snscrape/modules/twitter.py | 34 +++++++++++++++++----------------- snscrape/modules/vkontakte.py | 6 +++--- snscrape/modules/weibo.py | 6 +++--- 9 files changed, 49 insertions(+), 49 deletions(-) diff --git a/snscrape/_cli.py b/snscrape/_cli.py index ca9683f..720f0ad 100644 --- a/snscrape/_cli.py +++ b/snscrape/_cli.py @@ -246,7 +246,7 @@ def parse_args(): classes.extend(cls.__subclasses__()) for scraper, cls in sorted(scrapers.items()): subparser = subparsers.add_parser(cls.name, help = '', formatter_class = argparse.ArgumentDefaultsHelpFormatter) - cls.setup_parser(subparser) + cls.cli_setup_parser(subparser) subparser.set_defaults(cls = cls) args = parser.parse_args() @@ -293,7 +293,7 @@ def main(): setup_logging() args = parse_args() configure_logging(args.verbosity, args.dumpLocals) - scraper = args.cls.from_args(args) + scraper = args.cls.cli_from_args(args) i = 0 with _dump_locals_on_exception(): diff --git a/snscrape/base.py b/snscrape/base.py index 4e68793..242c76a 100644 --- a/snscrape/base.py +++ b/snscrape/base.py @@ -215,15 +215,15 @@ class Scraper: return self._request('POST', *args, **kwargs) @classmethod - def setup_parser(cls, subparser): + def cli_setup_parser(cls, subparser): pass @classmethod - def from_args(cls, args): + def cli_from_args(cls, args): return cls._construct(args) @classmethod - def _construct(cls, argparseArgs, *args, **kwargs): + def cli_construct(cls, argparseArgs, *args, **kwargs): return cls(*args, **kwargs, retries = argparseArgs.retries) diff --git a/snscrape/modules/facebook.py b/snscrape/modules/facebook.py index e8a7ffb..6df8b49 100644 --- a/snscrape/modules/facebook.py +++ b/snscrape/modules/facebook.py @@ -205,12 +205,12 @@ class _FacebookUserAndCommunityScraper(_FacebookCommonScraper): yield from self._soup_to_items(soup, self._baseUrl, 'user') @classmethod - def setup_parser(cls, subparser): + def cli_setup_parser(cls, subparser): subparser.add_argument('username', type = snscrape.base.nonempty_string('username'), help = 'A Facebook username or user ID') @classmethod - def from_args(cls, args): - return cls._construct(args, args.username) + def cli_from_args(cls, args): + return cls.cli_construct(args, args.username) class FacebookUserScraper(_FacebookUserAndCommunityScraper): @@ -356,9 +356,9 @@ class FacebookGroupScraper(_FacebookCommonScraper): yield from self._soup_to_items(soup, baseUrl, 'group') @classmethod - def setup_parser(cls, subparser): + def cli_setup_parser(cls, subparser): subparser.add_argument('group', type = snscrape.base.nonempty_string('group'), help = 'A group name or ID') @classmethod - def from_args(cls, args): - return cls._construct(args, args.group) + def cli_from_args(cls, args): + return cls.cli_construct(args, args.group) diff --git a/snscrape/modules/instagram.py b/snscrape/modules/instagram.py index a3fa977..0c50d53 100644 --- a/snscrape/modules/instagram.py +++ b/snscrape/modules/instagram.py @@ -156,12 +156,12 @@ class InstagramUserScraper(_InstagramCommonScraper): self._variablesFormat = '{{"id":"{pageID}","first":50,"after":"{endCursor}"}}' @classmethod - def setup_parser(cls, subparser): + def cli_setup_parser(cls, subparser): subparser.add_argument('username', type = snscrape.base.nonempty_string('username'), help = 'An Instagram username (no leading @)') @classmethod - def from_args(cls, args): - return cls._construct(args, args.username) + def cli_from_args(cls, args): + return cls.cli_construct(args, args.username) def _get_entity(self): r = self._initial_page() @@ -211,12 +211,12 @@ class InstagramHashtagScraper(_InstagramCommonScraper): self._variablesFormat = '{{"tag_name":"{pageID}","first":50,"after":"{endCursor}"}}' @classmethod - def setup_parser(cls, subparser): + def cli_setup_parser(cls, subparser): subparser.add_argument('hashtag', type = snscrape.base.nonempty_string('hashtag'), help = 'An Instagram hashtag (no leading #)') @classmethod - def from_args(cls, args): - return cls._construct(args, args.hashtag) + def cli_from_args(cls, args): + return cls.cli_construct(args, args.hashtag) class InstagramLocationScraper(_InstagramCommonScraper): @@ -233,9 +233,9 @@ class InstagramLocationScraper(_InstagramCommonScraper): self._variablesFormat = '{{"id":"{pageID}","first":50,"after":"{endCursor}"}}' @classmethod - def setup_parser(cls, subparser): + def cli_setup_parser(cls, subparser): subparser.add_argument('locationid', help = 'An Instagram location ID', type = int) @classmethod - def from_args(cls, args): - return cls._construct(args, args.locationid) + def cli_from_args(cls, args): + return cls.cli_construct(args, args.locationid) diff --git a/snscrape/modules/reddit.py b/snscrape/modules/reddit.py index 9668afd..fe77b5d 100644 --- a/snscrape/modules/reddit.py +++ b/snscrape/modules/reddit.py @@ -204,7 +204,7 @@ class _RedditPushshiftScraper(snscrape.base.Scraper): yield from self._iter_api_submissions_and_comments({type(self)._apiField: self._name}) @classmethod - def setup_parser(cls, subparser): + def cli_setup_parser(cls, subparser): subparser.add_argument('--no-submissions', dest = 'noSubmissions', action = 'store_true', default = False, help = 'Don\'t list submissions') subparser.add_argument('--no-comments', dest = 'noComments', action = 'store_true', default = False, help = 'Don\'t list comments') subparser.add_argument('--before', metavar = 'TIMESTAMP', type = int, help = 'Fetch results before a Unix timestamp') @@ -213,9 +213,9 @@ class _RedditPushshiftScraper(snscrape.base.Scraper): subparser.add_argument(name, type = snscrape.base.nonempty_string(name)) @classmethod - def from_args(cls, args): + def cli_from_args(cls, args): name = cls.name.split('-', 1)[1] - return cls._construct(args, getattr(args, name), submissions = not args.noSubmissions, comments = not args.noComments, before = args.before, after = args.after) + return cls.cli_construct(args, getattr(args, name), submissions = not args.noSubmissions, comments = not args.noComments, before = args.before, after = args.after) class RedditUserScraper(_RedditPushshiftScraper): diff --git a/snscrape/modules/telegram.py b/snscrape/modules/telegram.py index fb6bf24..f258b87 100644 --- a/snscrape/modules/telegram.py +++ b/snscrape/modules/telegram.py @@ -195,9 +195,9 @@ class TelegramChannelScraper(snscrape.base.Scraper): return Channel(**kwargs) @classmethod - def setup_parser(cls, subparser): + def cli_setup_parser(cls, subparser): subparser.add_argument('channel', type = snscrape.base.nonempty_string('channel'), help = 'A channel name') @classmethod - def from_args(cls, args): - return cls._construct(args, args.channel) + def cli_from_args(cls, args): + return cls.cli_construct(args, args.channel) diff --git a/snscrape/modules/twitter.py b/snscrape/modules/twitter.py index 8915f5c..06610ad 100644 --- a/snscrape/modules/twitter.py +++ b/snscrape/modules/twitter.py @@ -611,9 +611,9 @@ class _TwitterAPIScraper(snscrape.base.Scraper): return UserLabel(**labelKwargs) @classmethod - def _construct(cls, argparseArgs, *args, **kwargs): + def cli_construct(cls, argparseArgs, *args, **kwargs): kwargs['guestTokenManager'] = _CLIGuestTokenManager() - return super()._construct(argparseArgs, *args, **kwargs) + return super().cli_construct(argparseArgs, *args, **kwargs) class TwitterSearchScraper(_TwitterAPIScraper): @@ -682,14 +682,14 @@ class TwitterSearchScraper(_TwitterAPIScraper): yield from self._instructions_to_tweets(obj) @classmethod - def setup_parser(cls, subparser): + def cli_setup_parser(cls, subparser): subparser.add_argument('--cursor', metavar = 'CURSOR') subparser.add_argument('--top', action = 'store_true', default = False, help = 'Enable fetching top tweets instead of live/chronological') subparser.add_argument('query', type = snscrape.base.nonempty_string('query'), help = 'A Twitter search string') @classmethod - def from_args(cls, args): - return cls._construct(args, args.query, cursor = args.cursor, top = args.top) + def cli_from_args(cls, args): + return cls.cli_construct(args, args.query, cursor = args.cursor, top = args.top) class TwitterUserScraper(TwitterSearchScraper): @@ -758,7 +758,7 @@ class TwitterUserScraper(TwitterSearchScraper): return (1 <= len(s) <= 15 and s.strip(string.ascii_letters + string.digits + '_') == '') or (s and s.strip(string.digits) == '') @classmethod - def setup_parser(cls, subparser): + def cli_setup_parser(cls, subparser): def username(s): if cls.is_valid_username(s): return s @@ -768,8 +768,8 @@ class TwitterUserScraper(TwitterSearchScraper): subparser.add_argument('username', type = username, help = 'A Twitter username (without @)') @classmethod - def from_args(cls, args): - return cls._construct(args, args.username, args.isUserId) + def cli_from_args(cls, args): + return cls.cli_construct(args, args.username, args.isUserId) class TwitterProfileScraper(TwitterUserScraper): @@ -823,12 +823,12 @@ class TwitterHashtagScraper(TwitterSearchScraper): self._hashtag = hashtag @classmethod - def setup_parser(cls, subparser): + def cli_setup_parser(cls, subparser): subparser.add_argument('hashtag', type = snscrape.base.nonempty_string('hashtag'), help = 'A Twitter hashtag (without #)') @classmethod - def from_args(cls, args): - return cls._construct(args, args.hashtag) + def cli_from_args(cls, args): + return cls.cli_construct(args, args.hashtag) class TwitterTweetScraperMode(enum.Enum): @@ -904,15 +904,15 @@ class TwitterTweetScraper(_TwitterAPIScraper): queue.append(tweet.id) @classmethod - def setup_parser(cls, subparser): + def cli_setup_parser(cls, subparser): group = subparser.add_mutually_exclusive_group(required = False) group.add_argument('--scroll', action = 'store_true', default = False, help = 'Enable scrolling in both directions') group.add_argument('--recurse', '--recursive', action = 'store_true', default = False, help = 'Enable recursion through all tweets encountered (warning: slow, potentially memory-intensive!)') subparser.add_argument('tweetId', type = int, help = 'A tweet ID') @classmethod - def from_args(cls, args): - return cls._construct(args, args.tweetId, TwitterTweetScraperMode.from_args(args)) + def cli_from_args(cls, args): + return cls.cli_construct(args, args.tweetId, TwitterTweetScraperMode.from_args(args)) class TwitterListPostsScraper(TwitterSearchScraper): @@ -923,12 +923,12 @@ class TwitterListPostsScraper(TwitterSearchScraper): self._listName = listName @classmethod - def setup_parser(cls, subparser): + def cli_setup_parser(cls, subparser): subparser.add_argument('list', type = snscrape.base.nonempty_string('list'), help = 'A Twitter list ID or a string of the form "username/listname" (replace spaces with dashes)') @classmethod - def from_args(cls, args): - return cls._construct(args, args.list) + def cli_from_args(cls, args): + return cls.cli_construct(args, args.list) class TwitterTrendsScraper(_TwitterAPIScraper): diff --git a/snscrape/modules/vkontakte.py b/snscrape/modules/vkontakte.py index 13aa4e5..91edaae 100644 --- a/snscrape/modules/vkontakte.py +++ b/snscrape/modules/vkontakte.py @@ -374,9 +374,9 @@ class VKontakteUserScraper(snscrape.base.Scraper): return User(**kwargs) @classmethod - def setup_parser(cls, subparser): + def cli_setup_parser(cls, subparser): subparser.add_argument('username', type = snscrape.base.nonempty_string('username'), help = 'A VK username') @classmethod - def from_args(cls, args): - return cls._construct(args, args.username) + def cli_from_args(cls, args): + return cls.cli_construct(args, args.username) diff --git a/snscrape/modules/weibo.py b/snscrape/modules/weibo.py index f6d49ac..a01dc5a 100644 --- a/snscrape/modules/weibo.py +++ b/snscrape/modules/weibo.py @@ -141,15 +141,15 @@ class WeiboUserScraper(snscrape.base.Scraper): return self._user_info_to_entity(o['data']['userInfo']) @classmethod - def setup_parser(cls, subparser): + def cli_setup_parser(cls, subparser): subparser.add_argument('user', type = snscrape.base.nonempty_string('user'), help = 'A user name or ID') @classmethod - def from_args(cls, args): + def cli_from_args(cls, args): if len(args.user) == 10 and args.user.strip('0123456789') == '': uid = args.user name = None else: uid = None name = args.user - return cls._construct(args, name = name, uid = uid) + return cls.cli_construct(args, name = name, uid = uid)