From 51b61d2db7c5be04167b7c2b0b93130a44ef65ad Mon Sep 17 00:00:00 2001 From: SouthFox Date: Mon, 19 Jun 2023 10:03:31 +0800 Subject: [PATCH] [feat] add fetch function --- demo/activitypub.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 demo/activitypub.py diff --git a/demo/activitypub.py b/demo/activitypub.py new file mode 100644 index 0000000..03f13fe --- /dev/null +++ b/demo/activitypub.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +"""ActivityPub settings, fetch & post""" +import httpx +import config + + +def fetch( + url: str, +) -> dict: + """Fetch url and return json""" + print(f"fetch {url}") + + with httpx.Client() as client: + resp = client.get( + url, + headers={ + "User-Agent": config.USER_AGENT, + "Accept": config.AP_CONTENT_TYPE, + } + ) + + return resp.json()