Instagram → Fediverse bot
How to cross-post from Instagram to Pixelfed or Mastodon
These instructions are for Debian-based Linux (including Ubuntu & Mint).
You will need an account at Instagram to access their API.
1. Obtaining the code
Open a terminal.
Install the Python programming language & the pip package manager:
sudo apt install python3-pip
Get the code by cloning https://github.com/Horhik/Instagram2Fedi
Install the dependencies listed in the requirements file:
cd Instagram2Fedi
pip install -r requirements.txt
2. Running the bot
The bot will be permanently active once you start it.
So, instead of creating a cron job, I have wrapped the commands into a bash script and am running it as a systemd service.
Create a script file called insta2fedi.sh, then edit the file and paste in the code, adapting to your configuration:
#!/bin/bash
sleep 1s
pushd /path/to/Instagram2Fedi/
# Unit: seconds
declare -i CHECK_INTERVAL=60*15
declare -i POST_INTERVAL=60*5
INSTA_AUTH_USER=<insta_username>
INSTA_AUTH_PASSWORD=<insta_password>
# Token from <pixelfed_server>/settings/developers
TOKEN=<pixelfed_API_token>
# If you are poshing to Mastodon, use --use-mastodon 4 for the media limit
./insta2fedi --use-docker false --instagram-user <insta_username_to_be_fetched> \
--instance <pixelfed_server> --token ${TOKEN} \
--user-name $INSTA_AUTH_USER --user-password $INSTA_AUTH_PASSWORD \
--use-mastodon 0 --fetch-count 3 --carousel-limit 20 \
--check-interval $CHECK_INTERVAL --post-interval $POST_INTERVAL &
popd
# keep the systemd service running so that python scripts won't be killed
while true
do
sleep 1h
done
3. Automated startup
This is how you build the systemd service:
sudo <editor> /etc/systemd/system/insta2fedi.service
Paste this code into the editor, adapting the path to the script according to where you put it:
[Unit]Wants=network.target
After=syslog.target network-online.target
[Service]Type=simple
ExecStart=/path/to/script/insta2fedi.sh
KillMode=mixed
[Install]WantedBy=multi-user.target
Save it. Now adapt the access permissions for the service and the script in the terminal:
sudo chmod 640 /etc/systemd/system/insta2fedi.service
sudo chmod 744 ./insta2fedi.sh
Load the new service configuration into systemd:
sudo systemctl daemon-reload
You should call this every time you make any changes.
You can inspect, start and stop the service with the following commands:
systemctl status insta2fedi.service
sudo systemctl start insta2fedi.service
sudo systemctl stop insta2fedi.service
Once you are happy with the results, you can set it to load automatically on system start:
sudo systemctl enable insta2fedi.service
More information about systemd services:
https://www.howtogeek.com/687970/how-to-run-a-linux-program-at-startup-with-systemd/
https://forums.linuxmint.com/viewtopic.php?t=275464
These instructions are for Debian-based Linux (including Ubuntu & Mint).
You will need an account at Instagram to access their API.
1. Obtaining the code
Open a terminal.
Install the Python programming language & the pip package manager:
sudo apt install python3-pip
Get the code by cloning https://github.com/Horhik/Instagram2Fedi
Install the dependencies listed in the requirements file:
cd Instagram2Fedi
pip install -r requirements.txt
2. Running the bot
The bot will be permanently active once you start it.
So, instead of creating a cron job, I have wrapped the commands into a bash script and am running it as a systemd service.
Create a script file called insta2fedi.sh, then edit the file and paste in the code, adapting to your configuration:
#!/bin/bash
sleep 1s
pushd /path/to/Instagram2Fedi/
# Unit: seconds
declare -i CHECK_INTERVAL=60*15
declare -i POST_INTERVAL=60*5
INSTA_AUTH_USER=<insta_username>
INSTA_AUTH_PASSWORD=<insta_password>
# Token from <pixelfed_server>/settings/developers
TOKEN=<pixelfed_API_token>
# If you are poshing to Mastodon, use --use-mastodon 4 for the media limit
./insta2fedi --use-docker false --instagram-user <insta_username_to_be_fetched> \
--instance <pixelfed_server> --token ${TOKEN} \
--user-name $INSTA_AUTH_USER --user-password $INSTA_AUTH_PASSWORD \
--use-mastodon 0 --fetch-count 3 --carousel-limit 20 \
--check-interval $CHECK_INTERVAL --post-interval $POST_INTERVAL &
popd
# keep the systemd service running so that python scripts won't be killed
while true
do
sleep 1h
done
3. Automated startup
This is how you build the systemd service:
sudo <editor> /etc/systemd/system/insta2fedi.service
Paste this code into the editor, adapting the path to the script according to where you put it:
[Unit]Wants=network.target
After=syslog.target network-online.target
[Service]Type=simple
ExecStart=/path/to/script/insta2fedi.sh
KillMode=mixed
[Install]WantedBy=multi-user.target
Save it. Now adapt the access permissions for the service and the script in the terminal:
sudo chmod 640 /etc/systemd/system/insta2fedi.service
sudo chmod 744 ./insta2fedi.sh
Load the new service configuration into systemd:
sudo systemctl daemon-reload
You should call this every time you make any changes.
You can inspect, start and stop the service with the following commands:
systemctl status insta2fedi.service
sudo systemctl start insta2fedi.service
sudo systemctl stop insta2fedi.service
Once you are happy with the results, you can set it to load automatically on system start:
sudo systemctl enable insta2fedi.service
More information about systemd services:
https://www.howtogeek.com/687970/how-to-run-a-linux-program-at-startup-with-systemd/
https://forums.linuxmint.com/viewtopic.php?t=275464
teilten dies erneut