mirror of
https://github.com/Horhik/Instagram2Fedi.git
synced 2024-11-22 00:11:26 +00:00
Compare commits
No commits in common. "f5cceda106b8abeab0e6b9c9c77f5f5fc82afb83" and "2db531d2aa53c1abf323eb38896977ef70935aab" have entirely different histories.
f5cceda106
...
2db531d2aa
10
Docs.md
10
Docs.md
|
@ -3,7 +3,7 @@
|
|||
## How to use
|
||||
You can use Instagram2Fedi via docker or just like a python script
|
||||
|
||||
** Note: ** _Credentials can be complicated. Running without Instagram credentials (`user-name` and `user-password`) appears to work for a short period of time but will, eventually, fail. Providing credentials will work unless Instagram issues a challenge. Recommend leaving `user-name` blank if running as a scheduled job (`--scheduled`) and providing them otherwise._
|
||||
** Note: ** _Since somewhen it's seems not possible to fetch any data from instagram anonymously (maybe i'm wrong and there's a solution, I'll be very happy to know about it). Due that you unfortunately have to had an instagram accound and provide login and password to this script_
|
||||
### With Docker 🐋
|
||||
|
||||
Specify your variables in `./env.sh` and then run `./run.sh`
|
||||
|
@ -66,14 +66,6 @@ If theres more than one new post, sets with which time interval should it post t
|
|||
|
||||
`--use-docker` - If you're running it via docker container, set to `1` or `True`
|
||||
|
||||
---
|
||||
|
||||
`--scheduled` - If set, Instagram2Fedi runs once instead of sleeping for `check-interval` and running forever. This is intended for use as a `cron` job. No additional parameter is needed, just add `--scheduled`.
|
||||
|
||||
---
|
||||
|
||||
`--verbose` - If set, output all logs including secrets. No additional parameter is needed, just add `--scheduled`.
|
||||
|
||||
|
||||
## Default values ⚙
|
||||
Default values are:
|
||||
|
|
|
@ -11,30 +11,17 @@ instance = os.environ.get("I2M_INSTANCE")
|
|||
token = os.environ.get("I2M_TOKEN")
|
||||
check_interval = os.environ.get("I2M_CHECK_INTERVAL") #1 hour
|
||||
post_interval = os.environ.get("I2M_POST_INTERVAL") #1 hour
|
||||
use_mastodon = os.environ.get("I2M_USE_MASTODON") #max carousel is 4, if there's no limit set to -1
|
||||
use_mastodon = os.environ.get("I2M_USE_MASTODON") #max carouse is 4, if there's no limit set to -1
|
||||
fetch_count = os.environ.get("I2M_FETCH_COUNT") # how many instagram posts to fetch per check_interval
|
||||
if os.environ.get("I2M_SCHEDULED") == "True":
|
||||
scheduled_run = True # run continuously (if False) or a single time (if True)
|
||||
else:
|
||||
scheduled_run = False
|
||||
if os.environ.get("I2M_VERBOSE") == "True": # verbose output
|
||||
verbose_output = True
|
||||
else:
|
||||
verbose_output = False
|
||||
|
||||
if verbose_output:
|
||||
print('instagram', instagram_user)
|
||||
print('instagram', instance)
|
||||
print(token)
|
||||
print(check_interval)
|
||||
print(post_interval)
|
||||
print(use_mastodon)
|
||||
print(fetch_count)
|
||||
print(user_name)
|
||||
print(user_password)
|
||||
print(scheduled_run)
|
||||
print(verbose_output)
|
||||
|
||||
print('instagram', instagram_user)
|
||||
print('instagram', instance)
|
||||
print(token)
|
||||
print(check_interval)
|
||||
print(post_interval)
|
||||
print(use_mastodon)
|
||||
print(fetch_count)
|
||||
print(user_name)
|
||||
print(user_password)
|
||||
|
||||
|
||||
def flags(args, defaults):
|
||||
|
@ -65,12 +52,6 @@ def flags(args, defaults):
|
|||
defaults["user-name"] = args[count + 1]
|
||||
elif (args[count] == "--user-password"):
|
||||
defaults["user-password"] = args[count + 1]
|
||||
elif (args[count] == "--scheduled"):
|
||||
defaults["scheduled"] = True
|
||||
count -= 1
|
||||
elif (args[count] == "--verbose"):
|
||||
defaults["verbose"] = True
|
||||
count -= 1
|
||||
|
||||
else:
|
||||
print(Fore.RED + '❗ -> Wrong Argument Name!...')
|
||||
|
@ -94,8 +75,7 @@ def process_arguments(args, defaults):
|
|||
defaults["post-interval"] = int(post_interval) if post_interval != '' and post_interval else None
|
||||
defaults["fetch-count"] = int(fetch_count) if fetch_count != '' and fetch_count else None
|
||||
defaults["carousel-limit"] = int(use_mastodon) if use_mastodon != '' and use_mastodon else None
|
||||
defaults["scheduled"] = bool(scheduled_run) if scheduled_run else False
|
||||
defaults["verbose"] = bool(verbose_output) if verbose_output else False
|
||||
defaults["carousel-limit"] = int(use_mastodon) if use_mastodon != '' and use_mastodon else None
|
||||
#print(Fore.RED + '❗ -> Missing Argument ')
|
||||
#print(Style.RESET_ALL)
|
||||
#print(datetime.datetime.now())
|
||||
|
|
20
src/main.py
20
src/main.py
|
@ -13,6 +13,9 @@ from arguments import process_arguments
|
|||
from network import get_new_posts
|
||||
|
||||
|
||||
|
||||
print(sys.argv)
|
||||
print("ARGUMENTS")
|
||||
default_settings = {
|
||||
"instance": None,
|
||||
"instagram-user": None,
|
||||
|
@ -20,27 +23,18 @@ default_settings = {
|
|||
"user-password": None,
|
||||
"token": None,
|
||||
"check-interval": 3600,
|
||||
"post-interval": 60,
|
||||
"post-interval": 3600,
|
||||
"fetch-count" : 10,
|
||||
"carousel-limit": 4,
|
||||
"scheduled": False,
|
||||
"verbose": False
|
||||
}
|
||||
|
||||
settings = process_arguments(sys.argv, default_settings)
|
||||
|
||||
verbose = settings["verbose"]
|
||||
|
||||
if verbose:
|
||||
print("ARGUMENTS")
|
||||
print(sys.argv)
|
||||
print('SETTINGS' , settings)
|
||||
print('SETTINGS' , settings)
|
||||
|
||||
agree = [1, True, "true", "True", "yes", "Yes"]
|
||||
if (os.environ.get("USE_DOCKER")):
|
||||
id_filename = "/app/already_posted.txt"
|
||||
elif (os.environ.get("USE_KUBERNETES")):
|
||||
id_filename = "/data/already_posted.txt"
|
||||
else:
|
||||
id_filename = "./already_posted.txt"
|
||||
|
||||
|
@ -58,8 +52,6 @@ post_interval = settings["post-interval"]#1m
|
|||
|
||||
using_mastodon = settings["carousel-limit"] > 0;
|
||||
mastodon_carousel_size = settings["carousel-limit"]
|
||||
scheduled = settings["scheduled"]
|
||||
|
||||
|
||||
user = {
|
||||
"name": settings["user-name"],
|
||||
|
@ -76,6 +68,4 @@ mastodon = Mastodon(
|
|||
)
|
||||
while True:
|
||||
get_new_posts(mastodon, mastodon_carousel_size, post_limit, id_filename, using_mastodon, mastodon_carousel_size, post_interval, fetched_user, user)
|
||||
if scheduled:
|
||||
break
|
||||
time.sleep(time_interval_sec)
|
||||
|
|
|
@ -14,10 +14,8 @@ def get_instagram_user(user, fetched_user):
|
|||
print(Fore.GREEN + 'TEST 🚀 > Connecting to Instagram...')
|
||||
print(Style.RESET_ALL)
|
||||
print(datetime.datetime.now())
|
||||
|
||||
if user["name"] != None:
|
||||
print("USER USER USER!!!!!!!!!!!!!", user["name"])
|
||||
L.login(user["name"], user["password"])
|
||||
print("USER USER USER!!!!!!!!!!!!!1", user)
|
||||
L.login(user["name"], user["password"])
|
||||
return Profile.from_username(L.context, fetched_user)
|
||||
|
||||
def get_image(url):
|
||||
|
@ -64,7 +62,7 @@ def toot(urls, title, mastodon, fetched_user ):
|
|||
ids = []
|
||||
for url in urls:
|
||||
ids.append(upload_image_to_mastodon(url, mastodon))
|
||||
post_text = str(title) + "\n" # creating post text
|
||||
post_text = str(title) + "\n" + "crossposted from https://instagram.com/"+fetched_user # creating post text
|
||||
post_text = post_text[0:1000]
|
||||
if(ids):
|
||||
print(ids)
|
||||
|
|
Loading…
Reference in a new issue