Compare commits

...

4 commits

Author SHA1 Message Date
eb34c4cd8a
Sort imports 2024-01-04 19:39:41 +01:00
cf2d9b8af6
Change video download logic to enable videos with sound 2024-01-04 19:38:26 +01:00
34c734bc0d
Update environment 2024-01-04 19:29:25 +01:00
d12da18403
Change default cleanup offset 2024-01-04 19:21:51 +01:00
7 changed files with 63 additions and 49 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@
usercred.secret usercred.secret
clientcred.secret clientcred.secret
post_toots.sh post_toots.sh
redvid_temp

View file

@ -4,6 +4,7 @@
- Python 3 - Python 3
- conda/mamba - conda/mamba
- FFmpeg
## Usage ## Usage

View file

@ -2,9 +2,11 @@
# ----- imports ----- # # ----- imports ----- #
from os import getenv
from dotenv import load_dotenv from dotenv import load_dotenv
from mastodon import Mastodon, MastodonRatelimitError 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): def cleanup(offset: int = 200, num_batches: int = 10, limit: int = 40, start_id: int | None = None):
"""Delete old posts without any interactions. """Delete old posts without any interactions.
@ -95,4 +97,4 @@ def cleanup(offset: int = 200, num_batches: int = 10, limit: int = 40, start_id:
print("Ignoring post:", submission["url"]) print("Ignoring post:", submission["url"])
if __name__ == "__main__": if __name__ == "__main__":
cleanup(offset=200, num_batches=10, limit=40, start_id=None) cleanup(offset=100, num_batches=10, limit=40, start_id=None)

View file

@ -5,49 +5,47 @@ channels:
dependencies: dependencies:
- _libgcc_mutex=0.1=conda_forge - _libgcc_mutex=0.1=conda_forge
- _openmp_mutex=4.5=2_gnu - _openmp_mutex=4.5=2_gnu
- brotlipy=0.7.0=py310h5764c6d_1005 - brotli-python=1.1.0=py310hc6cd4ac_1
- bzip2=1.0.8=h7f98852_4 - bzip2=1.0.8=hd590300_5
- ca-certificates=2022.9.24=ha878542_0 - ca-certificates=2023.11.17=hbcca054_0
- certifi=2022.9.24=pyhd8ed1ab_0 - certifi=2023.11.17=pyhd8ed1ab_0
- cffi=1.15.1=py310h255011f_2 - charset-normalizer=3.3.2=pyhd8ed1ab_0
- charset-normalizer=2.1.1=pyhd8ed1ab_0 - idna=3.6=pyhd8ed1ab_0
- cryptography=38.0.3=py310h600f1e7_0 - ld_impl_linux-64=2.40=h41732ed_0
- idna=3.4=pyhd8ed1ab_0
- ld_impl_linux-64=2.39=hc81fddc_0
- libffi=3.4.2=h7f98852_5 - libffi=3.4.2=h7f98852_5
- libgcc-ng=12.2.0=h65d4601_19 - libgcc-ng=13.2.0=h807b86a_3
- libgomp=12.2.0=h65d4601_19 - libgomp=13.2.0=h807b86a_3
- libnsl=2.0.0=h7f98852_0 - libnsl=2.0.1=hd590300_0
- libsqlite=3.39.4=h753d276_0 - libsqlite=3.44.2=h2797004_0
- libuuid=2.32.1=h7f98852_1000 - libstdcxx-ng=13.2.0=h7e041cc_3
- libzlib=1.2.13=h166bdaf_4 - libuuid=2.38.1=h0b41bf4_0
- ncurses=6.3=h27087fc_1 - libzlib=1.2.13=hd590300_5
- openssl=3.0.7=h166bdaf_0 - ncurses=6.4=h59595ed_2
- pip=22.3.1=pyhd8ed1ab_0 - openssl=3.2.0=hd590300_1
- praw=7.6.0=pyhd8ed1ab_0 - pip=23.3.2=pyhd8ed1ab_0
- prawcore=2.3.0=pyhd8ed1ab_0 - praw=7.7.1=pyhd8ed1ab_0
- pycparser=2.21=pyhd8ed1ab_0 - prawcore=2.4.0=pyhd8ed1ab_0
- pyopenssl=22.1.0=pyhd8ed1ab_0
- pysocks=1.7.1=pyha2e5f31_6 - pysocks=1.7.1=pyha2e5f31_6
- python=3.10.6=ha86cf86_0_cpython - python=3.10.6=ha86cf86_0_cpython
- python_abi=3.10=2_cp310 - python_abi=3.10=4_cp310
- readline=8.1.2=h0f457ee_0 - readline=8.2=h8228510_1
- requests=2.28.1=pyhd8ed1ab_1 - requests=2.31.0=pyhd8ed1ab_0
- setuptools=65.5.1=pyhd8ed1ab_0 - setuptools=69.0.3=pyhd8ed1ab_0
- tk=8.6.12=h27826a3_0 - tk=8.6.13=noxft_h4845f30_101
- tzdata=2022f=h191b570_0 - tzdata=2023d=h0c530f3_0
- update_checker=0.18.0=pyh9f0ad1d_0 - update_checker=0.18.0=pyh9f0ad1d_0
- urllib3=1.26.11=pyhd8ed1ab_0 - urllib3=2.1.0=pyhd8ed1ab_0
- websocket-client=1.4.2=pyhd8ed1ab_0 - websocket-client=1.7.0=pyhd8ed1ab_0
- wheel=0.38.2=pyhd8ed1ab_0 - wheel=0.42.0=pyhd8ed1ab_0
- xz=5.2.6=h166bdaf_0 - xz=5.2.6=h166bdaf_0
- pip: - pip:
- blurhash==1.1.4 - blurhash==1.1.4
- decorator==5.1.1 - decorator==5.1.1
- mastodon-py==1.5.2 - mastodon-py==1.8.1
- python-dateutil==2.8.2 - python-dateutil==2.8.2
- python-dotenv==0.21.0 - python-dotenv==0.21.0
- python-magic==0.4.27 - python-magic==0.4.27
- pytz==2022.6 - pytz==2022.6
- redvid==2.0.3
- six==1.16.0 - six==1.16.0
- wget==3.2 - wget==3.2

View file

@ -1,8 +1,9 @@
"""Initialize Mastodon.py, login the account and register an application""" """Initialize Mastodon.py, login the account and register an application"""
from os import getenv
from dotenv import load_dotenv from dotenv import load_dotenv
from mastodon import Mastodon from mastodon import Mastodon
from os import getenv
# ----- load .env ----- # # ----- load .env ----- #

View file

@ -1,8 +1,9 @@
"""Initialize PRAW""" """Initialize PRAW"""
from os import getenv
import praw import praw
from dotenv import load_dotenv from dotenv import load_dotenv
from os import getenv
# ----- load .env ----- # # ----- load .env ----- #

View file

@ -1,11 +1,14 @@
"""Main script to toot a new post""" """Main script to toot a new post"""
import praw, wget
from dotenv import load_dotenv
from mastodon import Mastodon
from os import getenv, remove from os import getenv, remove
from os.path import getsize from os.path import getsize
import praw
import wget
from dotenv import load_dotenv
from mastodon import Mastodon
from redvid import Downloader
# ----- load .env ----- # # ----- load .env ----- #
load_dotenv() load_dotenv()
@ -42,7 +45,9 @@ for submission in reddit.subreddit(str(getenv("REDDIT_SUBREDDIT"))).top(time_fil
if submission.permalink in posted_submission["content"]: if submission.permalink in posted_submission["content"]:
already_posted = True already_posted = True
break break
# abort download if the post has been posted already
if already_posted: if already_posted:
print("Skipping post: https://www.reddit.com" + submission.permalink)
continue continue
# check if text only # check if text only
@ -51,25 +56,30 @@ for submission in reddit.subreddit(str(getenv("REDDIT_SUBREDDIT"))).top(time_fil
mastodon.status_post(status_text, visibility="unlisted") mastodon.status_post(status_text, visibility="unlisted")
# check if reddit video # check if reddit video
elif "v.redd.it" in submission.url: elif "v.redd.it" in submission.url:
url = submission.media["reddit_video"]["fallback_url"] print("Downloading video post: https://www.reddit.com" + submission.permalink)
url = url.split("?")[0] downloader = Downloader(url="https://www.reddit.com"+submission.permalink, filename="video.mp4", max_q=True)
filename = wget.download(url) downloader.download()
print()
print("\nUploading video")
# check if video file is small enough for the server (10MB) # check if video file is small enough for the server (10MB)
if getsize(filename) < 10*1000000: if getsize(filename) < 10_000_000:
media = mastodon.media_post(filename) media = mastodon.media_post(filename)
status_text = submission.title + "\n\ngeposted von u/" + submission.author.name + "\nhttps://reddit.com" + submission.permalink status_text = submission.title + "\n\ngeposted von u/" + submission.author.name + "\nhttps://www.reddit.com" + submission.permalink
mastodon.status_post(status_text, media_ids=media["id"], visibility="unlisted") mastodon.status_post(status_text, media_ids=media["id"], visibility="unlisted")
else: else:
status_text = submission.title + "\n\nGeposteter Videolink: " + url + "\n\ngeposted von u/" + submission.author.name + "\n" + submission.permalink + "\n\n" + submission.selftext 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
mastodon.status_post(status_text, visibility="unlisted") mastodon.status_post(status_text, visibility="unlisted")
remove(filename) remove(filename)
else: else:
filename = wget.download(submission.url) print("Downloading image post: https://www.reddit.com" + submission.permalink)
print() filename = wget.download(submission.url, out="image." + submission.url.split(".")[-1])
print("\nUploading image")
media = mastodon.media_post(filename) media = mastodon.media_post(filename)
status_text = submission.title + "\n\ngeposted von u/" + submission.author.name + "\nhttps://reddit.com" + submission.permalink status_text = submission.title + "\n\ngeposted von u/" + submission.author.name + "\nhttps://www.reddit.com" + submission.permalink
mastodon.status_post(status_text, media_ids=media["id"], visibility="unlisted") mastodon.status_post(status_text, media_ids=media["id"], visibility="unlisted")
remove(filename) remove(filename)
break break