From ea1a714e9b2334e8359d88e02be6891231dc090c Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Mon, 9 Aug 2021 04:58:47 -0700 Subject: [PATCH] Scaffolding for "mooncrawl ethcrawler trending" --- crawlers/mooncrawl/cli.py | 48 +++++++++++++++++++++++++++++++++++++++ crawlers/setup.py | 1 + 2 files changed, 49 insertions(+) diff --git a/crawlers/mooncrawl/cli.py b/crawlers/mooncrawl/cli.py index c37e9ff8..2673269c 100644 --- a/crawlers/mooncrawl/cli.py +++ b/crawlers/mooncrawl/cli.py @@ -8,6 +8,8 @@ import sys import time from typing import Iterator, List +import dateutil.parser + from .ethereum import ( crawl_blocks_executor, crawl_blocks, @@ -164,6 +166,11 @@ def ethcrawler_contracts_update_handler(args: argparse.Namespace) -> None: json.dump(results, args.outfile) +def ethcrawler_trending_handler(args: argparse.Namespace) -> None: + with args.outfile: + print(args) + + def main() -> None: parser = argparse.ArgumentParser(description="Moonstream crawlers CLI") parser.set_defaults(func=lambda _: parser.print_help()) @@ -314,6 +321,47 @@ def main() -> None: func=ethcrawler_contracts_update_handler ) + parser_ethcrawler_trending = subcommands_ethcrawler.add_parser( + "trending", description="Trending addresses on the Ethereum blockchain" + ) + parser_ethcrawler_trending.add_argument( + "-s", + "--start", + type=dateutil.parser.parse, + required=True, + help="Start time for window to calculate trending addresses in", + ) + parser_ethcrawler_trending.add_argument( + "--include-start", + action="store_true", + help="Set this flag if range should include start time", + ) + parser_ethcrawler_trending.add_argument( + "-e", + "--end", + type=dateutil.parser.parse, + required=True, + help="End time for window to calculate trending addresses in", + ) + parser_ethcrawler_trending.add_argument( + "--include-end", + action="store_true", + help="Set this flag if range should include end time", + ) + parser_ethcrawler_trending.add_argument( + "--humbug", + default=None, + help="If you would like to write this data to a Moonstream journal, please provide a Humbug token for that here.", + ) + parser_ethcrawler_trending.add_argument( + "-o", + "--outfile", + type=argparse.FileType("w"), + default=sys.stdout, + help="Optional file to write output to. By default, prints to stdout.", + ) + parser_ethcrawler_trending.set_defaults(func=ethcrawler_trending_handler) + args = parser.parse_args() args.func(args) diff --git a/crawlers/setup.py b/crawlers/setup.py index 737e8d65..29eefd31 100644 --- a/crawlers/setup.py +++ b/crawlers/setup.py @@ -34,6 +34,7 @@ setup( zip_safe=False, install_requires=[ "moonstreamdb @ git+https://git@github.com/bugout-dev/moonstream.git@ec3278e192119d1e8a273cfaab6cb53890d2e8e9#egg=moonstreamdb&subdirectory=db", + "python-dateutil", "requests", "tqdm", "web3",