"ethcrawler trending" humbug token from env

This makes life easier when using it as a systemd service.

Also added systemd service and timer for trending addresses crawler.
pull/94/head
Neeraj Kashyap 2021-08-09 18:58:43 -07:00
rodzic 58a9268b4d
commit 0e98794db9
3 zmienionych plików z 30 dodań i 2 usunięć

Wyświetl plik

@ -0,0 +1,11 @@
[Unit]
Description=Load trending Ethereum addresses to the database
After=network.target
[Service]
Type=oneshot
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/moonstream/crawlers
EnvironmentFile=/home/ubuntu/mooncrawl-secrets/app.env
ExecStart=/usr/bin/bash -c '/home/ubuntu/mooncrawl-env/bin/python -m mooncrawl.ethcrawler trending -s $(date -u -d '-2 hours' +%Y%m%d-%H%MT%z) -e $(date -u +%Y%m%d-%H%MT%z)'

Wyświetl plik

@ -0,0 +1,9 @@
[Unit]
Description=Load trending Ethereum addresses to the database every 5 minutes
[Timer]
OnBootSec=10s
OnUnitActiveSec=5m
[Install]
WantedBy=timers.target

Wyświetl plik

@ -4,6 +4,7 @@ Moonstream crawlers CLI.
import argparse import argparse
from enum import Enum from enum import Enum
import json import json
import os
import sys import sys
import time import time
from typing import Iterator, List from typing import Iterator, List
@ -177,7 +178,10 @@ def ethcrawler_trending_handler(args: argparse.Namespace) -> None:
include_end=args.include_end, include_end=args.include_end,
) )
results = trending(date_range) results = trending(date_range)
if args.humbug: humbug_token = args.humbug
if humbug_token is None:
humbug_token = os.environ.get("MOONSTREAM_HUMBUG_TOKEN")
if humbug_token:
opening_bracket = "[" if args.include_start else "(" opening_bracket = "[" if args.include_start else "("
closing_bracket = "]" if args.include_end else ")" closing_bracket = "]" if args.include_end else ")"
title = f"Ethereum trending addresses: {opening_bracket}{args.start}, {args.end}{closing_bracket}" title = f"Ethereum trending addresses: {opening_bracket}{args.start}, {args.end}{closing_bracket}"
@ -358,7 +362,11 @@ def main() -> None:
parser_ethcrawler_trending.add_argument( parser_ethcrawler_trending.add_argument(
"--humbug", "--humbug",
default=None, default=None,
help="If you would like to write this data to a Moonstream journal, please provide a Humbug token for that here.", help=(
"If you would like to write this data to a Moonstream journal, please provide a Humbug "
"token for that here. (This argument overrides any value set in the "
"MOONSTREAM_HUMBUG_TOKEN environment variable)"
),
) )
parser_ethcrawler_trending.add_argument( parser_ethcrawler_trending.add_argument(
"-o", "-o",