Add some comments

This commit is contained in:
lluni 2023-08-01 18:59:46 +02:00
parent 091927de06
commit f86e7f0a02
Signed by: lluni
GPG key ID: ACEEB468BC325D35
3 changed files with 21 additions and 11 deletions

View file

@ -4,17 +4,20 @@ from dotenv import load_dotenv
from mastodon import Mastodon from mastodon import Mastodon
from os import getenv from os import getenv
# load .env # ----- load .env ----- #
load_dotenv() load_dotenv()
# register application # ----- register application ----- #
Mastodon.create_app( Mastodon.create_app(
getenv("MASTODON_APP_NAME"), getenv("MASTODON_APP_NAME"),
api_base_url = str(getenv("MASTODON_URL")), api_base_url = str(getenv("MASTODON_URL")),
to_file = getenv("MASTODON_CLIENT_SECRET") to_file = getenv("MASTODON_CLIENT_SECRET")
) )
# login # ----- login Mastodon account ----- #
mastodon = Mastodon( mastodon = Mastodon(
client_id = getenv("MASTODON_CLIENT_SECRET"), client_id = getenv("MASTODON_CLIENT_SECRET"),
api_base_url = getenv("MASTODON_URL") api_base_url = getenv("MASTODON_URL")
@ -25,5 +28,6 @@ mastodon.log_in(
to_file = getenv("MASTODON_USER_SECRET") to_file = getenv("MASTODON_USER_SECRET")
) )
# test toot # ----- post test toot ----- #
mastodon.toot("Hello World") mastodon.toot("Hello World")

View file

@ -4,10 +4,12 @@ import praw
from dotenv import load_dotenv from dotenv import load_dotenv
from os import getenv from os import getenv
# load .env # ----- load .env ----- #
load_dotenv() load_dotenv()
# initialize reddit # ----- initialize reddit ----- #
reddit = praw.Reddit( reddit = praw.Reddit(
client_id = getenv("REDDIT_CLIENT_ID"), client_id = getenv("REDDIT_CLIENT_ID"),
client_secret = getenv("REDDIT_CLIENT_SECRET"), client_secret = getenv("REDDIT_CLIENT_SECRET"),

View file

@ -6,9 +6,12 @@ from mastodon import Mastodon
from os import getenv, remove from os import getenv, remove
from os.path import getsize from os.path import getsize
# load .env # ----- load .env ----- #
load_dotenv() load_dotenv()
# ----- initialization ----- #
# initialize reddit # initialize reddit
reddit = praw.Reddit( reddit = praw.Reddit(
client_id = getenv("REDDIT_CLIENT_ID"), client_id = getenv("REDDIT_CLIENT_ID"),
@ -23,6 +26,8 @@ mastodon = Mastodon(
api_base_url = getenv("MASTODON_URL") api_base_url = getenv("MASTODON_URL")
) )
# ----- main script ----- #
# get recent posts to check for duplicates # get recent posts to check for duplicates
last_posts = mastodon.account_statuses(getenv("MASTODON_USER_ID"), limit=15) last_posts = mastodon.account_statuses(getenv("MASTODON_USER_ID"), limit=15)
@ -68,4 +73,3 @@ for submission in reddit.subreddit(str(getenv("REDDIT_SUBREDDIT"))).top(time_fil
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