added removed flag & updated debug info
This commit is contained in:
@@ -18,6 +18,9 @@
|
|||||||
"by_human": true,
|
"by_human": true,
|
||||||
"by_ris": true
|
"by_ris": true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"EXAMPLE VALUE DELETED": {
|
||||||
|
"removed": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+10
-1
@@ -3,6 +3,7 @@ import json
|
|||||||
from typing import Final
|
from typing import Final
|
||||||
|
|
||||||
import bot as botPy
|
import bot as botPy
|
||||||
|
from macros import *
|
||||||
|
|
||||||
|
|
||||||
BK_WEEKLY: Final[str] = "bk_weekly_art_posts"
|
BK_WEEKLY: Final[str] = "bk_weekly_art_posts"
|
||||||
@@ -84,9 +85,17 @@ def write_data(bot: botPy.Bot):
|
|||||||
|
|
||||||
|
|
||||||
def update_post_in_data(bot: botPy.Bot, new_data: PostData):
|
def update_post_in_data(bot: botPy.Bot, new_data: PostData):
|
||||||
if new_data.url not in bot.data:
|
if new_data.url not in bot.data[BK_WEEKLY]:
|
||||||
bot.data[BK_WEEKLY][new_data.url] = new_data.to_json()
|
bot.data[BK_WEEKLY][new_data.url] = new_data.to_json()
|
||||||
|
py_print(f"Added post \"{new_data.url}\"")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
elif "removed" in bot.data[BK_WEEKLY][new_data.url]:
|
||||||
|
py_print(f"Failed to add post \"{new_data.url}\": Removed flag is True.")
|
||||||
|
return
|
||||||
|
|
||||||
|
else:
|
||||||
|
py_print(f"Failed to add post \"{new_data.url}\": Already exists.")
|
||||||
|
|
||||||
|
|
||||||
def remove_old_posts(bot: botPy.Bot, max_age_unix: int):
|
def remove_old_posts(bot: botPy.Bot, max_age_unix: int):
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
def py_print(*args: str):
|
||||||
|
print("Py -", " ".join(args))
|
||||||
+3
-42
@@ -1,16 +1,9 @@
|
|||||||
def py_print(*args: str):
|
|
||||||
print("Py -", " ".join(args))
|
|
||||||
|
|
||||||
py_print("Importing external modules...")
|
|
||||||
|
|
||||||
import emoji
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
py_print("Importing internal modules")
|
|
||||||
|
|
||||||
import bot as botPy
|
import bot as botPy
|
||||||
import data
|
import data
|
||||||
import reddit
|
import posts
|
||||||
|
from macros import *
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -20,39 +13,7 @@ def main():
|
|||||||
py_print("Reading data...")
|
py_print("Reading data...")
|
||||||
data.read_data(bot)
|
data.read_data(bot)
|
||||||
|
|
||||||
check_emoji = emoji.emojize(":check_mark_button:")
|
posts.add_new_posts(bot)
|
||||||
cross_emoji = emoji.emojize(":cross_mark:")
|
|
||||||
|
|
||||||
py_print("Fetching posts...")
|
|
||||||
posts = reddit.fetch_posts_with_flair(bot, "Original Art")
|
|
||||||
|
|
||||||
py_print("Evaluating posts...\n")
|
|
||||||
for post in posts:
|
|
||||||
media = reddit.has_media(post)
|
|
||||||
media_urls = "\n ".join(media[3])
|
|
||||||
|
|
||||||
print(
|
|
||||||
f"\n{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"
|
|
||||||
)
|
|
||||||
|
|
||||||
data.update_post_in_data(
|
|
||||||
bot,
|
|
||||||
data.PostData(
|
|
||||||
post.shortlink,
|
|
||||||
post.title,
|
|
||||||
post.score,
|
|
||||||
int(post.created_utc),
|
|
||||||
media[1],
|
|
||||||
media[3],
|
|
||||||
added_by_bot = True,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
data.write_data(bot)
|
|
||||||
|
|
||||||
|
|
||||||
py_print("Running main()...")
|
|
||||||
main()
|
main()
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import emoji
|
||||||
|
import reddit
|
||||||
|
import data
|
||||||
|
import bot as botPy
|
||||||
|
from macros import *
|
||||||
|
|
||||||
|
def add_new_posts(bot: botPy.Bot, debug_print: bool = False):
|
||||||
|
check_emoji = emoji.emojize(":check_mark_button:")
|
||||||
|
cross_emoji = emoji.emojize(":cross_mark:")
|
||||||
|
|
||||||
|
py_print("Fetching posts...")
|
||||||
|
posts = reddit.fetch_posts_with_flair(bot, "Original Art")
|
||||||
|
|
||||||
|
py_print("Evaluating posts...\n")
|
||||||
|
for post in posts:
|
||||||
|
media = reddit.has_media(post)
|
||||||
|
media_urls = "\n ".join(media[3])
|
||||||
|
|
||||||
|
if debug_print: print(
|
||||||
|
f"\n{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"
|
||||||
|
)
|
||||||
|
|
||||||
|
data.update_post_in_data(
|
||||||
|
bot,
|
||||||
|
data.PostData(
|
||||||
|
post.shortlink,
|
||||||
|
post.title,
|
||||||
|
post.score,
|
||||||
|
int(post.created_utc),
|
||||||
|
media[1],
|
||||||
|
media[3],
|
||||||
|
added_by_bot = True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
py_print(f"Sucessfully fetched {len(posts)} posts")
|
||||||
|
|
||||||
|
data.write_data(bot)
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
from praw import models
|
from praw import models
|
||||||
import praw
|
|
||||||
|
|
||||||
import bot as botPy
|
import bot as botPy
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user