some updates

This commit is contained in:
horhik 2021-11-11 14:51:48 +03:00
parent eaadf55a02
commit 9ddfab49d4
4 changed files with 72 additions and 11 deletions

38
src/arguments.py Normal file
View File

@ -0,0 +1,38 @@
from colorama import Fore, Back, Style
def process_arguments(args, defaults):
count = 1
while (len(args) > count):
if(args[count] == "--instance"):
defaults["instance"] = args[count + 1]
elif (args[count] == "--instagram-user"):
defaults["instagram-user"] = args[count + 1]
elif (args[count] == "--token"):
defaults["token"] = args[count + 1]
elif (args[count] == "--check-interval"):
defaults["check-interval"] = args[count + 1]
elif (args[count] == "--post-interval"):
defaults["post-interval"] = args[count + 1]
elif (args[count] == "--fetch-count"):
defaults["fetch-count"] = args[count + 1]
elif (args[count] == "--using-mastodon"):
defaults["carousel-limit"] = int(args[count + 1])
else:
print(Fore.RED + '❗ -> Wrong Argument Name!...')
print(Style.RESET_ALL)
count +=2
return defaults
#fuck this shit im out''
#teenagers scare the living shit out of me
#deeeespaaaacito quero esperanto de despacito
#хорошо всё будет хорошо
#и камнем вниииз
#u kinda smell *smif* like a BAKA
#Yeren Yegaaaaaaa!!!!!!!!!

View File

@ -5,23 +5,42 @@ import json
from mastodon import Mastodon from mastodon import Mastodon
from colorama import Fore, Back, Style from colorama import Fore, Back, Style
from instaloader import Profile, Instaloader, LatestStamps from instaloader import Profile, Instaloader, LatestStamps
from arguments import process_arguments
from network import get_new_posts from network import get_new_posts
id_filename = "/app/already_posted.txt" id_filename = "/app/already_posted.txt"
with open(id_filename, "a") as f: with open(id_filename, "a") as f:
f.write("\n") f.write("\n")
fetched_user = sys.argv[1] print(sys.argv)
mastodon_instance = sys.argv[2] print("ARGUMENTS")
mastodon_token = sys.argv[3] default_settings = {
"instance": None,
"instagram-user": None,
"token": None,
"check-interval": 3600,
"post-interval": 3600,
"fetch-count" : 10,
"carousel-limit": 4
}
post_limit = 1 settings = process_arguments(sys.argv, default_settings)
time_interval_sec = 86400
post_interval = 10
using_mastodon = True; print(settings)
mastodon_carousel_size = 4
fetched_user = settings["instagram-user"]
mastodon_instance = settings["instance"]
mastodon_token = settings["token"]
post_limit = settings["fetch-count"]
time_interval_sec = settings["check-interval"] #1d
post_interval = settings["post-interval"]#1m
using_mastodon = settings["carousel-limit"] > 0;
mastodon_carousel_size = settings["carousel-limit"]
print(Fore.GREEN + '🚀 > Connecting to Instagram...') print(Fore.GREEN + '🚀 > Connecting to Instagram...')
print(Style.RESET_ALL) print(Style.RESET_ALL)

View File

@ -44,8 +44,9 @@ def toot(urls, title, mastodon, fetched_user ):
ids.append(upload_image_to_mastodon(url, mastodon)) ids.append(upload_image_to_mastodon(url, mastodon))
post_text = str(title) + "\n" + "crosposted from https://instagram.com/"+fetched_user # creating post text post_text = str(title) + "\n" + "crosposted from https://instagram.com/"+fetched_user # creating post text
post_text = post_text[0:1000] post_text = post_text[0:1000]
print(ids) if(ids):
mastodon.status_post(post_text, media_ids = ids) print(ids)
mastodon.status_post(post_text, media_ids = ids)
except Exception as e: except Exception as e:
print(Fore.RED + "😿 > Failed to create toot \n", e) print(Fore.RED + "😿 > Failed to create toot \n", e)
@ -69,7 +70,6 @@ def get_new_posts(mastodon, profile, mastodon_carousel_size, post_limit, already
toot(urls, post.caption, mastodon, fetched_user) toot(urls, post.caption, mastodon, fetched_user)
else: else:
toot(url_arr, post.caption, mastodon, fetched_user) toot(url_arr, post.caption, mastodon, fetched_user)
mark_as_posted(str(post.mediaid), already_posted_path) mark_as_posted(str(post.mediaid), already_posted_path)
time.sleep(post_interval) time.sleep(post_interval)
else: else:

4
src/requipments.txt Normal file
View File

@ -0,0 +1,4 @@
pyparsing==2.4.7
tqdm==4.62.2
urllib3==1.26.6
colorama==