commit
80852374d3
|
@ -7,7 +7,7 @@ name: Docker
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "main" ]
|
branches: [ "*" ]
|
||||||
# Publish semver tags as releases.
|
# Publish semver tags as releases.
|
||||||
tags: [ 'v*.*.*' ]
|
tags: [ 'v*.*.*' ]
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
|
@ -4,5 +4,6 @@ src/__pycache__/
|
||||||
.venv
|
.venv
|
||||||
.venv/
|
.venv/
|
||||||
.env.sh
|
.env.sh
|
||||||
|
run.sh
|
||||||
docker-compose.yml
|
docker-compose.yml
|
||||||
docker-compose.yaml
|
docker-compose.yaml
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FROM python:3.9
|
FROM python:3.11
|
||||||
|
|
||||||
|
|
||||||
COPY . /app
|
COPY . /app
|
||||||
|
|
|
@ -4,7 +4,7 @@ charset-normalizer==2.1.0
|
||||||
colorama==0.4.5
|
colorama==0.4.5
|
||||||
decorator==5.1.1
|
decorator==5.1.1
|
||||||
idna==3.3
|
idna==3.3
|
||||||
instaloader==4.9.3
|
instaloader==4.9.6
|
||||||
Mastodon.py==1.5.1
|
Mastodon.py==1.5.1
|
||||||
python-dateutil==2.8.2
|
python-dateutil==2.8.2
|
||||||
python-magic==0.4.27
|
python-magic==0.4.27
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import os
|
||||||
def already_posted(id, path):
|
def already_posted(id, path):
|
||||||
|
print("Checking if posted " + id)
|
||||||
|
res = os.listdir("/data")
|
||||||
|
print(res)
|
||||||
with open(path) as file:
|
with open(path) as file:
|
||||||
content = file.read().split("\n")
|
content = file.read().split("\n")
|
||||||
|
print(content)
|
||||||
sha1 = hashlib.sha1(bytes(id, "utf-8")).hexdigest()
|
sha1 = hashlib.sha1(bytes(id, "utf-8")).hexdigest()
|
||||||
if sha1 in content:
|
if sha1 in content:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def mark_as_posted(id, path):
|
def mark_as_posted(id, path):
|
||||||
|
print("Adding " + id + " " + path)
|
||||||
with open(path, 'a') as file:
|
with open(path, 'a') as file:
|
||||||
sha1 = hashlib.sha1(bytes(id, "utf-8")).hexdigest()
|
sha1 = hashlib.sha1(bytes(id, "utf-8")).hexdigest()
|
||||||
file.write(sha1+'\n')
|
file.write(sha1+'\n')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ def split_array(arr, size):
|
||||||
|
|
||||||
def try_to_get_carousel(array, post):
|
def try_to_get_carousel(array, post):
|
||||||
try:
|
try:
|
||||||
|
print("Looking for carousel in " + str(post))
|
||||||
node = vars(post)['_node']
|
node = vars(post)['_node']
|
||||||
if 'edge_sidecar_to_children' in node:
|
if 'edge_sidecar_to_children' in node:
|
||||||
try:
|
try:
|
||||||
|
|
13
src/main.py
13
src/main.py
|
@ -37,13 +37,18 @@ if verbose:
|
||||||
print('SETTINGS' , settings)
|
print('SETTINGS' , settings)
|
||||||
|
|
||||||
agree = [1, True, "true", "True", "yes", "Yes"]
|
agree = [1, True, "true", "True", "yes", "Yes"]
|
||||||
if (os.environ.get("USE_DOCKER")):
|
|
||||||
id_filename = "/app/already_posted.txt"
|
if (os.environ.get("USE_KUBERNETES")):
|
||||||
elif (os.environ.get("USE_KUBERNETES")):
|
|
||||||
id_filename = "/data/already_posted.txt"
|
id_filename = "/data/already_posted.txt"
|
||||||
|
id_session = "/data/session"
|
||||||
|
elif (os.environ.get("USE_DOCKER")):
|
||||||
|
id_filename = "/app/already_posted.txt"
|
||||||
|
id_session = "/app/session"
|
||||||
else:
|
else:
|
||||||
id_filename = "./already_posted.txt"
|
id_filename = "./already_posted.txt"
|
||||||
|
id_session = "./session"
|
||||||
|
|
||||||
|
print(id_filename)
|
||||||
|
|
||||||
with open(id_filename, "a") as f:
|
with open(id_filename, "a") as f:
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
|
@ -75,7 +80,7 @@ mastodon = Mastodon(
|
||||||
# api_base_url = 'https://pixelfed.tokyo/'
|
# api_base_url = 'https://pixelfed.tokyo/'
|
||||||
)
|
)
|
||||||
while True:
|
while True:
|
||||||
get_new_posts(mastodon, mastodon_carousel_size, post_limit, id_filename, using_mastodon, mastodon_carousel_size, post_interval, fetched_user, user)
|
get_new_posts(mastodon, mastodon_carousel_size, post_limit, id_filename, using_mastodon, mastodon_carousel_size, post_interval, fetched_user, user, id_session)
|
||||||
if scheduled:
|
if scheduled:
|
||||||
break
|
break
|
||||||
time.sleep(time_interval_sec)
|
time.sleep(time_interval_sec)
|
||||||
|
|
|
@ -6,18 +6,21 @@ import datetime
|
||||||
from already_posted import already_posted, mark_as_posted
|
from already_posted import already_posted, mark_as_posted
|
||||||
from converters import split_array, try_to_get_carousel
|
from converters import split_array, try_to_get_carousel
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import os
|
||||||
from instaloader import Profile, Instaloader, LatestStamps
|
from instaloader import Profile, Instaloader, LatestStamps
|
||||||
|
|
||||||
def get_instagram_user(user, fetched_user):
|
def get_instagram_user(user, fetched_user, id_session):
|
||||||
L = Instaloader()
|
L = Instaloader()
|
||||||
|
|
||||||
print(Fore.GREEN + 'TEST 🚀 > Connecting to Instagram...')
|
print(Fore.GREEN + 'TEST 🚀 > Connecting to Instagram...')
|
||||||
print(Style.RESET_ALL)
|
print(Style.RESET_ALL)
|
||||||
print(datetime.datetime.now())
|
print(datetime.datetime.now())
|
||||||
|
if os.path.exists(id_session):
|
||||||
|
L.load_session_from_file(user["name"], id_session)
|
||||||
if user["name"] != None:
|
if user["name"] != None:
|
||||||
print("USER USER USER!!!!!!!!!!!!!", user["name"])
|
print("USER USER USER!!!!!!!!!!!!!", user["name"])
|
||||||
L.login(user["name"], user["password"])
|
L.login(user["name"], user["password"])
|
||||||
|
L.save_session_to_file(id_session)
|
||||||
return Profile.from_username(L.context, fetched_user)
|
return Profile.from_username(L.context, fetched_user)
|
||||||
|
|
||||||
def get_image(url):
|
def get_image(url):
|
||||||
|
@ -75,9 +78,9 @@ def toot(urls, title, mastodon, fetched_user ):
|
||||||
print(Style.RESET_ALL)
|
print(Style.RESET_ALL)
|
||||||
print(datetime.datetime.now())
|
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, user):
|
def get_new_posts(mastodon, mastodon_carousel_size, post_limit, already_posted_path, using_mastodon, carousel_size, post_interval, fetched_user, user, id_session):
|
||||||
# fetching user profile to get new posts
|
# fetching user profile to get new posts
|
||||||
profile = get_instagram_user(user, fetched_user)
|
profile = get_instagram_user(user, fetched_user, id_session)
|
||||||
# get list of all posts
|
# get list of all posts
|
||||||
posts = profile.get_posts()
|
posts = profile.get_posts()
|
||||||
stupidcounter = 0
|
stupidcounter = 0
|
||||||
|
|
Loading…
Reference in New Issue