Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import os
- import io
- import curses
- from PIL import Image
- from atproto import Client
- from atproto import models
- from datetime import datetime
- import curses
- import curses.ascii
- import sys
- import curses
- import curses.ascii
- import sys
- import curses
- import curses.ascii
- import sys
- def edit_text_window(stdscr, prompt, initial_text):
- curses.echo()
- stdscr.addstr(0, 0, prompt)
- stdscr.refresh()
- text = initial_text
- while True:
- stdscr.addstr(1, 0, f"Current text length: {len(text)} characters")
- stdscr.addstr(2, 0, "Edit the text below to 300 characters or less (Press ENTER to finish):")
- stdscr.addstr(3, 0, text)
- stdscr.refresh()
- ch = stdscr.getch()
- if ch == curses.ascii.CR:
- break
- elif ch == curses.ascii.BS or ch == 127:
- if len(text) > 0:
- text = text[:-1]
- stdscr.addstr(3, 0, " " * (len(text) + 1))
- stdscr.move(3, 0)
- stdscr.addstr(3, 0, text)
- else:
- text += chr(ch)
- return text
- def edit_text(text):
- return curses.wrapper(edit_text_window, "Warning: Text is too long. Please edit the text to 300 characters or less.", text)
- def main():
- client = Client()
- client.login('username', 'password')
- while True:
- post_type = input("Choose an option:\n(1) Post images\n(2) Post text\n(3) Exit\nYour choice: ")
- if post_type == '1':
- images = []
- image_extensions = ('.jpg', '.jpeg', '.png')
- image_files = [f for f in os.listdir('.') if f.endswith(image_extensions)][:4]
- max_size_kb = 976.56
- for image_file in image_files:
- img = Image.open(image_file)
- img_format = img.format
- while True:
- img_data = io.BytesIO()
- img.save(img_data, format=img_format)
- img_data.seek(0)
- if len(img_data.getvalue()) / 1024 <= max_size_kb:
- break
- img.thumbnail((img.width * 0.9, img.height * 0.9), Image.LANCZOS)
- img_data = img_data.getvalue()
- alt_text = input(f"Enter the alt text for {image_file}: ")
- upload = client.com.atproto.repo.upload_blob(img_data)
- images.append(models.AppBskyEmbedImages.Image(alt=alt_text, image=upload.blob))
- os.remove(image_file)
- if not images:
- print("No images found. Exiting.")
- return
- text = input("Enter the text for the post: ")
- while len(text) > 300:
- text = edit_text(text)
- embed = models.AppBskyEmbedImages.Main(images=images)
- client.com.atproto.repo.create_record(
- models.ComAtprotoRepoCreateRecord.Data(
- repo=client.me.did,
- collection='app.bsky.feed.post',
- record=models.AppBskyFeedPost.Main(
- createdAt=datetime.now().isoformat(), text=text, embed=embed
- ),
- )
- )
- print("Images posted on Bluesky! What else do you want to do?")
- elif post_type == '2':
- text = input("Enter the text for the post: ")
- while len(text) > 300:
- text = edit_text(text)
- client.send_post(text=text)
- print("Text posted on Bluesky! What else do you want to do?")
- elif post_type == '3':
- print("Exiting...")
- sys.exit()
- else:
- print("Invalid input. Please try again.")
- if __name__ == '__main__':
- os.system('cls' if os.name == 'nt' else 'clear')
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement