2021-11-14 19:47:34 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2021-08-31 14:03:06 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2021-08-31 20:44:43 +00:00
|
|
|
import time
|
2021-11-14 20:24:59 +00:00
|
|
|
import datetime
|
2021-09-05 14:08:50 +00:00
|
|
|
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
|
2021-09-05 14:08:50 +00:00
|
|
|
from instaloader import Profile, Instaloader, LatestStamps
|
2021-11-11 11:51:48 +00:00
|
|
|
from arguments import process_arguments
|
|
|
|
|
2021-08-31 14:03:06 +00:00
|
|
|
|
2021-09-07 08:44:47 +00:00
|
|
|
from network import get_new_posts
|
|
|
|
|
2021-11-11 11:51:48 +00:00
|
|
|
|
2021-08-31 14:03:06 +00:00
|
|
|
|
2021-11-11 11:51:48 +00:00
|
|
|
print(sys.argv)
|
|
|
|
print("ARGUMENTS")
|
|
|
|
default_settings = {
|
|
|
|
"instance": None,
|
|
|
|
"instagram-user": None,
|
|
|
|
"token": None,
|
|
|
|
"check-interval": 3600,
|
|
|
|
"post-interval": 3600,
|
|
|
|
"fetch-count" : 10,
|
2021-11-14 19:47:34 +00:00
|
|
|
"carousel-limit": 4,
|
|
|
|
"use-docker": True
|
2021-11-11 11:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
settings = process_arguments(sys.argv, default_settings)
|
|
|
|
|
|
|
|
print(settings)
|
|
|
|
|
2021-11-14 19:47:34 +00:00
|
|
|
agree = [1, True, "true", "True", "yes", "Yes"]
|
|
|
|
if (agree.count(settings["use-docker"])):
|
|
|
|
id_filename = "/app/already_posted.txt"
|
|
|
|
else:
|
|
|
|
id_filename = "./already_posted.txt"
|
|
|
|
|
|
|
|
|
|
|
|
with open(id_filename, "a") as f:
|
|
|
|
f.write("\n")
|
|
|
|
|
2021-11-11 11:51:48 +00:00
|
|
|
fetched_user = settings["instagram-user"]
|
|
|
|
mastodon_instance = settings["instance"]
|
|
|
|
mastodon_token = settings["token"]
|
2021-08-31 14:03:06 +00:00
|
|
|
|
2021-11-11 11:51:48 +00:00
|
|
|
post_limit = settings["fetch-count"]
|
|
|
|
time_interval_sec = settings["check-interval"] #1d
|
|
|
|
post_interval = settings["post-interval"]#1m
|
2021-09-06 07:02:50 +00:00
|
|
|
|
2021-11-11 11:51:48 +00:00
|
|
|
using_mastodon = settings["carousel-limit"] > 0;
|
|
|
|
mastodon_carousel_size = settings["carousel-limit"]
|
2021-09-06 07:02:50 +00:00
|
|
|
|
2021-08-31 20:35:05 +00:00
|
|
|
|
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-11-14 20:24:59 +00:00
|
|
|
print(datetime.datetime.now())
|
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-11-20 09:18:58 +00:00
|
|
|
get_new_posts(mastodon, 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)
|