Skip to content
Snippets Groups Projects
Commit 1fb72945 authored by supersonicwisd1's avatar supersonicwisd1
Browse files

examples update to involve parameter

Signed-off-by: supersonicwisd1 <supersonicwisd1>
parent 6fc4679a
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,7 @@ from pyfed.security.key_management import KeyManager ...@@ -21,7 +21,7 @@ from pyfed.security.key_management import KeyManager
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
async def announce_mastodon_post(): async def announce_post():
# Initialize components with config # Initialize components with config
key_manager = KeyManager( key_manager = KeyManager(
domain=CONFIG["domain"], domain=CONFIG["domain"],
...@@ -125,4 +125,4 @@ async def announce_mastodon_post(): ...@@ -125,4 +125,4 @@ async def announce_mastodon_post():
await delivery.close() await delivery.close()
if __name__ == "__main__": if __name__ == "__main__":
asyncio.run(announce_mastodon_post()) asyncio.run(announce_post())
...@@ -21,7 +21,7 @@ from pyfed.security.key_management import KeyManager ...@@ -21,7 +21,7 @@ from pyfed.security.key_management import KeyManager
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
async def block_mastodon_user(): async def block_user(resource="acct:kene29@mastodon.social"):
# Initialize components with config # Initialize components with config
key_manager = KeyManager( key_manager = KeyManager(
domain=CONFIG["domain"], domain=CONFIG["domain"],
...@@ -39,7 +39,7 @@ async def block_mastodon_user(): ...@@ -39,7 +39,7 @@ async def block_mastodon_user():
# 1. First, perform WebFinger lookup to get the actor's URL # 1. First, perform WebFinger lookup to get the actor's URL
logger.info("Performing WebFinger lookup...") logger.info("Performing WebFinger lookup...")
webfinger_result = await discovery.webfinger( 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}") logger.info(f"WebFinger result: {webfinger_result}")
...@@ -118,4 +118,4 @@ async def block_mastodon_user(): ...@@ -118,4 +118,4 @@ async def block_mastodon_user():
await delivery.close() await delivery.close()
if __name__ == "__main__": if __name__ == "__main__":
asyncio.run(block_mastodon_user()) asyncio.run(block_user())
...@@ -21,7 +21,7 @@ from pyfed.security.key_management import KeyManager ...@@ -21,7 +21,7 @@ from pyfed.security.key_management import KeyManager
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
async def follow_mastodon_user(): async def follow_user(resource="acct:kene29@mastodon.social"):
# Initialize components with config # Initialize components with config
key_manager = KeyManager( key_manager = KeyManager(
domain=CONFIG["domain"], domain=CONFIG["domain"],
...@@ -39,7 +39,7 @@ async def follow_mastodon_user(): ...@@ -39,7 +39,7 @@ async def follow_mastodon_user():
# 1. First, perform WebFinger lookup to get the actor's URL # 1. First, perform WebFinger lookup to get the actor's URL
logger.info("Performing WebFinger lookup...") logger.info("Performing WebFinger lookup...")
webfinger_result = await discovery.webfinger( 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}") logger.info(f"WebFinger result: {webfinger_result}")
...@@ -118,4 +118,4 @@ async def follow_mastodon_user(): ...@@ -118,4 +118,4 @@ async def follow_mastodon_user():
await delivery.close() await delivery.close()
if __name__ == "__main__": if __name__ == "__main__":
asyncio.run(follow_mastodon_user()) asyncio.run(follow_user())
...@@ -21,7 +21,8 @@ from pyfed.security.key_management import KeyManager ...@@ -21,7 +21,8 @@ from pyfed.security.key_management import KeyManager
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__) 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 # Initialize components with config
key_manager = KeyManager( key_manager = KeyManager(
domain=CONFIG["domain"], domain=CONFIG["domain"],
...@@ -39,7 +40,7 @@ async def like_mastodon_post(): ...@@ -39,7 +40,7 @@ async def like_mastodon_post():
# 1. First, perform WebFinger lookup to get the actor's URL # 1. First, perform WebFinger lookup to get the actor's URL
logger.info("Performing WebFinger lookup...") logger.info("Performing WebFinger lookup...")
webfinger_result = await discovery.webfinger( 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}") logger.info(f"WebFinger result: {webfinger_result}")
...@@ -81,8 +82,7 @@ async def like_mastodon_post(): ...@@ -81,8 +82,7 @@ async def like_mastodon_post():
) )
# 4. Create Like activity # 4. Create Like activity
# Replace with actual post URL you want to like post_url = post_url
post_url = "https://mastodon.social/@kene29/113555725485934788"
like = APLike( like = APLike(
id=f"https://{CONFIG['domain']}/activities/{int(asyncio.get_event_loop().time() * 1000)}", id=f"https://{CONFIG['domain']}/activities/{int(asyncio.get_event_loop().time() * 1000)}",
...@@ -121,4 +121,4 @@ async def like_mastodon_post(): ...@@ -121,4 +121,4 @@ async def like_mastodon_post():
await delivery.close() await delivery.close()
if __name__ == "__main__": if __name__ == "__main__":
asyncio.run(like_mastodon_post()) asyncio.run(like_post())
...@@ -164,7 +164,7 @@ async def actor_handler(request): ...@@ -164,7 +164,7 @@ async def actor_handler(request):
active_key = await key_manager.get_active_key() active_key = await key_manager.get_active_key()
response = { response = {
"@context": "https://www.w3.org/ns/activitystreams", "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
"type": "Person", "type": "Person",
"id": f"https://{CONFIG['domain']}/users/{username}", "id": f"https://{CONFIG['domain']}/users/{username}",
"preferredUsername": username, "preferredUsername": username,
......
...@@ -21,8 +21,10 @@ from pyfed.security.key_management import KeyManager ...@@ -21,8 +21,10 @@ from pyfed.security.key_management import KeyManager
logging.basicConfig(level=logging.DEBUG) # Set to DEBUG for more detailed logs logging.basicConfig(level=logging.DEBUG) # Set to DEBUG for more detailed logs
logger = logging.getLogger(__name__) 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 # Initialize components with config
key_manager = KeyManager( key_manager = KeyManager(
domain=CONFIG["domain"], domain=CONFIG["domain"],
...@@ -47,7 +49,7 @@ async def send_activity_to_mastodon(): ...@@ -47,7 +49,7 @@ async def send_activity_to_mastodon():
# 1. First, perform WebFinger lookup to get the actor's URL # 1. First, perform WebFinger lookup to get the actor's URL
logger.info("Performing WebFinger lookup...") logger.info("Performing WebFinger lookup...")
webfinger_result = await discovery.webfinger( webfinger_result = await discovery.webfinger(
resource="acct:kene29@mastodon.social" resource=resource
) )
logger.info(f"WebFinger result: {webfinger_result}") logger.info(f"WebFinger result: {webfinger_result}")
...@@ -94,7 +96,7 @@ async def send_activity_to_mastodon(): ...@@ -94,7 +96,7 @@ async def send_activity_to_mastodon():
# Create note with string attributed_to # Create note with string attributed_to
note = APNote( note = APNote(
id=note_id, 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 attributed_to=str(actor.id), # Convert URL to string
to=[inbox_url], to=[inbox_url],
cc=["https://www.w3.org/ns/activitystreams#Public"], cc=["https://www.w3.org/ns/activitystreams#Public"],
......
...@@ -4,4 +4,4 @@ asyncio_default_fixture_loop_scope = function ...@@ -4,4 +4,4 @@ asyncio_default_fixture_loop_scope = function
filterwarnings = filterwarnings =
ignore::DeprecationWarning ignore::DeprecationWarning
pythonpath = ../src pythonpath = ../src
addopts = --import-mode=importlib addopts = --import-mode=importlib -p no:warnings
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment