Created
January 26, 2024 14:55
-
-
Save fabiocosta0305/06261fbfd0ff550d84701ee254b4e24d to your computer and use it in GitHub Desktop.
Nova versão do Uploader em Massa para Mastodon/Pixelfed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mastodon import Mastodon | |
import os | |
''' | |
You'll need an API Key for the Mastodon/Pixelfed instance with at least read and write permissions | |
Você vai precisar de uma chave API com permissão para leitura (read) e escrita (write) pelo menos. | |
''' | |
connect=Mastodon(access_token=<token>,api_base_url=<instance_link>) | |
dirpath=<path for your pictures> | |
listfiles=os.listdir(dirpath) | |
files=sorted( filter( lambda x: os.path.isfile(os.path.join(dirpath, x)), | |
os.listdir(dirpath) )) | |
files.sort(reverse=True ) | |
message=<message for the posts/descriptions> | |
max_post=10 # by default, Pixelfed accepts 4 images/post | |
medias=[] | |
while files: | |
path=dirpath+"/"+files.pop() | |
#print(path) | |
data=connect.media_post(path,'image/jpg',message) | |
medias.append(data['id']) | |
if len(medias)>=max_post or files==[]: | |
connect.status_post(message,media_ids=medias) | |
medias=[] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment