diff options
| -rw-r--r-- | SmallYTChannelBotSubmissions.py | 21 | ||||
| -rw-r--r-- | SmallYTChannelDatabase.db | bin | 324608 -> 406528 bytes | |||
| -rw-r--r-- | onceaday.py | 1 | ||||
| -rw-r--r-- | runprog.py | 23 | 
4 files changed, 41 insertions, 4 deletions
| 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() diff --git a/SmallYTChannelDatabase.db b/SmallYTChannelDatabase.dbBinary files differ index ada38e6..07a077e 100644 --- a/SmallYTChannelDatabase.db +++ b/SmallYTChannelDatabase.db diff --git a/onceaday.py b/onceaday.py index 593a514..a84b0d9 100644 --- a/onceaday.py +++ b/onceaday.py @@ -5,4 +5,5 @@ SECONDS_IN_DAY = 25 * 60 * 60  while True:      SmallYTChannelBotSubmissions.every_day() +    print("Called @ %s" % SmallYTChannelBotSubmissions.get_time)      sleep(SECONDS_IN_DAY) diff --git a/runprog.py b/runprog.py new file mode 100644 index 0000000..a564678 --- /dev/null +++ b/runprog.py @@ -0,0 +1,23 @@ +from time import sleep +import subprocess +import multiprocessing + +def thread_(): +    subprocess.run(["python3", "SmallYTChannelBotSubmissions.py"]) + +while True: +    thread = multiprocessing.Process(target = thread_, args = ()) +    thread.start() + +    sleep(60 * 60 * 2) + +    #print("closing...") +    #file = open("pid.txt", "r") +    #pid = file.readlines()[0] +    #file.close() + +    #subprocess.run(["kill", pid]) +    thread.terminate() + +    #print("killed ", pid) + | 
