Skip to content

Instantly share code, notes, and snippets.

@ywindish
Last active February 9, 2021 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ywindish/24bd13951801e6db551a532fcee2b932 to your computer and use it in GitHub Desktop.
Save ywindish/24bd13951801e6db551a532fcee2b932 to your computer and use it in GitHub Desktop.
Images in folder be posted to Mastodon instance at random
require 'mastodon' # https://github.com/tootsuite/mastodon-api
message = '#hashtag'
pattern = '/path/to/image_files/*.jpg'
path = Dir.glob(pattern).sample
client = Mastodon::REST::Client.new(base_url: 'https://fedibird.com', bearer_token: ENV['MASTODON_TOKEN'])
media = client.upload_media(File.new(path))
client.create_status(message, media_ids: [media.id])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment