Skip to content

Instantly share code, notes, and snippets.

@samplereality
Last active May 21, 2024 19:49
Show Gist options
  • Save samplereality/ed086020d400bb99783fb021069b4789 to your computer and use it in GitHub Desktop.
Save samplereality/ed086020d400bb99783fb021069b4789 to your computer and use it in GitHub Desktop.
Moby Deck Python > Bluesky Skeleton
# -*- coding: utf-8 -*-
from atproto import Client, models
# BlueSky Client
bs_client = Client()
bs_client.login('BLUESKYHANDLE', 'BLUESKYPASSWORD')
# Now time to tweet a new line from Moby Dick
# Get index line
# 'mobyindex.txt' is a text file that contains the line number of the most recently posted passage
f = open('/home/pi/Documents/bots/mobydick/mobyindex.txt','r')
index = int(f.read().strip())
f.close()
# Update index
# Bump up the index by 1, so bot knows what the next passage to post is
f = open('/home/pi/Documents/bots/mobydick/mobyindex.txt','w')
f.write("%d" % (index + 1))
f.close()
# Read new line from database of lines and pick out the line with the appropriate index number
f = open('/home/pi/Documents/bots/mobydick/mobytweet.txt','r')
lines = f.readlines()
verse = lines[index]
# post to Bsky
bs_client.send_post(text=verse)
@samplereality
Copy link
Author

A few other notes: I run this from a Raspberry Pi. There are three necessary files:

  1. This python program (written for Python 3.11)
  2. A raw text file of lines to be posted to Bluesky
  3. An index file that keeps track of the most recently posted line

The secret sauce for communicating with Bluesky is the atproto Python library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment