diff --git a/examples/announce.py b/examples/announce.py index bc5fc04f4b780b21ec3896f0f8703a90c5f4d554..5e9b1731b41bbf3cd69c63c442bd95c86d30908b 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 ca76dac60d377f039dbd6d903b5c3ffe1bbb92e8..5a2007dc585705439863486490f9289cebd66313 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 c49a5598bcc29e7ab91f3445600e64a6b9ef3dd5..b985c25d0864b78fc1e70fe09222e17301dd1f34 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 da5c38d04134467b2132031a6d8ca4828f426ba0..d003e71a3af702d1dba97c9a7771e0bc4fedee43 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 45b7a0104e92d73e6a0b337a8dbd38a725a42944..5cd163d1e5032c446db90c8fc488c484cc506b0f 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 eb4f00493e234823d2734a457ca09b46a9303564..9c5c541bd794a72ee0c5c4a76859c8dbbdb1ff70 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 669471c40476a11d413e1ed9503473f5fdb356d3..b0e7f961bba6a16507d8e42d4e0724c5f5102a38 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