From d5e2293848a3506a1b13144062c24bae1cc10f2c Mon Sep 17 00:00:00 2001 From: Ilya Siamionau Date: Fri, 28 Jul 2023 22:22:36 +0400 Subject: [PATCH] Add update profile example (#120) --- examples/advanced_usage/update_profile.py | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 examples/advanced_usage/update_profile.py diff --git a/examples/advanced_usage/update_profile.py b/examples/advanced_usage/update_profile.py new file mode 100644 index 00000000..0b2510d5 --- /dev/null +++ b/examples/advanced_usage/update_profile.py @@ -0,0 +1,40 @@ +import os + +from atproto import Client, models + + +def main(): + client = Client() + client.login(os.environ['USERNAME'], os.environ['PASSWORD']) + + current_profile_record = client.com.atproto.repo.get_record( + models.ComAtprotoRepoGetRecord.Params( + collection=models.ids.AppBskyActorProfile, + repo=client.me.did, + rkey='self', + ) + ) + current_profile = current_profile_record.value + + # set new values to update + new_description = None + new_display_name = 'I love Python' + + client.com.atproto.repo.put_record( + models.ComAtprotoRepoPutRecord.Data( + collection=models.ids.AppBskyActorProfile, + repo=client.me.did, + rkey='self', + swapRecord=current_profile_record.cid, + record=models.AppBskyActorProfile.Main( + avatar=current_profile.avatar, + banner=current_profile.banner, + description=new_description or current_profile.description, + displayName=new_display_name or current_profile.display_name, + ), + ) + ) + + +if __name__ == '__main__': + main()