kopia lustrzana https://github.com/bugout-dev/moonstream
Functionality to publish JSON results to Humbug
For `mooncrawl ethcrawler trending`pull/92/head
rodzic
2d513800aa
commit
d9d863e742
|
@ -19,6 +19,7 @@ from .ethereum import (
|
|||
DateRange,
|
||||
trending,
|
||||
)
|
||||
from .publish import publish_json
|
||||
from .settings import MOONSTREAM_CRAWL_WORKERS
|
||||
|
||||
|
||||
|
@ -176,6 +177,11 @@ def ethcrawler_trending_handler(args: argparse.Namespace) -> None:
|
|||
include_end=args.include_end,
|
||||
)
|
||||
results = trending(date_range)
|
||||
if args.humbug:
|
||||
opening_bracket = "[" if args.include_start else "("
|
||||
closing_bracket = "]" if args.include_end else ")"
|
||||
title = f"Ethereum trending addresses: {opening_bracket}{args.start}, {args.end}{closing_bracket}"
|
||||
publish_json("ethereum_trending", args.humbug, title, results)
|
||||
with args.outfile as ofp:
|
||||
json.dump(results, ofp)
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
import json
|
||||
import os
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def publish_json(
|
||||
crawl_type: str,
|
||||
humbug_token: str,
|
||||
title: str,
|
||||
content: Dict[str, Any],
|
||||
tags: Optional[List[str]] = None,
|
||||
) -> None:
|
||||
spire_api_url = os.environ.get(
|
||||
"MOONSTREAM_SPIRE_API_URL", "https://spire.bugout.dev"
|
||||
).rstrip("/")
|
||||
report_url = f"{spire_api_url}/humbug/reports"
|
||||
|
||||
if tags is None:
|
||||
tags = []
|
||||
|
||||
tags.append(f"crawl_type:{crawl_type}")
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {humbug_token}",
|
||||
}
|
||||
request_body = {"title": title, "content": json.dumps(content), "tags": tags}
|
||||
query_parameters = {"sync": True}
|
||||
response = requests.post(
|
||||
report_url, headers=headers, json=request_body, params=query_parameters
|
||||
)
|
||||
response.raise_for_status()
|
Ładowanie…
Reference in New Issue