From 1fb72945930c83e51f1056f4a603c357039d35ea Mon Sep 17 00:00:00 2001 From: supersonicwisd1 <supersonicwisd1> Date: Wed, 11 Dec 2024 07:17:34 +0100 Subject: [PATCH] examples update to involve parameter Signed-off-by: supersonicwisd1 <supersonicwisd1> --- examples/announce.py | 4 ++-- examples/block.py | 6 +++--- examples/follow.py | 6 +++--- examples/like.py | 10 +++++----- examples/minimal_server.py | 2 +- examples/send_message.py | 10 ++++++---- tests/pytest.ini | 2 +- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/examples/announce.py b/examples/announce.py index bc5fc04..5e9b173 100644 --- a/examples/announce.py +++ b/examples/announce.py @@ -21,7 +21,7 @@ from pyfed.security.key_management import KeyManager logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) -async def announce_mastodon_post(): +async def announce_post(): # Initialize components with config key_manager = KeyManager( domain=CONFIG["domain"], @@ -125,4 +125,4 @@ async def announce_mastodon_post(): await delivery.close() if __name__ == "__main__": - asyncio.run(announce_mastodon_post()) + asyncio.run(announce_post()) diff --git a/examples/block.py b/examples/block.py index ca76dac..5a2007d 100644 --- a/examples/block.py +++ b/examples/block.py @@ -21,7 +21,7 @@ from pyfed.security.key_management import KeyManager logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) -async def block_mastodon_user(): +async def block_user(resource="acct:kene29@mastodon.social"): # Initialize components with config key_manager = KeyManager( domain=CONFIG["domain"], @@ -39,7 +39,7 @@ async def block_mastodon_user(): # 1. First, perform WebFinger lookup to get the actor's URL logger.info("Performing WebFinger lookup...") webfinger_result = await discovery.webfinger( - resource="acct:kene29@mastodon.social" # Replace with target username + resource=resource # Replace with target username ) logger.info(f"WebFinger result: {webfinger_result}") @@ -118,4 +118,4 @@ async def block_mastodon_user(): await delivery.close() if __name__ == "__main__": - asyncio.run(block_mastodon_user()) + asyncio.run(block_user()) diff --git a/examples/follow.py b/examples/follow.py index c49a559..b985c25 100644 --- a/examples/follow.py +++ b/examples/follow.py @@ -21,7 +21,7 @@ from pyfed.security.key_management import KeyManager logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) -async def follow_mastodon_user(): +async def follow_user(resource="acct:kene29@mastodon.social"): # Initialize components with config key_manager = KeyManager( domain=CONFIG["domain"], @@ -39,7 +39,7 @@ async def follow_mastodon_user(): # 1. First, perform WebFinger lookup to get the actor's URL logger.info("Performing WebFinger lookup...") webfinger_result = await discovery.webfinger( - resource="acct:kene29@mastodon.social" # Replace with target username + resource=resource # Replace with target username ) logger.info(f"WebFinger result: {webfinger_result}") @@ -118,4 +118,4 @@ async def follow_mastodon_user(): await delivery.close() if __name__ == "__main__": - asyncio.run(follow_mastodon_user()) + asyncio.run(follow_user()) diff --git a/examples/like.py b/examples/like.py index da5c38d..d003e71 100644 --- a/examples/like.py +++ b/examples/like.py @@ -21,7 +21,8 @@ from pyfed.security.key_management import KeyManager logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) -async def like_mastodon_post(): +async def like_post(resource="acct:kene29@mastodon.social", + post_url="https://mastodon.social/@kene29/110089837579093763"): # Initialize components with config key_manager = KeyManager( domain=CONFIG["domain"], @@ -39,7 +40,7 @@ async def like_mastodon_post(): # 1. First, perform WebFinger lookup to get the actor's URL logger.info("Performing WebFinger lookup...") webfinger_result = await discovery.webfinger( - resource="acct:kene29@mastodon.social" # Replace with target username + resource=resource # Replace with target username ) logger.info(f"WebFinger result: {webfinger_result}") @@ -81,8 +82,7 @@ async def like_mastodon_post(): ) # 4. Create Like activity - # Replace with actual post URL you want to like - post_url = "https://mastodon.social/@kene29/113555725485934788" + post_url = post_url like = APLike( id=f"https://{CONFIG['domain']}/activities/{int(asyncio.get_event_loop().time() * 1000)}", @@ -121,4 +121,4 @@ async def like_mastodon_post(): await delivery.close() if __name__ == "__main__": - asyncio.run(like_mastodon_post()) + asyncio.run(like_post()) diff --git a/examples/minimal_server.py b/examples/minimal_server.py index 45b7a01..5cd163d 100644 --- a/examples/minimal_server.py +++ b/examples/minimal_server.py @@ -164,7 +164,7 @@ async def actor_handler(request): active_key = await key_manager.get_active_key() response = { - "@context": "https://www.w3.org/ns/activitystreams", + "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"], "type": "Person", "id": f"https://{CONFIG['domain']}/users/{username}", "preferredUsername": username, diff --git a/examples/send_message.py b/examples/send_message.py index eb4f004..9c5c541 100644 --- a/examples/send_message.py +++ b/examples/send_message.py @@ -21,8 +21,10 @@ from pyfed.security.key_management import KeyManager logging.basicConfig(level=logging.DEBUG) # Set to DEBUG for more detailed logs logger = logging.getLogger(__name__) - # @gvelez17@mas.to -async def send_activity_to_mastodon(): +async def send_activity_to_mastodon( + resource="acct:kene29@mastodon.social", + message="Hello @gvelez17@mas.to! This is a test note to test mention to Golda" + ): # Initialize components with config key_manager = KeyManager( domain=CONFIG["domain"], @@ -47,7 +49,7 @@ async def send_activity_to_mastodon(): # 1. First, perform WebFinger lookup to get the actor's URL logger.info("Performing WebFinger lookup...") webfinger_result = await discovery.webfinger( - resource="acct:kene29@mastodon.social" + resource=resource ) logger.info(f"WebFinger result: {webfinger_result}") @@ -94,7 +96,7 @@ async def send_activity_to_mastodon(): # Create note with string attributed_to note = APNote( id=note_id, - content=f"Hello @gvelez17@mas.to! This is a test note to test mention to Golda", + content=message, attributed_to=str(actor.id), # Convert URL to string to=[inbox_url], cc=["https://www.w3.org/ns/activitystreams#Public"], diff --git a/tests/pytest.ini b/tests/pytest.ini index 669471c..b0e7f96 100644 --- a/tests/pytest.ini +++ b/tests/pytest.ini @@ -4,4 +4,4 @@ asyncio_default_fixture_loop_scope = function filterwarnings = ignore::DeprecationWarning pythonpath = ../src -addopts = --import-mode=importlib \ No newline at end of file +addopts = --import-mode=importlib -p no:warnings -- GitLab