diff --git a/.gitignore b/.gitignore index dbf626a..77edef0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ usercred.secret clientcred.secret post_toots.sh -redvid_temp diff --git a/README.md b/README.md index 7f70855..fca862f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ - Python 3 - conda/mamba -- FFmpeg ## Usage diff --git a/cleanup.py b/cleanup.py index b732ff9..ed6b633 100644 --- a/cleanup.py +++ b/cleanup.py @@ -2,11 +2,9 @@ # ----- imports ----- # -from os import getenv - from dotenv import load_dotenv from mastodon import Mastodon, MastodonRatelimitError - +from os import getenv def cleanup(offset: int = 200, num_batches: int = 10, limit: int = 40, start_id: int | None = None): """Delete old posts without any interactions. @@ -97,4 +95,4 @@ def cleanup(offset: int = 200, num_batches: int = 10, limit: int = 40, start_id: print("Ignoring post:", submission["url"]) if __name__ == "__main__": - cleanup(offset=100, num_batches=10, limit=40, start_id=None) + cleanup(offset=200, num_batches=10, limit=40, start_id=None) diff --git a/environment.yml b/environment.yml index 530164e..814c4d6 100644 --- a/environment.yml +++ b/environment.yml @@ -5,47 +5,49 @@ channels: dependencies: - _libgcc_mutex=0.1=conda_forge - _openmp_mutex=4.5=2_gnu - - brotli-python=1.1.0=py310hc6cd4ac_1 - - bzip2=1.0.8=hd590300_5 - - ca-certificates=2023.11.17=hbcca054_0 - - certifi=2023.11.17=pyhd8ed1ab_0 - - charset-normalizer=3.3.2=pyhd8ed1ab_0 - - idna=3.6=pyhd8ed1ab_0 - - ld_impl_linux-64=2.40=h41732ed_0 + - brotlipy=0.7.0=py310h5764c6d_1005 + - bzip2=1.0.8=h7f98852_4 + - ca-certificates=2022.9.24=ha878542_0 + - certifi=2022.9.24=pyhd8ed1ab_0 + - cffi=1.15.1=py310h255011f_2 + - charset-normalizer=2.1.1=pyhd8ed1ab_0 + - cryptography=38.0.3=py310h600f1e7_0 + - idna=3.4=pyhd8ed1ab_0 + - ld_impl_linux-64=2.39=hc81fddc_0 - libffi=3.4.2=h7f98852_5 - - libgcc-ng=13.2.0=h807b86a_3 - - libgomp=13.2.0=h807b86a_3 - - libnsl=2.0.1=hd590300_0 - - libsqlite=3.44.2=h2797004_0 - - libstdcxx-ng=13.2.0=h7e041cc_3 - - libuuid=2.38.1=h0b41bf4_0 - - libzlib=1.2.13=hd590300_5 - - ncurses=6.4=h59595ed_2 - - openssl=3.2.0=hd590300_1 - - pip=23.3.2=pyhd8ed1ab_0 - - praw=7.7.1=pyhd8ed1ab_0 - - prawcore=2.4.0=pyhd8ed1ab_0 + - libgcc-ng=12.2.0=h65d4601_19 + - libgomp=12.2.0=h65d4601_19 + - libnsl=2.0.0=h7f98852_0 + - libsqlite=3.39.4=h753d276_0 + - libuuid=2.32.1=h7f98852_1000 + - libzlib=1.2.13=h166bdaf_4 + - ncurses=6.3=h27087fc_1 + - openssl=3.0.7=h166bdaf_0 + - pip=22.3.1=pyhd8ed1ab_0 + - praw=7.6.0=pyhd8ed1ab_0 + - prawcore=2.3.0=pyhd8ed1ab_0 + - pycparser=2.21=pyhd8ed1ab_0 + - pyopenssl=22.1.0=pyhd8ed1ab_0 - pysocks=1.7.1=pyha2e5f31_6 - python=3.10.6=ha86cf86_0_cpython - - python_abi=3.10=4_cp310 - - readline=8.2=h8228510_1 - - requests=2.31.0=pyhd8ed1ab_0 - - setuptools=69.0.3=pyhd8ed1ab_0 - - tk=8.6.13=noxft_h4845f30_101 - - tzdata=2023d=h0c530f3_0 + - python_abi=3.10=2_cp310 + - readline=8.1.2=h0f457ee_0 + - requests=2.28.1=pyhd8ed1ab_1 + - setuptools=65.5.1=pyhd8ed1ab_0 + - tk=8.6.12=h27826a3_0 + - tzdata=2022f=h191b570_0 - update_checker=0.18.0=pyh9f0ad1d_0 - - urllib3=2.1.0=pyhd8ed1ab_0 - - websocket-client=1.7.0=pyhd8ed1ab_0 - - wheel=0.42.0=pyhd8ed1ab_0 + - urllib3=1.26.11=pyhd8ed1ab_0 + - websocket-client=1.4.2=pyhd8ed1ab_0 + - wheel=0.38.2=pyhd8ed1ab_0 - xz=5.2.6=h166bdaf_0 - pip: - blurhash==1.1.4 - decorator==5.1.1 - - mastodon-py==1.8.1 + - mastodon-py==1.5.2 - python-dateutil==2.8.2 - python-dotenv==0.21.0 - python-magic==0.4.27 - pytz==2022.6 - - redvid==2.0.3 - six==1.16.0 - wget==3.2 diff --git a/masto.py b/masto.py index 39c6d6d..552f6dc 100644 --- a/masto.py +++ b/masto.py @@ -1,9 +1,8 @@ """Initialize Mastodon.py, login the account and register an application""" -from os import getenv - from dotenv import load_dotenv from mastodon import Mastodon +from os import getenv # ----- load .env ----- # diff --git a/reddit.py b/reddit.py index 861e55b..43a8d61 100644 --- a/reddit.py +++ b/reddit.py @@ -1,9 +1,8 @@ """Initialize PRAW""" -from os import getenv - import praw from dotenv import load_dotenv +from os import getenv # ----- load .env ----- # diff --git a/script.py b/script.py index ca27f41..6e054d4 100644 --- a/script.py +++ b/script.py @@ -1,13 +1,10 @@ """Main script to toot a new post""" -from os import getenv, remove -from os.path import getsize - -import praw -import wget +import praw, wget from dotenv import load_dotenv from mastodon import Mastodon -from redvid import Downloader +from os import getenv, remove +from os.path import getsize # ----- load .env ----- # @@ -45,9 +42,7 @@ for submission in reddit.subreddit(str(getenv("REDDIT_SUBREDDIT"))).top(time_fil if submission.permalink in posted_submission["content"]: already_posted = True break - # abort download if the post has been posted already if already_posted: - print("Skipping post: https://www.reddit.com" + submission.permalink) continue # check if text only @@ -56,30 +51,25 @@ for submission in reddit.subreddit(str(getenv("REDDIT_SUBREDDIT"))).top(time_fil mastodon.status_post(status_text, visibility="unlisted") # check if reddit video elif "v.redd.it" in submission.url: - print("Downloading video post: https://www.reddit.com" + submission.permalink) - downloader = Downloader(url="https://www.reddit.com"+submission.permalink, filename="video.mp4", max_q=True) - downloader.download() - - print("\nUploading video") + url = submission.media["reddit_video"]["fallback_url"] + url = url.split("?")[0] + filename = wget.download(url) + print() # check if video file is small enough for the server (10MB) - if getsize(filename) < 10_000_000: + if getsize(filename) < 10*1000000: media = mastodon.media_post(filename) - status_text = submission.title + "\n\ngeposted von u/" + submission.author.name + "\nhttps://www.reddit.com" + submission.permalink + status_text = submission.title + "\n\ngeposted von u/" + submission.author.name + "\nhttps://reddit.com" + submission.permalink mastodon.status_post(status_text, media_ids=media["id"], visibility="unlisted") else: - status_text = submission.title + "\n\nDas gepostete Video ist leider zu lang für diesen Server. Das Video bzw. der Post kann über den untenstehenden Link aufgerufen werden. " + "\n\ngeposted von u/" + submission.author.name + "\nhttps://www.reddit.com" + submission.permalink + status_text = submission.title + "\n\nGeposteter Videolink: " + url + "\n\ngeposted von u/" + submission.author.name + "\n" + submission.permalink + "\n\n" + submission.selftext mastodon.status_post(status_text, visibility="unlisted") - remove(filename) else: - print("Downloading image post: https://www.reddit.com" + submission.permalink) - filename = wget.download(submission.url, out="image." + submission.url.split(".")[-1]) - - print("\nUploading image") + filename = wget.download(submission.url) + print() media = mastodon.media_post(filename) - status_text = submission.title + "\n\ngeposted von u/" + submission.author.name + "\nhttps://www.reddit.com" + submission.permalink + status_text = submission.title + "\n\ngeposted von u/" + submission.author.name + "\nhttps://reddit.com" + submission.permalink mastodon.status_post(status_text, media_ids=media["id"], visibility="unlisted") - remove(filename) break