Merge pull request #1 from neilcar/pvc-debug

Add session file to login
This commit is contained in:
neilcar 2023-05-29 09:06:00 -04:00 committed by GitHub
commit 80852374d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 28 additions and 11 deletions

View File

@ -7,7 +7,7 @@ name: Docker
on:
push:
branches: [ "main" ]
branches: [ "*" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:

1
.gitignore vendored
View File

@ -4,5 +4,6 @@ src/__pycache__/
.venv
.venv/
.env.sh
run.sh
docker-compose.yml
docker-compose.yaml

View File

@ -1,4 +1,4 @@
FROM python:3.9
FROM python:3.11
COPY . /app

View File

@ -4,7 +4,7 @@ charset-normalizer==2.1.0
colorama==0.4.5
decorator==5.1.1
idna==3.3
instaloader==4.9.3
instaloader==4.9.6
Mastodon.py==1.5.1
python-dateutil==2.8.2
python-magic==0.4.27

View File

@ -1,14 +1,21 @@
import hashlib
import os
def already_posted(id, path):
print("Checking if posted " + id)
res = os.listdir("/data")
print(res)
with open(path) as file:
content = file.read().split("\n")
print(content)
sha1 = hashlib.sha1(bytes(id, "utf-8")).hexdigest()
if sha1 in content:
return True
return False
def mark_as_posted(id, path):
print("Adding " + id + " " + path)
with open(path, 'a') as file:
sha1 = hashlib.sha1(bytes(id, "utf-8")).hexdigest()
file.write(sha1+'\n')

0
src/arguments.py Normal file → Executable file
View File

View File

@ -12,6 +12,7 @@ def split_array(arr, size):
def try_to_get_carousel(array, post):
try:
print("Looking for carousel in " + str(post))
node = vars(post)['_node']
if 'edge_sidecar_to_children' in node:
try:

View File

@ -37,13 +37,18 @@ if verbose:
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")):
if (os.environ.get("USE_KUBERNETES")):
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:
id_filename = "./already_posted.txt"
id_session = "./session"
print(id_filename)
with open(id_filename, "a") as f:
f.write("\n")
@ -75,7 +80,7 @@ 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, 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:
break
time.sleep(time_interval_sec)

View File

@ -6,18 +6,21 @@ import datetime
from already_posted import already_posted, mark_as_posted
from converters import split_array, try_to_get_carousel
import hashlib
import os
from instaloader import Profile, Instaloader, LatestStamps
def get_instagram_user(user, fetched_user):
def get_instagram_user(user, fetched_user, id_session):
L = Instaloader()
print(Fore.GREEN + 'TEST 🚀 > Connecting to Instagram...')
print(Style.RESET_ALL)
print(datetime.datetime.now())
if os.path.exists(id_session):
L.load_session_from_file(user["name"], id_session)
if user["name"] != None:
print("USER USER USER!!!!!!!!!!!!!", user["name"])
L.login(user["name"], user["password"])
L.save_session_to_file(id_session)
return Profile.from_username(L.context, fetched_user)
def get_image(url):
@ -75,9 +78,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, 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
profile = get_instagram_user(user, fetched_user)
profile = get_instagram_user(user, fetched_user, id_session)
# get list of all posts
posts = profile.get_posts()
stupidcounter = 0