Instagram2Fedi/src/main.py

42 lines
1.1 KiB
Python
Raw Normal View History

2021-08-31 14:03:06 +00:00
import os
import sys
2021-08-31 20:44:43 +00:00
import time
import json
2021-08-31 14:03:06 +00:00
from mastodon import Mastodon
2021-08-31 15:47:21 +00:00
from colorama import Fore, Back, Style
from instaloader import Profile, Instaloader, LatestStamps
2021-08-31 14:03:06 +00:00
2021-09-07 08:44:47 +00:00
from network import get_new_posts
2021-08-31 14:45:42 +00:00
id_filename = "/app/already_posted.txt"
with open(id_filename, "a") as f:
f.write("\n")
2021-08-31 14:03:06 +00:00
fetched_user = sys.argv[1]
2021-08-31 20:57:31 +00:00
mastodon_instance = sys.argv[2]
mastodon_token = sys.argv[3]
2021-08-31 14:03:06 +00:00
post_limit = 1
time_interval_sec = 86400
post_interval = 10
using_mastodon = True;
mastodon_carousel_size = 4
2021-08-31 20:35:05 +00:00
print(Fore.GREEN + '🚀 > Connecting to Instagram...')
2021-08-31 15:47:21 +00:00
print(Style.RESET_ALL)
2021-08-31 20:35:05 +00:00
L = Instaloader()
profile = Profile.from_username(L.context, fetched_user)
2021-08-31 14:03:06 +00:00
2021-08-31 18:57:12 +00:00
print(Fore.GREEN + '🚀 > Connecting to Mastodon/Pixelfed...')
2021-08-31 15:47:21 +00:00
print(Style.RESET_ALL)
2021-08-31 14:03:06 +00:00
mastodon = Mastodon(
access_token = mastodon_token,
2021-08-31 20:57:31 +00:00
api_base_url = mastodon_instance
2021-08-31 18:57:12 +00:00
# api_base_url = 'https://pixelfed.tokyo/'
2021-08-31 14:03:06 +00:00
)
2021-08-31 20:50:06 +00:00
while True:
2021-09-07 08:44:47 +00:00
get_new_posts(mastodon, profile, mastodon_carousel_size, post_limit, id_filename, using_mastodon, mastodon_carousel_size, post_interval, fetched_user)
2021-09-01 04:14:05 +00:00
time.sleep(time_interval_sec)