From 93c4146644ea2125fd13a971c456a9ffcf6a274d Mon Sep 17 00:00:00 2001 From: jwansek Date: Sun, 6 Jan 2019 20:43:49 +0000 Subject: added feature that restarts the program every two hours and fixed one bug --- SmallYTChannelBotSubmissions.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'SmallYTChannelBotSubmissions.py') diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index 2a95c48..712f5b0 100644 --- a/SmallYTChannelBotSubmissions.py +++ b/SmallYTChannelBotSubmissions.py @@ -10,6 +10,7 @@ import login import time import praw import re +import os reddit = login.REDDIT @@ -18,6 +19,10 @@ subreddit = reddit.subreddit("SmallYTChannel") db = Database() +def get_time(): + #this is not the correct way to do this but I don't care + return str(datetime.datetime.now().time())[:8] + def get_lambda_from_flair(s): result = re.search("\[(.*)\]", s) if result is not None and "λ" in result.group(1): @@ -182,9 +187,9 @@ def main(): elif db.user_given_lambda(parentauthour, str(submission.permalink)): text = "You have already given /u/%s λ for this submission. Why not give λ to another user instead?" % parentauthour else: - print("'/u/%s' has given '/u/%s' lambda!" % (op, parentauthour)) + print("[%s] '/u/%s' has given '/u/%s' lambda!" % (get_time(), op, parentauthour)) text = "You have given /u/%s 1λ. /u/%s now has %iλ" % (parentauthour, parentauthour, db.get_lambda(parentauthour)[0] + 1) - + if not db.link_in_db(submission.permalink) or not db.link_in_db(submission.permalink.replace("https://www.reddit.com", "")): db.give_lambda(parentauthour, submission.permalink, op) print("The OP has received lambda too!") @@ -208,6 +213,9 @@ def main(): except Exception as e: print("[ERROR while removing λ] %s" % e) text = r"An error was encountered. Please use the syntax `!takelambda [user] [how much to remove {integer}] [reason]`" + reply = comment.reply(text + tail) + reply.mod.distinguish() + continue update_users_flair(comment.parent()) reply = comment.reply(text + tail) @@ -219,12 +227,12 @@ def main(): break if not db.id_in_blacklist(submission.id): db.add_to_blacklist(submission.id) - print("There has been a new submission: '%s', with flair '%s'" % (submission.title, submission.link_flair_text)) + print("[%s] There has been a new submission: '%s', with flair '%s'" % (get_time(), submission.title, submission.link_flair_text)) if str(submission.author) not in get_mods(): score = db.get_lambda(str(submission.author))[0] if submission.link_flair_text in ["Discussion", "Meta", "Collab"]: - if "youtube.com" in str(submission.url): + if "youtube.com" in str(submission.url) or "youtu.be" in str(submission.url): text = "Your post has been removed because it has the wrong flair. [Discussion], [Meta] and [Collab] flairs are only for text submissions." submission.mod.remove() else: @@ -249,5 +257,10 @@ def main(): continue if __name__ == "__main__": + #file = open("pid.txt", "w") + #file.write(str(os.getpid())) + #file.close() + + print("\n####################\n[%s] RESTARTED\n####################\n" % get_time()) main() -- cgit v1.2.3