Commit | Line | Data |
---|---|---|
f9ace606 | 1 | #!/usr/bin/env python3 |
03c21027 IK |
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 | |
f9ace606 | 5 | |
03c21027 IK |
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. | |
10 | ||
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. | |
15 | ||
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/>. | |
18 | ||
19 | # Usage: see pdt.sh example. | |
f9ace606 IK |
20 | |
21 | import sys | |
03c21027 IK |
22 | import tweepy |
23 | import time | |
24 | from twitter_keys import * | |
25 | ||
26 | ||
27 | auth = tweepy.OAuth1UserHandler( | |
28 | consumer_key, consumer_secret, access_token, access_token_secret | |
29 | ) | |
30 | ||
31 | api = tweepy.API(auth) | |
32 | ||
33 | client = tweepy.Client( | |
34 | consumer_key=consumer_key, consumer_secret=consumer_secret, | |
35 | access_token=access_token, access_token_secret=access_token_secret | |
36 | ) | |
37 | ||
38 | if len(sys.argv) == 2: | |
39 | response = client.delete_tweet(sys.argv[1]) | |
f9ace606 | 40 | else: |
03c21027 IK |
41 | input_text = input() |
42 | ||
43 | posts=input_text.split("/tnt/") | |
44 | post_count=len(posts) | |
45 | ||
46 | tweet_text=posts[0].strip() | |
47 | ||
48 | if post_count > 1: | |
49 | tweet_text=tweet_text + f" 1/{post_count}" | |
50 | ||
51 | have_image = False | |
52 | try: | |
53 | image_path = input() | |
54 | have_image = True | |
55 | except: | |
56 | pass | |
57 | ||
58 | have_alt = False | |
59 | try: | |
60 | alt = input() | |
61 | have_alt = True | |
62 | except: | |
63 | pass | |
64 | if have_image: | |
65 | media = api.media_upload(image_path) | |
66 | media_id = media.media_id_string | |
67 | ||
68 | if have_alt: | |
69 | api.create_media_metadata(media_id, alt) | |
70 | ||
71 | ||
72 | if have_image: | |
73 | response = client.create_tweet(text=tweet_text, media_ids=[media_id]) | |
74 | else: | |
75 | #print(tweet_text) | |
76 | response = client.create_tweet(text=tweet_text) | |
77 | print(f"https://nitter.net/user/status/{response.data['id']}") | |
78 | if post_count > 1: | |
79 | for x in range(1, post_count): | |
80 | time.sleep(1) | |
81 | tweet_text=posts[x].strip() + f" {x+1}/{post_count}" | |
82 | response = client.create_tweet(text=tweet_text, in_reply_to_tweet_id=response.data['id']) | |
83 | print(f"{x+1}/{post_count} https://nitter.net/user/status/{response.data['id']}") | |
84 | #print(tweet_text) |