mirror of
https://github.com/Horhik/Instagram2Fedi.git
synced 2024-11-21 16:11:26 +00:00
Add instagram authorization
This commit is contained in:
parent
ae9afdbc3e
commit
c388f6096a
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,6 +2,7 @@
|
|||
already_posted.txt
|
||||
src/__pycache__/
|
||||
.venv
|
||||
.venv/
|
||||
.env.sh
|
||||
docker-compose.yml
|
||||
docker-compose.yaml
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
FROM python:3.9
|
||||
|
||||
RUN pip install instaloader
|
||||
RUN pip install Mastodon.py
|
||||
RUN pip install colorama
|
||||
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
ENV USE_DOCKER=1
|
||||
ENV YOUR_CONTAINER_NAME="$YOUR_CONTAINER_NAME"
|
||||
ENV I2M_INSTAGRAM_USER="$I2M_INSTAGRAM_USER"
|
||||
|
|
13
Docs.md
13
Docs.md
|
@ -3,6 +3,7 @@
|
|||
## How to use
|
||||
You can use Instagram2Fedi via docker or just like a python script
|
||||
|
||||
** 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`
|
||||
|
@ -17,7 +18,7 @@ Specify your arguments. You should use `--use-docker 0`.
|
|||
|
||||
For example:
|
||||
``` bash
|
||||
./insta2fedi --use-docker false --instagram-user <instagram username> --instance <instance domain> --token <OAuth token> --check-interval 10 --post-interval 10 --use-mastodon 4
|
||||
./insta2fedi --use-docker false --instagram-user <instagram username> --instance <instance domain> --token <OAuth token> --check-interval 10 --post-interval 10 --use-mastodon 4 --user-name <admin> --user-password <admin>
|
||||
# will check for new post each 10 seconds
|
||||
```
|
||||
|
||||
|
@ -33,7 +34,15 @@ For example, default maximum photo count in mastodon is `4`
|
|||
|
||||
---
|
||||
|
||||
`--instagram-user` - Your instagram user name.
|
||||
`--instagram-user` - Your fetched instagram account user name.
|
||||
|
||||
---
|
||||
|
||||
`--user-name` - Your instagram user name.
|
||||
|
||||
---
|
||||
|
||||
`--user-password` - Your instagram password.
|
||||
|
||||
---
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ See [Docs.md](./Docs.md)
|
|||
## Using docker-compose
|
||||
|
||||
1. create `docker-compose.yaml` with following content
|
||||
_You can use default.docker-compose.yaml from repo_
|
||||
``` yaml
|
||||
version: '3'
|
||||
services:
|
||||
|
@ -24,8 +25,12 @@ services:
|
|||
- I2M_POST_INTERVAL=3600 #1 hour
|
||||
- I2M_USE_MASTODON=4 #max carouse - is 4, if there's no limit set to -1
|
||||
- I2M_FETCH_COUNT=5 # how many instagram posts to fetch per check_interval -
|
||||
- I2M_USER_NAME=admin # Your instagram login name
|
||||
- I2M_USER_PASSWORD=admin # Your instagram password
|
||||
```
|
||||
|
||||
** 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_
|
||||
|
||||
2. And edit environment variables
|
||||
|
||||
3. Run `docker-compose up -d`
|
||||
|
|
17
default.docker-compose.yaml
Normal file
17
default.docker-compose.yaml
Normal file
|
@ -0,0 +1,17 @@
|
|||
version: '3'
|
||||
services:
|
||||
bot:
|
||||
build:
|
||||
context: .
|
||||
#image: "horhik/instagram2fedi:latest"
|
||||
environment:
|
||||
- YOUR_CONTAINER_NAME=instagram2fedi
|
||||
- I2M_INSTAGRAM_USER= #<fetched instagram user name>
|
||||
- I2M_INSTANCE= #<Mastodon or pixelfed instance>
|
||||
- I2M_TOKEN= # SECRET TOKEN
|
||||
- I2M_CHECK_INTERVAL=3600 #1 hour
|
||||
- I2M_POST_INTERVAL=3600 #1 hour
|
||||
- I2M_USE_MASTODON=4 #max carouse - is 4, if there's no limit set to -1
|
||||
- I2M_FETCH_COUNT=5 # how many instagram posts to fetch per check_interval -
|
||||
- I2M_USER_NAME= # Your instagram login name
|
||||
- I2M_USER_PASSWORD= # Your instagram password
|
|
@ -1,16 +0,0 @@
|
|||
version: '3'
|
||||
services:
|
||||
bot:
|
||||
build:
|
||||
context: .
|
||||
image: "horhik/instagram2fedi:latest"
|
||||
environment:
|
||||
- YOUR_CONTAINER_NAME=<whatever>
|
||||
- I2M_INSTAGRAM_USER=<instgram username>
|
||||
- I2M_INSTANCE=<mastodon or pixelfed instance>
|
||||
- I2M_TOKEN=<your token here>
|
||||
- I2M_CHECK_INTERVAL=3600 #1 hour
|
||||
- I2M_POST_INTERVAL=3600 #1 hour
|
||||
- I2M_USE_MASTODON=4 #max carouse - is 4, if there's no limit set to -1
|
||||
- I2M_FETCH_COUNT=5 # how many instagram posts to fetch per check_interval -
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
blurhash==1.1.4
|
||||
certifi==2021.10.8
|
||||
charset-normalizer==2.0.7
|
||||
colorama==0.4.4
|
||||
decorator==5.1.0
|
||||
certifi==2022.6.15
|
||||
charset-normalizer==2.1.0
|
||||
colorama==0.4.5
|
||||
decorator==5.1.1
|
||||
idna==3.3
|
||||
instaloader==4.8.1
|
||||
instaloader==4.9.3
|
||||
Mastodon.py==1.5.1
|
||||
python-dateutil==2.8.2
|
||||
python-magic==0.4.24
|
||||
pytz==2021.3
|
||||
requests==2.26.0
|
||||
python-magic==0.4.27
|
||||
pytz==2022.1
|
||||
requests==2.28.1
|
||||
six==1.16.0
|
||||
urllib3==1.26.7
|
||||
urllib3==1.26.11
|
||||
|
|
|
@ -5,6 +5,8 @@ from colorama import Fore, Back, Style
|
|||
|
||||
|
||||
instagram_user = os.environ.get("I2M_INSTAGRAM_USER")
|
||||
user_name = os.environ.get("I2M_USER_NAME")
|
||||
user_password = os.environ.get("I2M_USER_PASSWORD")
|
||||
instance = os.environ.get("I2M_INSTANCE")
|
||||
token = os.environ.get("I2M_TOKEN")
|
||||
check_interval = os.environ.get("I2M_CHECK_INTERVAL") #1 hour
|
||||
|
@ -18,6 +20,9 @@ print(check_interval)
|
|||
print(post_interval)
|
||||
print(use_mastodon)
|
||||
print(fetch_count)
|
||||
print(user_name)
|
||||
print(user_password)
|
||||
|
||||
|
||||
def flags(args, defaults):
|
||||
count = 1
|
||||
|
@ -43,6 +48,10 @@ def flags(args, defaults):
|
|||
defaults["carousel-limit"] = int(args[count + 1])
|
||||
elif (args[count] == "--use-docker"):
|
||||
defaults["use-docker"] = args[count + 1]
|
||||
elif (args[count] == "--user-name"):
|
||||
defaults["user-name"] = args[count + 1]
|
||||
elif (args[count] == "--user-password"):
|
||||
defaults["user-password"] = args[count + 1]
|
||||
|
||||
else:
|
||||
print(Fore.RED + '❗ -> Wrong Argument Name!...')
|
||||
|
@ -52,17 +61,27 @@ def flags(args, defaults):
|
|||
count +=2
|
||||
return defaults
|
||||
|
||||
def check_defaults(arg):
|
||||
return arg if arg != '' and arg else None
|
||||
|
||||
def process_arguments(args, defaults):
|
||||
defaults["instance"] = instance if instance !='' and instance else None
|
||||
defaults["instagram-user"] = instagram_user if instagram_user != '' and instagram_user else None
|
||||
# Users login and password
|
||||
defaults["user-name"] = check_defaults(user_name)
|
||||
defaults["user-password"] = check_defaults(user_password)
|
||||
defaults["token"] = token if token != '' and token else None
|
||||
defaults["check-interval"] = int(check_interval) if check_interval != '' and check_interval else None
|
||||
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["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())
|
||||
|
||||
|
||||
# Command line arguments more prioritized, if smth has been written in .env and in cmd args, then Instagram2Fedi will take values from `cmd args`
|
||||
new_defaults = flags(args, defaults)
|
||||
return new_defaults
|
||||
|
||||
|
|
13
src/main.py
13
src/main.py
|
@ -18,10 +18,12 @@ print(sys.argv)
|
|||
print("ARGUMENTS")
|
||||
default_settings = {
|
||||
"instance": None,
|
||||
"instagram-user": None,
|
||||
"instagram-user": None,
|
||||
"user-name": "",
|
||||
"user-password": None,
|
||||
"token": None,
|
||||
"check-interval": 3600,
|
||||
"post-interval": 3600,
|
||||
"post-interval": 3600,
|
||||
"fetch-count" : 10,
|
||||
"carousel-limit": 4,
|
||||
}
|
||||
|
@ -51,7 +53,10 @@ post_interval = settings["post-interval"]#1m
|
|||
using_mastodon = settings["carousel-limit"] > 0;
|
||||
mastodon_carousel_size = settings["carousel-limit"]
|
||||
|
||||
|
||||
user = {
|
||||
"name": settings["user-name"],
|
||||
"password": settings["user-password"]
|
||||
}
|
||||
|
||||
print(Fore.GREEN + '🚀 > Connecting to Mastodon/Pixelfed...')
|
||||
print(Style.RESET_ALL)
|
||||
|
@ -62,5 +67,5 @@ mastodon = Mastodon(
|
|||
# api_base_url = 'https://pixelfed.tokyo/'
|
||||
)
|
||||
while True:
|
||||
get_new_posts(mastodon, mastodon_carousel_size, post_limit, id_filename, using_mastodon, mastodon_carousel_size, post_interval, fetched_user)
|
||||
get_new_posts(mastodon, mastodon_carousel_size, post_limit, id_filename, using_mastodon, mastodon_carousel_size, post_interval, fetched_user, user)
|
||||
time.sleep(time_interval_sec)
|
||||
|
|
|
@ -8,14 +8,15 @@ from converters import split_array, try_to_get_carousel
|
|||
import hashlib
|
||||
from instaloader import Profile, Instaloader, LatestStamps
|
||||
|
||||
def get_instagram_user(user):
|
||||
def get_instagram_user(user, fetched_user):
|
||||
L = Instaloader()
|
||||
|
||||
print(Fore.GREEN + '🚀 > Connecting to Instagram...')
|
||||
print(Fore.GREEN + 'TEST 🚀 > Connecting to Instagram...')
|
||||
print(Style.RESET_ALL)
|
||||
print(datetime.datetime.now())
|
||||
|
||||
return Profile.from_username(L.context, user)
|
||||
print("USER USER USER!!!!!!!!!!!!!1", user)
|
||||
L.login(user["name"], user["password"])
|
||||
return Profile.from_username(L.context, fetched_user)
|
||||
|
||||
def get_image(url):
|
||||
try:
|
||||
|
@ -72,9 +73,9 @@ def toot(urls, title, mastodon, fetched_user ):
|
|||
print(Style.RESET_ALL)
|
||||
print(datetime.datetime.now())
|
||||
|
||||
def get_new_posts(mastodon, mastodon_carousel_size, post_limit, already_posted_path, using_mastodon, carousel_size, post_interval, fetched_user):
|
||||
def get_new_posts(mastodon, mastodon_carousel_size, post_limit, already_posted_path, using_mastodon, carousel_size, post_interval, fetched_user, user):
|
||||
# fetching user profile to get new posts
|
||||
profile = get_instagram_user(fetched_user)
|
||||
profile = get_instagram_user(user, fetched_user)
|
||||
# get list of all posts
|
||||
posts = profile.get_posts()
|
||||
stupidcounter = 0
|
||||
|
|
Loading…
Reference in a new issue