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 # This is meant to be sourced.
21 PATH
="$HOME/.local/bin:$PATH"
23 # usage: rbow [-PROFILE_NAME] [COMMAND]
25 # Wrapper for rainbowstream to use multiple logins and tweet directly
26 # from the command line. PROFILE_NAME can be anything you want.
29 oath
=$HOME/.rainbow_oauth
30 if [[ $1 == -* ]]; then
35 source ~
/src
/rainbowstream
/venv
/bin
/activate
39 # adds a short delay after each send for more reliable operation
40 set force_conservative 1
43 expect -nocase timeout {exit 1} "@*]: "
44 set cmd [lindex $argv 0];
46 expect -nocase timeout {exit 1} "@*]: "
47 # this may not be needed. didnt test
52 expect
$f "$*" ||
{ echo error
: expect failed
; deactivate
; rm -f $f; return 1; }
61 source ~
/src
/diaspy
/venv
/bin
/activate
62 python3 ~
/src
/jan-pona-mute
/jan-pona-mute.py
"$@" ||
{ deactivate
; return 1; }
66 # usage: toot [-PROFILE_NAME] [TOOT_ARGS]
69 source ~
/src
/toot
/venv
/bin
/activate
70 if [[ $1 == -* ]]; then
73 command toot activate
--quiet $account ||
{ deactivate
; return 1; }
75 command toot
"$@" ||
{ deactivate
; return 1; }
80 # post to mastodon + twitter + gnu social post + diaspora
82 # Diaspora is skipped if posting to dbd accounts.
84 # If posting video, it only goes to twitter. Other accounts can be
85 # posted to manually with free software.
87 # usage: pdt [--dbd] [-m MEDIA_FILE] [-v VIDEO_PATH] [POST]
89 local video media rbow_account gs_account mastodon_account dbd video rbow_arg toot_arg dia_arg gs_arg
90 if [[ $pdttest ]]; then
93 mastodon_account
=iank@hostux.social
97 mastodon_account
=fsf@hostux.social
101 while [[ $1 == -* ]]; do
106 rbow_arg
=" --i $media"
107 toot_arg
="--media $media"
109 gs_arg
="-F media=@$media"
115 mastodon_account
=endDRM@hostux.social
125 if [[ $media ]]; then
126 if [[ ! -e $media ]]; then
127 echo "error: file not found $media"
130 if [[ $media == *\
* ]]; then
131 echo "error: file path contains a space. move it to non-space path"
135 # if we have no argument
137 read -r -p "input PDT text: " input
140 if [[ $
- == *i
* ]]; then
141 echo "About to PDT the following line. Press enter to confirm or ctrl-c to quit:"
147 oath
=$HOME/.rainbow_oauth
153 ln -s ${oath}-$account $oath
154 python3 ~
/src
/video-tweet
/async-upload.py
"$media" "$*"
158 if ! rbow
-$rbow_account t
"$*" $rbow_arg; then
161 if ! toot
-$mastodon_account post
"$*" $toot_arg; then
165 if ! printf "post %s\n" "${dia_arg}$*" | diaspora
; then
169 # https://gnusocial.net/doc/twitterapi
170 if ! curl
-o /dev
/null
-sS -u "$gs_account:$(cat ~/.gnusocial_login-$gs_account)" \
171 $gs_arg -F "status=$*" https
://status.fsf.org
/api
/statuses
/update.xml
; then
174 if (( ${#fails[@]} )); then
175 printf "$(tput setaf 5)█$(tput sgr0)%.0s" $
(eval echo "{1..${COLUMNS:-60}}"); echo
176 echo "FSF ERROR: ${fails[*]} might not have posted" >&2
182 if [[ $pdttest ]]; then
183 mastodon_accounts
=(iank
)
185 mastodon_accounts
=(fsf endDRM
)
190 for repo
in errhandle rainbowstream diaspy jan-pona-mute video-tweet
; do
191 if [[ -e $repo ]]; then
194 git
reset --hard origin
/master
198 git clone https
://vcs.fsf.org
/git
/$repo.git
201 source ~
/src
/errhandle
/err
202 cp ~
/src
/rainbowstream
/rainbowstream
/colorset
/config ~
/.rainbow_config.json
204 if [[ ! -e ~
/.local
/bin
/pip
]]; then
206 wget
-O$tmp https
://bootstrap.pypa.io
/get-pip.py
212 if [[ ! -e ~
/.local
/bin
/virtualenv
]]; then
213 python3
-m pip
install --user virtualenv
216 cd ~
/src
/rainbowstream
217 python3
-m virtualenv
-p python3 venv
218 source venv
/bin
/activate
219 python3
-m pip
install -r requirements.txt
220 python3
-m pip
install -e .
224 # This repo's upstream is https://alexschroeder.ch/cgit/diaspy which is
225 # recommended in the install instructions here:
226 # https://alexschroeder.ch/cgit/jan-pona-mute/about/
228 python3
-m virtualenv
-p python3 venv
229 source venv
/bin
/activate
230 python3
-m pip
install -r requirements.txt
231 python3
-m pip
install -e .
237 python3
-m virtualenv
-p python3 venv
238 source venv
/bin
/activate
239 # pip freeze after a pip install.
240 cat >requirements.txt
<<'EOF'
241 beautifulsoup4==4.8.2
252 python3
-m pip
install -r requirements.txt
256 if [[ ! -s ~
/.config
/jan-pona-mute
/login
]]; then
257 mkdir ~
/.config
/jan-pona-mute
258 account
=fsf@framasphere.org
259 read -r -p "enter the password for $account > " pass
260 # background: format for this found using the save command
261 cat >~
/.config
/jan-pona-mute
/login
<<EOF
268 for account
in dbd fsf
; do
269 if [[ ! -s ~
/.rainbow_oauth-
$account ]]; then
270 printf "$(tput setaf 5)█$(tput sgr0)%.0s" $
(eval echo "{1..${COLUMNS:-60}}");
271 echo "Please login to $account on twitter in your main browser then press enter. After rainbowstream prompt loads, quit with command q"
275 if [[ ! -s ~
/.gnusocial_login-
$account ]]; then
276 printf "$(tput setaf 5)█$(tput sgr0)%.0s" $
(eval echo "{1..${COLUMNS:-60}}");
277 read -r -p "please enter the password for $account@status.fsf.org > " pass
278 touch ~
/.gnusocial_login-
$account
279 chmod 600 ~
/.gnusocial_login-
$account
280 printf "%s\n" "$pass" > ~
/.gnusocial_login-
$account
284 for account
in ${mastodon_accounts[@]}; do
285 if ! toot activate
$account@hostux.social
&>/dev
/null
; then
286 printf "$(tput setaf 5)█$(tput sgr0)%.0s" $
(eval echo "{1..${COLUMNS:-60}}");
287 echo "Please login to $account on https://hostux.social in your main browser then press enter."
289 toot login
-i hostux.social