Something went wrong. Try again.
Documentation website about Ruby gems for ATProto ruby.sdk.blue
atprotocol bluesky ruby atproto
Something went wrong. Try again.
1.5 kB · 64 lines
Ruby
at master
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465#!/usr/bin/env ruby
# Example: fetch profile info of a given user and their last 10 posts (excluding reposts).## This script connects to the AppView server at api.bsky.app, which allows calling such# endpoints as getProfile or getAuthorFeed without authentication.
require 'bundler/setup'require 'didkit'require 'minisky'require 'time'
$handle = ARGV[0]
if $handle.nil? puts "Usage: #{$PROGRAM_NAME} <handle | did>" exit 1end
$did = DID.resolve_handle($handle).to_s
if $did.empty? puts "Couldn't resolve handle: #{$handle}" exit 1end
# passing nil as config file to use an unauthenticated clientbsky = Minisky.new('api.bsky.app', nil)
# fetch profile infoprofile = bsky.get_request('app.bsky.actor.getProfile', { actor: $did })
# fetch posts, without replies - we fetch a bit more than we need because we'll also# filter out reposts on our sideposts = bsky.get_request('app.bsky.feed.getAuthorFeed', { actor: $did, filter: 'posts_no_replies', limit: 40})
# print the profile info
putsputs "====[ @#{profile['handle']} • #{profile['displayName']} • #{profile['did']} ]===="putsputs profile['description']putsputs '=' * 80puts
# print the posts
posts['feed'].map { |r| r['post']}.select { |p| # select only posts from this account p['author']['did'] == $did}.slice(0, 10).each { |p| time = Time.parse(p['record']['createdAt']) timestamp = time.getlocal.strftime('%a %d.%m %H:%M')
puts "#{timestamp}: #{p['record']['text']}" puts}