Compare commits
No commits in common. "eb34c4cd8adab561e484192d6c6fb7ae2c04be73" and "d369d30b32db28f72cdf5f0d44fc9e353efa08c1" have entirely different histories.
eb34c4cd8a
...
d369d30b32
7 changed files with 49 additions and 63 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,4 +3,3 @@
|
||||||
usercred.secret
|
usercred.secret
|
||||||
clientcred.secret
|
clientcred.secret
|
||||||
post_toots.sh
|
post_toots.sh
|
||||||
redvid_temp
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
- Python 3
|
- Python 3
|
||||||
- conda/mamba
|
- conda/mamba
|
||||||
- FFmpeg
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,9 @@
|
||||||
|
|
||||||
# ----- 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.
|
||||||
|
@ -97,4 +95,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=100, num_batches=10, limit=40, start_id=None)
|
cleanup(offset=200, num_batches=10, limit=40, start_id=None)
|
||||||
|
|
|
@ -5,47 +5,49 @@ 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
|
||||||
- brotli-python=1.1.0=py310hc6cd4ac_1
|
- brotlipy=0.7.0=py310h5764c6d_1005
|
||||||
- bzip2=1.0.8=hd590300_5
|
- bzip2=1.0.8=h7f98852_4
|
||||||
- ca-certificates=2023.11.17=hbcca054_0
|
- ca-certificates=2022.9.24=ha878542_0
|
||||||
- certifi=2023.11.17=pyhd8ed1ab_0
|
- certifi=2022.9.24=pyhd8ed1ab_0
|
||||||
- charset-normalizer=3.3.2=pyhd8ed1ab_0
|
- cffi=1.15.1=py310h255011f_2
|
||||||
- idna=3.6=pyhd8ed1ab_0
|
- charset-normalizer=2.1.1=pyhd8ed1ab_0
|
||||||
- ld_impl_linux-64=2.40=h41732ed_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
|
- libffi=3.4.2=h7f98852_5
|
||||||
- libgcc-ng=13.2.0=h807b86a_3
|
- libgcc-ng=12.2.0=h65d4601_19
|
||||||
- libgomp=13.2.0=h807b86a_3
|
- libgomp=12.2.0=h65d4601_19
|
||||||
- libnsl=2.0.1=hd590300_0
|
- libnsl=2.0.0=h7f98852_0
|
||||||
- libsqlite=3.44.2=h2797004_0
|
- libsqlite=3.39.4=h753d276_0
|
||||||
- libstdcxx-ng=13.2.0=h7e041cc_3
|
- libuuid=2.32.1=h7f98852_1000
|
||||||
- libuuid=2.38.1=h0b41bf4_0
|
- libzlib=1.2.13=h166bdaf_4
|
||||||
- libzlib=1.2.13=hd590300_5
|
- ncurses=6.3=h27087fc_1
|
||||||
- ncurses=6.4=h59595ed_2
|
- openssl=3.0.7=h166bdaf_0
|
||||||
- openssl=3.2.0=hd590300_1
|
- pip=22.3.1=pyhd8ed1ab_0
|
||||||
- pip=23.3.2=pyhd8ed1ab_0
|
- praw=7.6.0=pyhd8ed1ab_0
|
||||||
- praw=7.7.1=pyhd8ed1ab_0
|
- prawcore=2.3.0=pyhd8ed1ab_0
|
||||||
- prawcore=2.4.0=pyhd8ed1ab_0
|
- pycparser=2.21=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=4_cp310
|
- python_abi=3.10=2_cp310
|
||||||
- readline=8.2=h8228510_1
|
- readline=8.1.2=h0f457ee_0
|
||||||
- requests=2.31.0=pyhd8ed1ab_0
|
- requests=2.28.1=pyhd8ed1ab_1
|
||||||
- setuptools=69.0.3=pyhd8ed1ab_0
|
- setuptools=65.5.1=pyhd8ed1ab_0
|
||||||
- tk=8.6.13=noxft_h4845f30_101
|
- tk=8.6.12=h27826a3_0
|
||||||
- tzdata=2023d=h0c530f3_0
|
- tzdata=2022f=h191b570_0
|
||||||
- update_checker=0.18.0=pyh9f0ad1d_0
|
- update_checker=0.18.0=pyh9f0ad1d_0
|
||||||
- urllib3=2.1.0=pyhd8ed1ab_0
|
- urllib3=1.26.11=pyhd8ed1ab_0
|
||||||
- websocket-client=1.7.0=pyhd8ed1ab_0
|
- websocket-client=1.4.2=pyhd8ed1ab_0
|
||||||
- wheel=0.42.0=pyhd8ed1ab_0
|
- wheel=0.38.2=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.8.1
|
- mastodon-py==1.5.2
|
||||||
- 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
|
||||||
|
|
3
masto.py
3
masto.py
|
@ -1,9 +1,8 @@
|
||||||
"""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 ----- #
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
"""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 ----- #
|
||||||
|
|
||||||
|
|
36
script.py
36
script.py
|
@ -1,13 +1,10 @@
|
||||||
"""Main script to toot a new post"""
|
"""Main script to toot a new post"""
|
||||||
|
|
||||||
from os import getenv, remove
|
import praw, wget
|
||||||
from os.path import getsize
|
|
||||||
|
|
||||||
import praw
|
|
||||||
import wget
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from mastodon import Mastodon
|
from mastodon import Mastodon
|
||||||
from redvid import Downloader
|
from os import getenv, remove
|
||||||
|
from os.path import getsize
|
||||||
|
|
||||||
# ----- load .env ----- #
|
# ----- 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"]:
|
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
|
||||||
|
@ -56,30 +51,25 @@ 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:
|
||||||
print("Downloading video post: https://www.reddit.com" + submission.permalink)
|
url = submission.media["reddit_video"]["fallback_url"]
|
||||||
downloader = Downloader(url="https://www.reddit.com"+submission.permalink, filename="video.mp4", max_q=True)
|
url = url.split("?")[0]
|
||||||
downloader.download()
|
filename = wget.download(url)
|
||||||
|
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_000_000:
|
if getsize(filename) < 10*1000000:
|
||||||
media = mastodon.media_post(filename)
|
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")
|
mastodon.status_post(status_text, media_ids=media["id"], visibility="unlisted")
|
||||||
else:
|
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")
|
mastodon.status_post(status_text, visibility="unlisted")
|
||||||
|
|
||||||
remove(filename)
|
remove(filename)
|
||||||
else:
|
else:
|
||||||
print("Downloading image post: https://www.reddit.com" + submission.permalink)
|
filename = wget.download(submission.url)
|
||||||
filename = wget.download(submission.url, out="image." + submission.url.split(".")[-1])
|
print()
|
||||||
|
|
||||||
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://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")
|
mastodon.status_post(status_text, media_ids=media["id"], visibility="unlisted")
|
||||||
|
|
||||||
remove(filename)
|
remove(filename)
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in a new issue