2 # pdt: post to FSF social media via command line
3 # Copyright (C) 2021 Ian Kelling
4 # SPDX-License-Identifier: AGPL-3.0-or-later
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 # Usage: see pdt.sh example.
25 from twitter_keys
import *
29 # logging.basicConfig(level=logging.DEBUG)
32 ## begin cli option parsing ##
34 if len(sys
.argv
) == 2 and sys
.argv
[1] == "-v":
36 ## end cli option parsing ##
40 auth
= tweepy
.OAuth1UserHandler(
41 consumer_key
, consumer_secret
, access_token
, access_token_secret
43 api
= tweepy
.API(auth
)
44 client
= tweepy
.Client(
45 consumer_key
=consumer_key
, consumer_secret
=consumer_secret
,
46 access_token
=access_token
, access_token_secret
=access_token_secret
51 if len(sys
.argv
) == 3:
52 if sys
.argv
[1] == '--delete':
53 client
.delete_tweet(sys
.argv
[2])
54 elif sys
.argv
[1] == '--pin':
55 api
.pin_tweet(sys
.argv
[2])
56 elif sys
.argv
[1] == '--unpin':
57 api
.unpin_tweet(sys
.argv
[2])
58 elif sys
.argv
[1] == '--banner':
59 api
.update_profile_banner(sys
.argv
[2])
61 print("t.py: error: unexpected argument. exiting without doing anything")
65 #### For the rest of the script:: no action specified in cli arguments,
66 #### post based on input from STDIN
69 posts
=input_text
.split("/tnt/")
72 tweet_text
=posts
[0].strip()
75 tweet_text
=tweet_text
+ f
" 1/{post_count}"
90 media
= api
.media_upload(image_path
)
91 media_id
= media
.media_id_string
94 api
.create_media_metadata(media_id
, alt
)
98 response
= client
.create_tweet(text
=tweet_text
, media_ids
=[media_id
])
100 response
= client
.create_tweet(text
=tweet_text
)
102 print(response
.data
['id'])
104 for x
in range(1, post_count
):
106 tweet_text
=posts
[x
].strip() + f
" {x+1}/{post_count}"
107 response
= client
.create_tweet(text
=tweet_text
, in_reply_to_tweet_id
=response
.data
['id'])
109 print(response
.data
['id'])