uhhh, bug fixed 👍
This commit is contained in:
+1
-3
@@ -6,6 +6,4 @@ Cargo.lock
|
||||
.vscode/
|
||||
|
||||
# program-created data
|
||||
data/reddit_data.json
|
||||
data/reddit_images/*
|
||||
!data/reddit_images/
|
||||
data/reddit_data.json
|
||||
@@ -1,4 +1,13 @@
|
||||
{
|
||||
"file_created_correctly": true,
|
||||
"bk_manually_added_posts": []
|
||||
"bk_weekly_art_posts": [
|
||||
{
|
||||
"url": "EXAMPLE VALUE DO NOT INCLUDE",
|
||||
"date_unix": 1738614657,
|
||||
"added_by_human": false,
|
||||
"added_by_bot": true,
|
||||
"approved_by_human": true,
|
||||
"approved_by_ris": true
|
||||
}
|
||||
]
|
||||
}
|
||||
+33
-12
@@ -27,20 +27,25 @@ def main():
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
|
||||
bot = Bot()
|
||||
print("Reading data...")
|
||||
read_data(bot)
|
||||
|
||||
check_emoji = emoji.emojize(":check_mark_button:")
|
||||
cross_emoji = emoji.emojize(":cross_mark:")
|
||||
|
||||
print("Fetching posts...")
|
||||
posts = fetch_posts_with_flair(bot, "Original Art")
|
||||
|
||||
print("Evaluating posts...\n\n")
|
||||
for post in posts:
|
||||
media = has_media(post)
|
||||
media_urls = "\n ".join(media[3])
|
||||
|
||||
print(post.title, "\n ", post.link_flair_text, "\n ", post.url)
|
||||
print(
|
||||
" ", check_emoji if media[0] else cross_emoji, f"Media ({media[1]}) [{media[2]}]",
|
||||
"\n"
|
||||
f"{post.title}",
|
||||
f"\n {post.shortlink}"
|
||||
f"\n {check_emoji if media[0] else cross_emoji} Media ({media[1]}) [{media[2]}]",
|
||||
f"\n {media_urls}\n"
|
||||
)
|
||||
|
||||
|
||||
@@ -51,8 +56,12 @@ def read_data(bot: Bot):
|
||||
try:
|
||||
bot.data_f = open(data_path + "\\reddit_data.json", "r+")
|
||||
except FileNotFoundError:
|
||||
bot.data_f = open(data_path + "\\reddit_data.json", "w+")
|
||||
bot.data_f.write(open(data_path + "\\reddit_data_preset.json", "r").read())
|
||||
print("reddit_data.json not found, creating new from preset...")
|
||||
with open(data_path + "\\reddit_data.json", "w") as f:
|
||||
f.write(open(data_path + "\\reddit_data_preset.json", "r").read())
|
||||
|
||||
|
||||
bot.data_f = open(data_path + "\\reddit_data.json", "r+")
|
||||
|
||||
data_str = bot.data_f.read()
|
||||
bot.data = json.loads(data_str)
|
||||
@@ -65,28 +74,40 @@ def fetch_posts_with_flair(bot: Bot, flair_name: str) -> list[models.Submission]
|
||||
posts: list[models.Submission] = []
|
||||
|
||||
# ~36 OG-art posts per week, round limit to 50 or 75
|
||||
for post in bot.sr.new(limit=10): #.search(f"flair:\"{flair_name}\"", sort="new", limit=10):
|
||||
for post in bot.sr.search(f"flair:\"{flair_name}\"", sort="new", limit=10):
|
||||
posts.append(post)
|
||||
|
||||
return posts
|
||||
|
||||
|
||||
def has_media(post: models.Submission) -> tuple[bool, str, int]:
|
||||
media_type = None
|
||||
def has_media(post: models.Submission) -> tuple[bool, str, int, list[str]]:
|
||||
media_type: str = None
|
||||
media_count = 0
|
||||
media_urls: list[str] = []
|
||||
|
||||
if hasattr(post, "post_hint"):
|
||||
media_type = post.post_hint
|
||||
media_count = 1
|
||||
media_urls.append(post.url)
|
||||
|
||||
elif hasattr(post, "is_gallery"):
|
||||
elif getattr(post, "is_gallery", False):
|
||||
if not post.is_gallery: pass
|
||||
media_type = "multiple"
|
||||
if hasattr(post, "gallery_data") and post.gallery_data:
|
||||
media_count = len(post.gallery_data.get("items", []))
|
||||
|
||||
gallery_items = getattr(post, "gallery_data", {}).get("items", [])
|
||||
media_metadata = getattr(post, "media_metadata", {})
|
||||
|
||||
media_count = len(gallery_items)
|
||||
|
||||
for item in gallery_items:
|
||||
media_id = item.get("media_id")
|
||||
image_url = media_metadata.get(media_id, {}).get("s", {}).get("u")
|
||||
|
||||
if image_url:
|
||||
media_urls.append(image_url)
|
||||
|
||||
|
||||
return (media_type != None, media_type, media_count)
|
||||
return (media_type != None, media_type, media_count, media_urls)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user