Compare commits
4 commits
d369d30b32
...
eb34c4cd8a
Author | SHA1 | Date | |
---|---|---|---|
eb34c4cd8a | |||
cf2d9b8af6 | |||
34c734bc0d | |||
d12da18403 |
7 changed files with 63 additions and 49 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@
|
|||
usercred.secret
|
||||
clientcred.secret
|
||||
post_toots.sh
|
||||
redvid_temp
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
- Python 3
|
||||
- conda/mamba
|
||||
- FFmpeg
|
||||
|
||||
## Usage
|
||||
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
# ----- 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.
|
||||
|
@ -95,4 +97,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=200, num_batches=10, limit=40, start_id=None)
|
||||
cleanup(offset=100, num_batches=10, limit=40, start_id=None)
|
||||
|
|
|
@ -5,49 +5,47 @@ channels:
|
|||
dependencies:
|
||||
- _libgcc_mutex=0.1=conda_forge
|
||||
- _openmp_mutex=4.5=2_gnu
|
||||
- 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
|
||||
- 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
|
||||
- libffi=3.4.2=h7f98852_5
|
||||
- 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
|
||||
- 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
|
||||
- pysocks=1.7.1=pyha2e5f31_6
|
||||
- python=3.10.6=ha86cf86_0_cpython
|
||||
- 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
|
||||
- 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
|
||||
- update_checker=0.18.0=pyh9f0ad1d_0
|
||||
- urllib3=1.26.11=pyhd8ed1ab_0
|
||||
- websocket-client=1.4.2=pyhd8ed1ab_0
|
||||
- wheel=0.38.2=pyhd8ed1ab_0
|
||||
- urllib3=2.1.0=pyhd8ed1ab_0
|
||||
- websocket-client=1.7.0=pyhd8ed1ab_0
|
||||
- wheel=0.42.0=pyhd8ed1ab_0
|
||||
- xz=5.2.6=h166bdaf_0
|
||||
- pip:
|
||||
- blurhash==1.1.4
|
||||
- decorator==5.1.1
|
||||
- mastodon-py==1.5.2
|
||||
- mastodon-py==1.8.1
|
||||
- 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
|
||||
|
|
3
masto.py
3
masto.py
|
@ -1,8 +1,9 @@
|
|||
"""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 ----- #
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
"""Initialize PRAW"""
|
||||
|
||||
from os import getenv
|
||||
|
||||
import praw
|
||||
from dotenv import load_dotenv
|
||||
from os import getenv
|
||||
|
||||
# ----- load .env ----- #
|
||||
|
||||
|
|
36
script.py
36
script.py
|
@ -1,11 +1,14 @@
|
|||
"""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.path import getsize
|
||||
|
||||
import praw
|
||||
import wget
|
||||
from dotenv import load_dotenv
|
||||
from mastodon import Mastodon
|
||||
from redvid import Downloader
|
||||
|
||||
# ----- load .env ----- #
|
||||
|
||||
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"]:
|
||||
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
|
||||
|
@ -51,25 +56,30 @@ 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:
|
||||
url = submission.media["reddit_video"]["fallback_url"]
|
||||
url = url.split("?")[0]
|
||||
filename = wget.download(url)
|
||||
print()
|
||||
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")
|
||||
|
||||
# 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)
|
||||
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")
|
||||
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")
|
||||
|
||||
remove(filename)
|
||||
else:
|
||||
filename = wget.download(submission.url)
|
||||
print()
|
||||
print("Downloading image post: https://www.reddit.com" + submission.permalink)
|
||||
filename = wget.download(submission.url, out="image." + submission.url.split(".")[-1])
|
||||
|
||||
print("\nUploading image")
|
||||
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")
|
||||
|
||||
remove(filename)
|
||||
break
|
||||
|
|
Loading…
Reference in a new issue