6.2.2. Demo & Practice: Author Info#
Choose Social Media Platform: Bluesky | Reddit | Discord | No Coding
Though Bluesky might collect the device/program sources of submissions (like we saw from former President Trump), it unfortunately doesn’t let us see them.
Instead we will look at other information about the author of posts on Bluesky that can perhaps tell us something about their authenticity.
But first, we need our helper functions for converting Bluesky feed weblink urls and atproto uris:
helper function for atproto links#
NOTE: You don’t need to worry about the details of how this works, it just is here to make the code later easier to use.
import re #load a "regular expression" library for helping to parse text
# function to convert a post's special atproto "at" URI to a weblink url
def get_weblink_from_post(post):
# Get the user id and post id from the weblink url
match = re.search(r'at://([^/]+)/app.bsky.feed.post/([^/]+)', post.uri)
if not match:
raise ValueError("Invalid Bluesky atproto post URL format.")
user_id, post_id = match.groups()
post_uri = f"https://bsky.app/profile/{user_id}/post/{post_id}"
return post_uri
# function to take an author profile and generate a weblink url
def get_weblink_from_profile(author_info):
author_uri = f"https://bsky.app/profile/{author_info.did}"
return author_uri
Log into Bluesky (atproto)#
These are our normal steps get atproto loaded and logged into Bluesky
from atproto import Client
(optional) make a fake Bluesky connection with the fake_atproto library For testing purposes, we”ve added this line of code, which loads a fake version of atproto, so it wont actually connect to Bluesky. If you want to try to actually connect to Bluesky, don’t run this line of code.
%run ../../fake_apis/fake_atproto.ipynb
# Login to Bluesky
# TODO: put your account name and password below
client = Client(base_url="https://bsky.social")
client.login("your_account_name.bsky.social", "m#5@_fake_bsky_password_$%Ds")
Load a set of Bluesky posts and look up author information#
The code below searches posts from Bluesky that includes the word news, and then does a loop though all the posts, for each one making another request to Bluesky for the author info, then printing out some of that information, such as:
followers_count (how many accounts this author follows)
follows_count (how many accounts follow this author)
posts_count (how many posts this account has made)
Try running other searches and see what you notice about the authors of posts.
To do this:
put in your Bluesky bot username and passwords
skip the fake_atproto step above
take the first line of the code below and replace the search term with a different search term
Note: If you run this on real Bluesky, we can’t gurantee anything about how offensive what you might find is.
# Save what we want to search for in a variable
search_query = "news"
# run the search and save the resulting list in a variable
search_result_posts = client.app.bsky.feed.search_posts({'q': search_query}).posts
# go through each post and look up author information for that post
for post in search_result_posts:
print("Info for post with url: " + str(get_weblink_from_post(post)))
# look up additional information about that author
author_did = post.author.did
author_info = client.app.bsky.actor.get_profile({'actor': author_did})
# print out various pieces of author info
print(" author handle: " + str(author_info.handle))
print(" author display name: " + str(author_info.display_name))
print(" author creation date: " + str(author_info.created_at))
print(" author did: " + str(author_info.did))
print(" author followers_count: " + str(author_info.followers_count))
print(" author follows_count: " + str(author_info.follows_count))
print(" author posts_count: " + str(author_info.posts_count))
print(" author avatar: " + str(author_info.avatar))
print(" author banner: " + str(author_info.banner))
print(" author description: " + str(author_info.description))
print(" author profile url: " + get_weblink_from_profile(author_info))
print()
print()
Info for post with url: https://bsky.app/profile/did:plc:fake_user/post/fake_post_id
author handle: fake_user.bsky.social
author display name: Fake User
author creation date: 2024-1-01
author did: 93j45jg9ej5gjt
author followers_count: 75
author follows_count: 345
author posts_count: 13
author avatar: fake_user_profile.jpg
author banner: fake_user_banner.jpg
author description: I am a fake user!
author profile url: https://bsky.app/profile/93j45jg9ej5gjt
Info for post with url: https://bsky.app/profile/did:plc:pretend_user/post/fake_post_id
author handle: pretend_user.bsky.social
author display name: Pretend User
author creation date: 2024-3-02
author did: 75n4tk5gn4oi
author followers_count: 2
author follows_count: 1323
author posts_count: 1
author avatar: pretend_user_profile.jpg
author banner: pretend_user_banner.jpg
author description: I am a pretend user!
author profile url: https://bsky.app/profile/75n4tk5gn4oi
Info for post with url: https://bsky.app/profile/did:plc:imaginary_user/post/fake_post_id
author handle: imaginary_user.bsky.social
author display name: Imaginary User
author creation date: 2022-1-01
author did: 5kj45nkj4n6kj45n
author followers_count: 50
author follows_count: 60
author posts_count: 355
author avatar: imaginary_user_profile.jpg
author banner: imaginary_user_banner.jpg
author description: I am an imaginary user!
author profile url: https://bsky.app/profile/5kj45nkj4n6kj45n
Info for post with url: https://bsky.app/profile/did:plc:mysterious_user/post/fake_post_id
author handle: mysterious_user.bsky.social
author display name: Mysterious User
author creation date: 2022-1-01
author did: 433489n34n943h5943h
author followers_count: 4233
author follows_count: 7
author posts_count: 120
author avatar: mysterious_user_profile.jpg
author banner: mysterious_user_banner.jpg
author description: I am a mysterious user!
author profile url: https://bsky.app/profile/433489n34n943h5943h