Add both flags and environment variables support

This commit is contained in:
horhik 2022-04-13 23:11:54 +03:00
parent ff058ea7d8
commit 95e3f9d220
3 changed files with 38 additions and 9 deletions

8
env.sh
View file

@ -1,10 +1,10 @@
#!b/in/sh
# Required
export YOUR_CONTAINER_NAME=
export I2M_INSTAGRAM_USER=
export I2M_INSTANCE=
export I2M_TOKEN=
export YOUR_CONTAINER_NAME=kek
export I2M_INSTAGRAM_USER=kek
export I2M_INSTANCE=kek
export I2M_TOKEN=kek
export I2M_CHECK_INTERVAL=3600 #1 hour
export I2M_POST_INTERVAL=3600 #1 hour

2
run.sh
View file

@ -1,3 +1,3 @@
#!/bin/sh
source ./env.sh
docker build -t $YOUR_CONTAINER_NAME .; docker container run -it -v $(pwd):/app $YOUR_CONTAINER_NAME --use-docker 1 --instagram-user $I2M_INSTAGRAM_USER --instance $I2M_INSTANCE --token $I2M_TOKEN --check-interval $I2M_CHECK_INTERVAL --post-interval $I2M_POST_INTERVAL --fetch-count $I2M_FETCH_COUNT --use-mastodon $I2M_USE_MASTODON
docker build -t $YOUR_CONTAINER_NAME .; docker container run -it -v $(pwd):/app

View file

@ -19,9 +19,38 @@ print(post_interval)
print(use_mastodon)
print(fetch_count)
def exists(a):
return a != '' and a != False
def flags(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"] = int(args[count + 1])
elif (args[count] == "--post-interval"):
defaults["post-interval"] = int(args[count + 1])
elif (args[count] == "--fetch-count"):
defaults["fetch-count"] = int(args[count + 1])
elif (args[count] == "--use-mastodon"):
defaults["carousel-limit"] = int(args[count + 1])
elif (args[count] == "--use-docker"):
defaults["use-docker"] = args[count + 1]
else:
print(Fore.RED + '❗ -> Wrong Argument Name!...')
print(Style.RESET_ALL)
print(datetime.datetime.now())
count +=2
return defaults
def process_arguments(args, defaults):
defaults["instance"] = instance if instance !='' and instance else None
@ -34,6 +63,6 @@ def process_arguments(args, defaults):
#print(Fore.RED + '❗ -> Missing Argument ')
#print(Style.RESET_ALL)
#print(datetime.datetime.now())
print(defaults)
return defaults
new_defaults = flags(args, defaults)
return new_defaults