#!/usr/bin/env python3 # pdt: post to FSF social media via command line # Copyright (C) 2021 Ian Kelling # SPDX-License-Identifier: AGPL-3.0-or-later # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # Usage: see pdt.sh example. import sys import tweepy import time from twitter_keys import * auth = tweepy.OAuth1UserHandler( consumer_key, consumer_secret, access_token, access_token_secret ) api = tweepy.API(auth) client = tweepy.Client( consumer_key=consumer_key, consumer_secret=consumer_secret, access_token=access_token, access_token_secret=access_token_secret ) if len(sys.argv) == 2: response = client.delete_tweet(sys.argv[1]) else: input_text = input() posts=input_text.split("/tnt/") post_count=len(posts) tweet_text=posts[0].strip() if post_count > 1: tweet_text=tweet_text + f" 1/{post_count}" have_image = False try: image_path = input() have_image = True except: pass have_alt = False try: alt = input() have_alt = True except: pass if have_image: media = api.media_upload(image_path) media_id = media.media_id_string if have_alt: api.create_media_metadata(media_id, alt) if have_image: response = client.create_tweet(text=tweet_text, media_ids=[media_id]) else: #print(tweet_text) response = client.create_tweet(text=tweet_text) print(f"https://nitter.net/user/status/{response.data['id']}") if post_count > 1: for x in range(1, post_count): time.sleep(1) tweet_text=posts[x].strip() + f" {x+1}/{post_count}" response = client.create_tweet(text=tweet_text, in_reply_to_tweet_id=response.data['id']) print(f"{x+1}/{post_count} https://nitter.net/user/status/{response.data['id']}") #print(tweet_text)